소스 검색

Merge branch '4G_PingFeng' into 4G_PingFeng_Release

# Conflicts:
#	src/AppGlobalVar.c
#	src/AppGlobalVar.h
LAPTOP-KB7QFH2U\ChenJie-PC 2 년 전
부모
커밋
eac90b8cf7
67개의 변경된 파일8692개의 추가작업 그리고 1845개의 파일을 삭제
  1. 12 10
      .cproject
  2. 4 4
      .settings/language.settings.xml
  3. 17 0
      .vscode/c_cpp_properties.json
  4. 5 1
      FreeRTOS/Source/include/FreeRTOSConfig.h
  5. 107 0
      code/app/AppGlobalVar.c
  6. 119 0
      code/app/AppGlobalVar.h
  7. 36 33
      code/app/AppTaskCan.c
  8. 8 5
      code/app/AppTaskCan.h
  9. 20 16
      code/app/AppTaskGps.c
  10. 8 5
      code/app/AppTaskGps.h
  11. 9 22
      code/app/AppTaskMain.c
  12. 19 0
      code/app/AppTaskMain.h
  13. 261 0
      code/app/AppTaskUart0.c
  14. 18 16
      code/app/AppTaskUart0.h
  15. 150 151
      code/app/AppTaskUart1.c
  16. 14 19
      code/app/AppTaskUart1.h
  17. 1 1
      code/app/UDSTask.c
  18. 1 1
      code/app/UDSTask.h
  19. 1 1
      code/app/USER_CONFIG.h
  20. 39 46
      code/app/lib/AppFuncLib.c
  21. 13 19
      code/app/lib/AppFuncLib.h
  22. 113 0
      code/debug/SEGGER/Global.h
  23. 248 0
      code/debug/SEGGER/SEGGER.h
  24. 667 144
      code/debug/SEGGER/SEGGER_RTT.c
  25. 492 0
      code/debug/SEGGER/SEGGER_RTT.h
  26. 428 0
      code/debug/SEGGER/SEGGER_RTT_Conf.h
  27. 124 0
      code/debug/SEGGER/SEGGER_RTT_Syscalls_GCC.c
  28. 119 0
      code/debug/SEGGER/SEGGER_RTT_Syscalls_IAR.c
  29. 393 0
      code/debug/SEGGER/SEGGER_RTT_Syscalls_KEIL.c
  30. 251 0
      code/debug/SEGGER/SEGGER_RTT_Syscalls_SES.c
  31. 9 24
      code/debug/SEGGER/SEGGER_RTT_printf.c
  32. 3102 0
      code/debug/SEGGER/SEGGER_SYSVIEW.c
  33. 370 0
      code/debug/SEGGER/SEGGER_SYSVIEW.h
  34. 85 0
      code/debug/SEGGER/SEGGER_SYSVIEW_Conf.h
  35. 579 0
      code/debug/SEGGER/SEGGER_SYSVIEW_ConfDefaults.h
  36. 104 0
      code/debug/SEGGER/SEGGER_SYSVIEW_Config_FreeRTOS.c
  37. 252 0
      code/debug/SEGGER/SEGGER_SYSVIEW_FreeRTOS.c
  38. 334 0
      code/debug/SEGGER/SEGGER_SYSVIEW_FreeRTOS.h
  39. 99 0
      code/debug/SEGGER/SEGGER_SYSVIEW_Int.h
  40. 0 0
      code/debug/cm_backtrace/Languages/README.md
  41. 0 0
      code/debug/cm_backtrace/Languages/en-US/cmb_en_US.h
  42. 0 0
      code/debug/cm_backtrace/Languages/zh-CN/cmb_zh_CN.h
  43. 0 0
      code/debug/cm_backtrace/Languages/zh-CN/cmb_zh_CN_UTF8.h
  44. 0 0
      code/debug/cm_backtrace/cm_backtrace.c
  45. 0 0
      code/debug/cm_backtrace/cm_backtrace.h
  46. 0 0
      code/debug/cm_backtrace/cmb_cfg.h
  47. 0 0
      code/debug/cm_backtrace/cmb_def.h
  48. 0 0
      code/debug/cm_backtrace/fault_handler/gcc/cmb_fault.S
  49. 0 0
      code/debug/cm_backtrace/fault_handler/iar/cmb_fault.S
  50. 0 0
      code/debug/cm_backtrace/fault_handler/keil/cmb_fault.S
  51. 0 0
      code/driver/SL_Sc7a20_Driver.c
  52. 33 33
      code/driver/SL_Sc7a20_Driver.h
  53. 1 4
      code/hal/Hal_Fls.c
  54. 1 1
      code/hal/Hal_Fls.h
  55. 1 1
      code/hal/Hal_Var.c
  56. 1 1
      code/hal/Hal_Var.h
  57. 0 0
      code/hal/Hal_Wdg.c
  58. 1 1
      code/hal/Hal_Wdg.h
  59. 6 28
      code/hal/hal_adapter.c
  60. 6 13
      code/hal/hal_adapter.h
  61. 11 7
      code/main.c
  62. 0 97
      src/AppGlobalVar.c
  63. 0 131
      src/AppGlobalVar.h
  64. 0 16
      src/AppTaskMain.h
  65. 0 476
      src/AppTaskUart0.c
  66. 0 249
      src/SEGGER_RTT.h
  67. 0 269
      src/SEGGER_RTT_Conf.h

+ 12 - 10
.cproject

@@ -38,9 +38,15 @@
 								<option id="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.c.compiler.option.target.libraries.334102120" name="Libraries support" superClass="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.c.compiler.option.target.libraries" useByScannerDiscovery="false" value="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.c.compiler.option.target.libraries.newlib_hosted" valueType="enumerated"/>
 								<option id="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.c.compiler.option.target.sysroot.2141010934" name="Sysroot" superClass="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.c.compiler.option.target.sysroot" useByScannerDiscovery="false" value="--sysroot=&quot;${S32DS_ARM32_NEWLIB_DIR}&quot;" valueType="string"/>
 								<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="gnu.c.compiler.option.include.paths.203066772" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
+									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/code}&quot;"/>
+									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/code/app/lib}&quot;"/>
+									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/code/debug/SEGGER}&quot;"/>
+									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/code/debug/cm_backtrace}&quot;"/>
+									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/code/app}&quot;"/>
+									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/code/debug}&quot;"/>
+									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/code/driver}&quot;"/>
+									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/code/hal}&quot;"/>
 									<listOptionValue builtIn="false" value="../FreeRTOS/Source/include"/>
-									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/cm_backtrace}&quot;"/>
-									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/src}&quot;"/>
 									<listOptionValue builtIn="false" value="../RTD/include"/>
 									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/FreeRTOS/Source/portable/GCC/ARM_CM4F}&quot;"/>
 									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/FreeRTOS/Source/portable/MemMang}&quot;"/>
@@ -193,9 +199,8 @@
 						<entry excluding="Linker_Files|Debugger" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Project_Settings"/>
 						<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="RTD"/>
 						<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="board"/>
-						<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="cm_backtrace"/>
+						<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="code"/>
 						<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="generate"/>
-						<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src"/>
 					</sourceEntries>
 				</configuration>
 			</storageModule>
@@ -376,12 +381,11 @@
 					<fileInfo id="com.nxp.s32ds.cle.arm.mbs.arm32.bare.gnu.9.2.exe.release.95203412.Project_Settings/Debugger" name="Debugger" rcbsApplicability="disable" resourcePath="Project_Settings/Debugger" toolsToInvoke=""/>
 					<fileInfo id="com.nxp.s32ds.cle.arm.mbs.arm32.bare.gnu.9.2.exe.release.95203412.Project_Settings/Linker_Files" name="Linker_Files" rcbsApplicability="disable" resourcePath="Project_Settings/Linker_Files" toolsToInvoke=""/>
 					<sourceEntries>
+						<entry flags="LOCAL|VALUE_WORKSPACE_PATH" kind="sourcePath" name="FreeRTOS"/>
 						<entry excluding="Linker_Files|Debugger" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Project_Settings"/>
 						<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="RTD"/>
 						<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="board"/>
 						<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="generate"/>
-						<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src"/>
-						<entry flags="LOCAL|VALUE_WORKSPACE_PATH" kind="sourcePath" name="FreeRTOS"/>
 					</sourceEntries>
 				</configuration>
 			</storageModule>
@@ -562,12 +566,11 @@
 					<fileInfo id="com.nxp.s32ds.cle.arm.mbs.arm32.bare.gnu.9.2.exe.debug.ram.800707771.Project_Settings/Debugger" name="Debugger" rcbsApplicability="disable" resourcePath="Project_Settings/Debugger" toolsToInvoke=""/>
 					<fileInfo id="com.nxp.s32ds.cle.arm.mbs.arm32.bare.gnu.9.2.exe.debug.ram.800707771.Project_Settings/Linker_Files" name="Linker_Files" rcbsApplicability="disable" resourcePath="Project_Settings/Linker_Files" toolsToInvoke=""/>
 					<sourceEntries>
+						<entry flags="LOCAL|VALUE_WORKSPACE_PATH" kind="sourcePath" name="FreeRTOS"/>
 						<entry excluding="Linker_Files|Debugger" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Project_Settings"/>
 						<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="RTD"/>
 						<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="board"/>
 						<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="generate"/>
-						<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src"/>
-						<entry flags="LOCAL|VALUE_WORKSPACE_PATH" kind="sourcePath" name="FreeRTOS"/>
 					</sourceEntries>
 				</configuration>
 			</storageModule>
@@ -748,12 +751,11 @@
 					<fileInfo id="com.nxp.s32ds.cle.arm.mbs.arm32.bare.gnu.9.2.exe.release.ram.883375570.Project_Settings/Debugger" name="Debugger" rcbsApplicability="disable" resourcePath="Project_Settings/Debugger" toolsToInvoke=""/>
 					<fileInfo id="com.nxp.s32ds.cle.arm.mbs.arm32.bare.gnu.9.2.exe.release.ram.883375570.Project_Settings/Linker_Files" name="Linker_Files" rcbsApplicability="disable" resourcePath="Project_Settings/Linker_Files" toolsToInvoke=""/>
 					<sourceEntries>
+						<entry flags="LOCAL|VALUE_WORKSPACE_PATH" kind="sourcePath" name="FreeRTOS"/>
 						<entry excluding="Linker_Files|Debugger" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Project_Settings"/>
 						<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="RTD"/>
 						<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="board"/>
 						<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="generate"/>
-						<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src"/>
-						<entry flags="LOCAL|VALUE_WORKSPACE_PATH" kind="sourcePath" name="FreeRTOS"/>
 					</sourceEntries>
 				</configuration>
 			</storageModule>

+ 4 - 4
.settings/language.settings.xml

@@ -5,7 +5,7 @@
 			<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
 			<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
 			<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
-			<provider class="com.freescale.s32ds.cross.gnu.CrossGCCBuiltinSpecsDetector" console="false" env-hash="1789340707480773096" id="com.freescale.s32ds.cross.gnu.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT S32DS Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+			<provider class="com.freescale.s32ds.cross.gnu.CrossGCCBuiltinSpecsDetector" console="false" env-hash="-1225283376601702587" id="com.freescale.s32ds.cross.gnu.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT S32DS Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
 				<language-scope id="org.eclipse.cdt.core.gcc"/>
 				<language-scope id="org.eclipse.cdt.core.g++"/>
 			</provider>
@@ -16,7 +16,7 @@
 			<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
 			<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
 			<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
-			<provider class="com.freescale.s32ds.cross.gnu.CrossGCCBuiltinSpecsDetector" console="false" env-hash="1789340707480773096" id="com.freescale.s32ds.cross.gnu.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT S32DS Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+			<provider class="com.freescale.s32ds.cross.gnu.CrossGCCBuiltinSpecsDetector" console="false" env-hash="-1225283376601702587" id="com.freescale.s32ds.cross.gnu.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT S32DS Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
 				<language-scope id="org.eclipse.cdt.core.gcc"/>
 				<language-scope id="org.eclipse.cdt.core.g++"/>
 			</provider>
@@ -27,7 +27,7 @@
 			<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
 			<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
 			<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
-			<provider class="com.freescale.s32ds.cross.gnu.CrossGCCBuiltinSpecsDetector" console="false" env-hash="1789340707480773096" id="com.freescale.s32ds.cross.gnu.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT S32DS Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+			<provider class="com.freescale.s32ds.cross.gnu.CrossGCCBuiltinSpecsDetector" console="false" env-hash="-1225283376601702587" id="com.freescale.s32ds.cross.gnu.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT S32DS Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
 				<language-scope id="org.eclipse.cdt.core.gcc"/>
 				<language-scope id="org.eclipse.cdt.core.g++"/>
 			</provider>
@@ -38,7 +38,7 @@
 			<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
 			<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
 			<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
-			<provider class="com.freescale.s32ds.cross.gnu.CrossGCCBuiltinSpecsDetector" console="false" env-hash="1789340707480773096" id="com.freescale.s32ds.cross.gnu.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT S32DS Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+			<provider class="com.freescale.s32ds.cross.gnu.CrossGCCBuiltinSpecsDetector" console="false" env-hash="-1225283376601702587" id="com.freescale.s32ds.cross.gnu.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT S32DS Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
 				<language-scope id="org.eclipse.cdt.core.gcc"/>
 				<language-scope id="org.eclipse.cdt.core.g++"/>
 			</provider>

+ 17 - 0
.vscode/c_cpp_properties.json

@@ -0,0 +1,17 @@
+{
+    "configurations": [
+        {
+            "name": "Win32",
+            "includePath": [
+                "${workspaceFolder}/**"
+            ],
+            "defines": [
+                "_DEBUG",
+                "UNICODE",
+                "_UNICODE"
+            ],
+            "intelliSenseMode": "windows-msvc-x64"
+        }
+    ],
+    "version": 4
+}

+ 5 - 1
FreeRTOS/Source/include/FreeRTOSConfig.h

@@ -28,7 +28,11 @@
 
 #ifndef FREERTOS_CONFIG_H
 #define FREERTOS_CONFIG_H
-
+//#define SEGGER_SYSTEMVIEW //选择SYSTEM查看
+//#define SEGGER_RTT_PRINTF //选择RTT打印
+#ifdef SEGGER_SYSTEMVIEW
+	#include "SEGGER_SYSVIEW_FreeRTOS.h"
+#endif
 /*-----------------------------------------------------------
  * Application specific definitions.
  *

+ 107 - 0
code/app/AppGlobalVar.c

@@ -0,0 +1,107 @@
+/*
+ * @Author: chenjie
+ * @Date: 2022-06-06
+ * @LastEditTime: 2022-10-27
+ * @LastEditors: chenjie
+ * @Description: 
+ * @FilePath: \S32K146_4G\code\app\AppGlobalVar.c
+ * Copyright (c) 2022 by chenjie, All Rights Reserved.
+ */
+
+/*
+ * AppGlobalVar.c
+ *应用层全局变量
+ *  Created on: 2022年1月19日
+ *      Author: QiXiang_CHENJIE
+ */
+#include "AppGlobalVar.h"
+//#define APP_RELEASE
+#ifdef APP_RELEASE
+const char WebSiteName[] = "\"iotp.fast-fun.cn\"";
+uint16 WebSitePort = 8712;
+#else
+const char WebSiteName[] = "\"nas.fast-fun.cn\"";
+uint16 WebSitePort = 8812;
+#endif
+
+#define defaultSn "SPFPFL264S226D001"
+const uint32 AppSwVersion = 0x00000105;
+
+const uint8 DataModuleType = 0x02;//01=NB,02-4G
+const uint16 HwVersion = 0x001;
+const uint32 BlSwVersion = 0x00000001;
+const uint32 DrvSwVersion = 0x00000001;
+const uint8 BmsManuFacture = 0xff;
+const uint8 BmsInfo = 0xff;
+
+uint8 TcpbattSN[BATT_SN_LEN] = {0x31};
+volatile uint32 TimerCounter = 0; // ms单位
+uint8 Fota_update_flag = 0;
+uint8 Fota_error_flag = 0;
+/*GPS*/
+QueueHandle_t GpsDataQueueHandle;
+sint16 xyzData[3] = {0};
+/*Hal_Can*/
+uint8 CanIf_u8TxConfirmCnt = 0U;
+boolean CanIf_bTxFlag = false;
+uint8 CanIf_u8RxIndicationCnt = 0U;
+boolean CanIf_bRxFlag = false;
+QueueHandle_t CanRecvQueueHandle;
+
+/*TCP相关变量*/
+bool TcpSysReboot = 1; // tcp无法联网时,重启使能
+char ImeiNum[15] = {0};
+char IccidNum[20] = {0};
+uint8 CSQValue = 0;
+sint8 SocketId = -1; // 联网状态
+sint8 RegChkRet = 0; // 驻网状态
+char WebSiteIp[20] = {0};
+uint8 TcpWorkState = 0;
+
+#define EEP_START_SEC_VAR_INIT_8_NO_CACHEABLE
+#include "Eep_MemMap.h"
+AppConfigBody AppConfigInfo = {false, true, {defaultSn}, {0}};
+#define EEP_STOP_SEC_VAR_INIT_8_NO_CACHEABLE
+#include "Eep_MemMap.h"
+
+/*以下变量均为串口协议相关变量*/
+#ifdef APP_UART0_ENABLE
+AppDataBody AppDataInfo = {BMS_CELLNUM, BMS_TEMPNUM};
+uint16 avrgCellVol = 0; // 平均电压
+uint16 bmsHwVersion = 0;
+uint32 bmsSwVersion = 0;
+uint16 battCellU[BMS_CELLNUM]; // 电池电压
+uint16 battI = 10000;              // BMS电流(tcp上传)
+uint16 battPackVol = 0;        // bms电压
+uint16 maxCellVol = 0;         // 最大单体电压
+uint16 minCellVol = 0;         // 最小单体电压
+// uint16 socd_pct_vcuSoc = 0;		 // soc(tcp上传,精度0.1)
+// uint16 sohd_pct_bcuSoh = 0;		 // soh(tcp上传,精度0.1)
+uint32 battBalanceoInfo = 0;     //
+uint32 battProtectState = 0;     // bms保护状态
+uint32 battWarningState = 0;     // bms告警状态
+uint8 AvgBattTemp = 0;           // 平均单体温度
+uint8 battCellTemp[BMS_TEMPNUM]; // 电池温度
+uint8 Battdesigncap = 0;         // 电池包设计容量
+uint8 battHeatEnableState = 0;   // bms加热状态
+uint8 battMOSSwitchState = 0;    // bms mos开关状态
+uint8 battSOC = 0;               // bms发送soc
+uint8 battSOH = 0;               // bms发送soh
+uint8 battWorkState = 0;         // bms工作状态
+uint8 BmsOtherTemp = 0;          // BMS其他温度,没有其他温度,为0
+uint8 maxCellTemp = 0;           // 最大单体温度
+uint8 minCellTemp = 0;           // 最小单体温度
+uint8 OtherTemp = 0;             // 通讯模块其他温度
+uint8 battHeatState = 0;
+uint8 battFanState = 0;
+uint8 battRelayState = 0;
+uint8 battConverState = 0;
+uint8 battSeparateEnable = 0;
+uint8 battSeparateCtlState = 0;
+uint8 battSeparateState = 0;
+uint16 ErrorArray[5] = {0};
+uint32 meterAllPwr[2] = {0};
+uint32 meterPosPwr[2] = {0};
+uint32 meterNegPwr[2] = {0};
+uint32 BattTempR[4] = {0xFF};
+#endif

+ 119 - 0
code/app/AppGlobalVar.h

@@ -0,0 +1,119 @@
+/*** 
+ * @Author: chenjie
+ * @Date: 2022-06-06
+ * @LastEditTime: 2022-10-27
+ * @LastEditors: chenjie
+ * @Description: 
+ * @FilePath: \S32K146_4G\code\app\AppGlobalVar.h
+ * @Copyright (c) 2022 by chenjie, All Rights Reserved.
+ */
+
+#ifndef APPGLOBALVAR_H_
+#define APPGLOBALVAR_H_
+
+#define APP_UART0_ENABLE
+//#define APP_CAN_ENABLE
+
+#include "hal_adapter.h"
+#define BATT_SN_LEN 17
+extern const uint32 AppSwVersion;
+extern const uint8 DataModuleType;
+extern const uint16 HwVersion;
+extern const uint32 BlSwVersion;
+extern const uint32 DrvSwVersion;
+extern const uint8 BmsManuFacture;
+extern const uint8 BmsInfo;
+extern bool TcpSysReboot;
+extern uint8 TcpbattSN[BATT_SN_LEN];
+extern uint8 VIN[17];
+extern volatile uint32 TimerCounter;
+extern uint8 Fota_update_flag;
+extern uint8 Fota_error_flag;
+typedef struct
+{
+	uint8 RealLen;
+	uint8 *DataPtr;
+} QueueDataTrans_Type;
+/*GPS*/
+extern QueueHandle_t GpsDataQueueHandle;
+extern sint16 xyzData[3];
+/*Hal_Can*/
+extern uint8 CanIf_u8TxConfirmCnt;
+extern boolean CanIf_bTxFlag;
+extern uint8 CanIf_u8RxIndicationCnt;
+extern boolean CanIf_bRxFlag;
+extern QueueHandle_t CanRecvQueueHandle;
+
+extern uint8 CSQValue;
+extern sint8 SocketId;
+extern sint8 RegChkRet;
+extern char WebSiteIp[20];
+extern const char WebSiteName[];
+extern uint16 WebSitePort;
+extern char ImeiNum[15];
+extern char IccidNum[20];
+extern uint8 TcpWorkState;
+typedef struct _AppEppType
+{
+	uint32 battDischrgAccCap;  //单位maH
+	uint32 battDischrgAccEnrg; //单位wh
+	uint16 battCycleTimes;
+} AppEppBody;
+typedef struct _AppConfigType
+{
+	bool appSaveFlg;
+	bool eolFlg;
+	uint8 deviceSn[17];
+	AppEppBody AppDataInfo;
+	uint8 re[20];
+} AppConfigBody;
+extern AppConfigBody AppConfigInfo;
+#define BMS_CELLNUM 120
+#define BMS_TEMPNUM 40
+typedef struct _AppDataType
+{
+	uint8 BattCellCount;
+	uint8 BattTempCount;
+} AppDataBody;
+extern AppDataBody AppDataInfo;
+extern uint16 avrgCellVol;
+extern uint16 battCellU[BMS_CELLNUM];
+extern uint16 battI;
+extern uint16 bmsHwVersion;
+extern uint32 bmsSwVersion;
+extern uint16 battPackVol;
+extern uint16 maxCellVol;
+extern uint16 minCellVol;
+// extern uint16 socd_pct_vcuSoc;
+// extern uint16 sohd_pct_bcuSoh;
+extern uint32 battBalanceoInfo;
+extern uint32 battProtectState;
+extern uint32 battWarningState;
+extern uint8 AvgBattTemp;
+extern uint8 battCellTemp[BMS_TEMPNUM];
+extern uint8 Battdesigncap;
+extern uint8 battHeatEnableState;
+extern uint8 battMOSSwitchState;
+extern uint8 battSOC;
+extern uint8 battSOH;
+extern uint8 battWorkState;
+extern uint8 BmsOtherTemp;
+extern uint8 maxCellTemp;
+extern uint8 minCellTemp;
+extern uint8 OtherTemp;
+extern uint8 battHeatState;
+extern uint8 battFanState;
+extern uint8 battRelayState;
+extern uint8 battConverState;
+extern uint8 battSeparateEnable;
+extern uint8 battSeparateCtlState;
+extern uint8 battSeparateState;
+extern uint16 ErrorArray[5];
+extern uint32 meterAllPwr[2];
+extern uint32 meterPosPwr[2];
+extern uint32 meterNegPwr[2];
+extern uint32 BattTempR[4];
+extern uint32 battAccEnrg;
+extern uint32 battAccCap;
+extern uint16 battAccUseTimes;
+#endif /* APPGLOBALVAR_H_ */

+ 36 - 33
src/AppTaskCan.c → code/app/AppTaskCan.c

@@ -1,8 +1,11 @@
 /*
- * AppTaskCan.c
- *
- *  Created on: 2022年2月13日
- *      Author: QiXiang_CHENJIE
+ * @Author: chenjie
+ * @Date: 2022-06-06
+ * @LastEditTime: 2022-10-27
+ * @LastEditors: chenjie
+ * @Description: 
+ * @FilePath: \S32K146_4G\code\app\AppTaskCan.c
+ * Copyright (c) 2022 by chenjie, All Rights Reserved.
  */
 #include "AppTaskCan.h"
 static uint8 BattSendFlg = 0;
@@ -47,7 +50,7 @@ void CanTask(void *pvParameters)
 				}
 				else
 				{
-					BcuDecodeFunction(CanRxMsg.id,CanRxMsg.data);//can协议解析
+					BcuDecodeFunction(CanRxMsg.id,CanRxMsg.data);//can鍗忚�瑙f瀽
 				}
 			}
 		}while(ret == pdPASS);
@@ -59,12 +62,12 @@ void CanTask(void *pvParameters)
 		if((TimerCounter - timerCounterNow)>=100)
 		{
 			timerCounterNow = TimerCounter;
-			//温度采集
+			//娓╁害閲囬泦
 			ADC_ReadValue();
 		}
 	}
 }
-//注意解码超限问题
+//娉ㄦ剰瑙g爜瓒呴檺闂��
 void BcuDecodeFunction(uint32 ID, uint8 *rawData)
 {
 	switch(ID)
@@ -89,18 +92,18 @@ static void UDSAnsFunc(uint8 *rawData)
 	static uint8 deviceSnRecvFlg = 0;
 	switch(UdsService)
 	{
-	case 0x10://模式切换
+	case 0x10://妯″紡鍒囨崲
 	{
 		if(UdsSubService==0x01)
 		{
-			UdsStates = 0x01;//关闭UDS诊断
+			UdsStates = 0x01;//鍏抽棴UDS璇婃柇
 			UdsAns(true,UdsService,UdsSubService,0x00,NULL,0);
 		}
 		else if(UdsSubService==0x02)
 		{
 			if(UdsStates==0x01||UdsStates==0x02)
 			{
-				UdsStates = 0x02;//打开UDS诊断
+				UdsStates = 0x02;//鎵撳紑UDS璇婃柇
 				UdsAns(true,UdsService,UdsSubService,0x00,NULL,0);
 			}
 			else
@@ -110,18 +113,18 @@ static void UDSAnsFunc(uint8 *rawData)
 		}
 		break;
 	}
-	case 0x11://控制
+	case 0x11://鎺у埗
 	{
 		if(UdsStates==0x02)
 		{
 			switch(UdsSubService)
 			{
-				case 0x01://重启
+				case 0x01://閲嶅惎
 				{
-					AnsData[0] = APPSWVERSION>>24;
-					AnsData[1] = APPSWVERSION>>16;
-					AnsData[2] = APPSWVERSION>>8;
-					AnsData[3] = APPSWVERSION>>0;
+					AnsData[0] = AppSwVersion>>24;
+					AnsData[1] = AppSwVersion>>16;
+					AnsData[2] = AppSwVersion>>8;
+					AnsData[3] = AppSwVersion>>0;
 					UdsAns(true,UdsService,UdsSubService,0x00,AnsData,4);
 					AppConfigInfo.appSaveFlg = true;
 					vTaskDelay(pdMS_TO_TICKS(1000));
@@ -141,22 +144,22 @@ static void UDSAnsFunc(uint8 *rawData)
 		}
 		break;
 	}
-	case 0x22://查询
+	case 0x22://鏌ヨ�
 	{
 		if(UdsStates==0x02)
 		{
 			switch(UdsSubService)
 			{
-			case 0x01://版本号查询
+			case 0x01://鐗堟湰鍙锋煡璇�
 			{
-				AnsData[0] = APPSWVERSION>>24;
-				AnsData[1] = APPSWVERSION>>16;
-				AnsData[2] = APPSWVERSION>>8;
-				AnsData[3] = APPSWVERSION>>0;
+				AnsData[0] = AppSwVersion>>24;
+				AnsData[1] = AppSwVersion>>16;
+				AnsData[2] = AppSwVersion>>8;
+				AnsData[3] = AppSwVersion>>0;
 				UdsAns(true,UdsService,UdsSubService,0x00,AnsData,4);
 				break;
 			}
-			case 0x02://SN号码查询
+			case 0x02://SN鍙风爜鏌ヨ�
 			{
 				memcpy(AnsData,AppConfigInfo.deviceSn,17);
 				for(uint8 i=0;i<5;i++)
@@ -165,7 +168,7 @@ static void UDSAnsFunc(uint8 *rawData)
 				}
 				break;
 			}
-			case 0x03://ICCID查询
+			case 0x03://ICCID鏌ヨ�
 			{
 				memcpy(AnsData,IccidNum,20);
 				for(uint8 i=0;i<5;i++)
@@ -174,7 +177,7 @@ static void UDSAnsFunc(uint8 *rawData)
 				}
 				break;
 			}
-			case 0x04://IMEI查询
+			case 0x04://IMEI鏌ヨ�
 			{
 				memcpy(AnsData,ImeiNum,15);
 				for(uint8 i=0;i<4;i++)
@@ -183,19 +186,19 @@ static void UDSAnsFunc(uint8 *rawData)
 				}
 				break;
 			}
-			case 0x05://驻网状态查询
+			case 0x05://椹荤綉鐘舵€佹煡璇�
 			{
 				AnsData[0]= RegChkRet;
 				UdsAns(true,UdsService,UdsSubService,0x00,AnsData,1);
 				break;
 			}
-			case 0x06://联网状态查询
+			case 0x06://鑱旂綉鐘舵€佹煡璇�
 			{
 				AnsData[0]= SocketId;
 				UdsAns(true,UdsService,UdsSubService,0x00,AnsData,1);
 				break;
 			}
-			case 0x07://定位信息查询
+			case 0x07://瀹氫綅淇℃伅鏌ヨ�
 			{
 				GPSInfo GpsRecvData;
 				if (xQueuePeek(GpsDataQueueHandle, &GpsRecvData, 0) == pdPASS)
@@ -225,18 +228,18 @@ static void UDSAnsFunc(uint8 *rawData)
 				}
 				break;
 			}
-			case 0x08://温度检测查询
+			case 0x08://娓╁害妫€娴嬫煡璇�
 			{
 				UdsAns(true,UdsService,UdsSubService,0x00,AnsData,1);
 				break;
 			}
-			case 0x09://电池信息查询
+			case 0x09://鐢垫睜淇℃伅鏌ヨ�
 			{
 				UdsAns(true,UdsService,UdsSubService,0x00,AnsData,1);
 				BattSendFlg = 1;
 				break;
 			}
-			case 0x0A://三轴数据查询
+			case 0x0A://涓夎酱鏁版嵁鏌ヨ�
 			{
 				AnsData[0] = xyzData[0]>>8;
 				AnsData[1] = xyzData[0]>>0;
@@ -258,7 +261,7 @@ static void UDSAnsFunc(uint8 *rawData)
 		}
 		break;
 	}
-	case 0x2E://写入
+	case 0x2E://鍐欏叆
 	{
 		if(UdsStates==0x02)
 		{
@@ -293,7 +296,7 @@ static void UDSAnsFunc(uint8 *rawData)
 		}
 		break;
 	}
-	case 0x31://控制
+	case 0x31://鎺у埗
 	{
 		if(UdsStates==0x02)
 		{

+ 8 - 5
src/AppTaskCan.h → code/app/AppTaskCan.h

@@ -1,8 +1,11 @@
-/*
- * AppTaskCan.h
- *
- *  Created on: 2022Äê2ÔÂ13ÈÕ
- *      Author: QiXiang_CHENJIE
+/*** 
+ * @Author: chenjie
+ * @Date: 2022-06-06
+ * @LastEditTime: 2022-10-27
+ * @LastEditors: chenjie
+ * @Description: 
+ * @FilePath: \S32K146_4G\code\app\AppTaskCan.h
+ * @Copyright (c) 2022 by chenjie, All Rights Reserved.
  */
 
 #ifndef APPTASKCAN_H_

+ 20 - 16
src/AppTaskGps.c → code/app/AppTaskGps.c

@@ -1,9 +1,13 @@
 /*
- * AppTaskGps.c
- *
- *  Created on: 2022爛2堎16゜
- *      Author: QiXiang_CHENJIE
+ * @Author: chenjie
+ * @Date: 2022-06-06
+ * @LastEditTime: 2022-10-27
+ * @LastEditors: chenjie
+ * @Description: 
+ * @FilePath: \S32K146_4G\code\app\AppTaskGps.c
+ * Copyright (c) 2022 by chenjie, All Rights Reserved.
  */
+
 #include "AppTaskGps.h"
 void strdel(char *str, char c);
 uint32 location_handle(char *in1);
@@ -12,8 +16,8 @@ uint8 GpsRecvPtr[1024];
 void GpsTask(void *pvParameters)
 {
 	(void)pvParameters;
-	GpsDataQueueHandle = xQueueCreate(1, sizeof(GPSInfo));//酗僅峈1符褫眕埰勍葡迡
-	Dio_WriteChannel(DioConf_DioChannel_PTD1_GPIO_OUT_MCU_GPS_POW_EN, STD_ON);//GPS羲儂
+	GpsDataQueueHandle = xQueueCreate(1, sizeof(GPSInfo));//�踹漲銝�1�滚虾隞亙�霈貉���
+	Dio_WriteChannel(DioConf_DioChannel_PTD1_GPIO_OUT_MCU_GPS_POW_EN, STD_ON);//GPS撘���
 	uint16 pReadLen = 0;
 	while(1)
 	{
@@ -40,10 +44,10 @@ void GpsDataDecode(uint8 *msg)
 	uint32 longitude;
 	uint16 direction;
 	memset((uint8 *)&GpsInfoData, 0x00, sizeof(GPSInfo));
-	p = strtok(msg, delim); //蔚陓洘輛俴煦賃
+	p = strtok(msg, delim); //撠�縑�航�銵����
 	p2 = strtok(NULL, delim);
-	p = strtok(p, ","); //硐龰菴1俴腔陓洘RMC
-	//p = strtok(temp,",");//耀攜聆彸
+	p = strtok(p, ","); //�芸�蝚�1銵𣬚�靽⊥�RMC
+	//p = strtok(temp,",");//璅⊥�瘚贝�
 	if (strcmp(p, "$GNRMC") == 0)
 	{
 		index = 0;
@@ -55,11 +59,11 @@ void GpsDataDecode(uint8 *msg)
 		}
 		if (index > 5 && strcmp(databuffer[2], "A") == 0)
 		{
-			GpsInfoData.locateMark = 0x01; //衄虴ㄛ陲冪ㄛ控帠迡隅
+			GpsInfoData.locateMark = 0x01; //�㗇�嚗䔶�蝏𧶏��㛖漪�坔�
 			strdel(databuffer[3], '.');
 			strdel(databuffer[5], '.');
 			strdel(databuffer[7], '.');
-			speedtemp = atol(databuffer[7]) * 1852 / 1e5; //誹遙呾等弇ㄛ1誹=1.852km藩苤奀
+			speedtemp = atol(databuffer[7]) * 1852 / 1e5; //��揢蝞堒�雿㵪�1��=1.852km瘥誩���
 			GpsInfoData.speed[0] = (speedtemp >> 8) & 0xFF;
 			GpsInfoData.speed[1] = speedtemp & 0xFF;
 			latitude = location_handle(databuffer[3]);
@@ -72,7 +76,7 @@ void GpsDataDecode(uint8 *msg)
 			GpsInfoData.longitude[1] = longitude >> 16;
 			GpsInfoData.longitude[2] = longitude >> 8;
 			GpsInfoData.longitude[3] = longitude;
-			if (speedtemp >= 50) //湮衾5km/h符怀堤源弇
+			if (speedtemp >= 50) //憭找�5km/h�滩��箸䲮雿�
 			{
 				direction = atol(databuffer[8]);
 				GpsInfoData.direction[0] = direction >> 8;
@@ -91,14 +95,14 @@ void GpsDataDecode(uint8 *msg)
 //				{
 //					AppDataInfo.AccMileage = 0;
 //				}
-//			}濛數爵最腔濛樓
+//			}蝝航恣�𣬚���敞��
 		}
 //		GpsInfoData.AccMileage[0] = AppDataInfo.AccMileage >> 24;
 //		GpsInfoData.AccMileage[1] = AppDataInfo.AccMileage >> 16;
 //		GpsInfoData.AccMileage[2] = AppDataInfo.AccMileage >> 8;
 //		GpsInfoData.AccMileage[3] = AppDataInfo.AccMileage;
 	}
-	p2 = strtok(p2, ","); //硐龰菴2俴腔陓洘GGA
+	p2 = strtok(p2, ","); //�芸�蝚�2銵𣬚�靽⊥�GGA
 	memset(databuffer, 0x00, 20);
 	if (strcmp(p2, "$GNGGA") == 0)
 	{
@@ -111,11 +115,11 @@ void GpsDataDecode(uint8 *msg)
 		}
 		if (index > 9 && (strcmp(databuffer[6], "1") == 0 || strcmp(databuffer[6], "2") == 0))
 		{
-			GpsInfoData.satelliteNum = atol(databuffer[7]); //怹陎杅醴迡⻌
+			GpsInfoData.satelliteNum = atol(databuffer[7]); //�急��啁𤌍�坔�
 			strdel(databuffer[9], '.');
 			uint16 alt = 0;
 			alt = atol(databuffer[9]) / 10 + 1000;
-			GpsInfoData.altitude[0] = alt >> 8; //漆匿
+			GpsInfoData.altitude[0] = alt >> 8; //瘚瑟�
 			GpsInfoData.altitude[1] = alt;
 			strdel(databuffer[2], '.');
 			strdel(databuffer[4], '.');

+ 8 - 5
src/AppTaskGps.h → code/app/AppTaskGps.h

@@ -1,8 +1,11 @@
-/*
- * AppTaskGps.h
- *
- *  Created on: 2022Äê2ÔÂ16ÈÕ
- *      Author: QiXiang_CHENJIE
+/*** 
+ * @Author: chenjie
+ * @Date: 2022-06-06
+ * @LastEditTime: 2022-10-27
+ * @LastEditors: chenjie
+ * @Description: 
+ * @FilePath: \S32K146_4G\code\app\AppTaskGps.h
+ * @Copyright (c) 2022 by chenjie, All Rights Reserved.
  */
 
 #ifndef APPTASKGPS_H_

+ 9 - 22
src/AppTaskMain.c → code/app/AppTaskMain.c

@@ -1,8 +1,11 @@
 /*
- * AppTaskMain.c
- *
- *  Created on: 2022年2月22日
- *      Author: QiXiang_CHENJIE
+ * @Author: chenjie
+ * @Date: 2022-06-06
+ * @LastEditTime: 2022-10-27
+ * @LastEditors: chenjie
+ * @Description: 
+ * @FilePath: \S32K146_4G\code\app\AppTaskMain.c
+ * Copyright (c) 2022 by chenjie, All Rights Reserved.
  */
 
 #include "AppTaskMain.h"
@@ -23,21 +26,8 @@ void MainTask(void *pvParameters)
 		HAL_EEP_Write(0,(uint8 *)&AppConfigInfo,sizeof(AppConfigInfo));
 	}
 	HAL_EEP_Read(0,(uint8 *)&AppConfigInfo,sizeof(AppConfigInfo));
-	#if UARTPRINTF==1
-		create_ringBuffer(&printfRingBuffer,ringbuffer,sizeof(ringbuffer));
-	#endif
 	while(1)
 	{
-//#if SEGGER_PRINTF==1
-//		static uint32 tempcounter = 0;
-//			if((TimerCounter - tempcounter)>1000)
-//			{
-//				tempcounter = TimerCounter;
-//				UBaseType_t uxHighWaterMark;
-//				uxHighWaterMark = uxTaskGetStackHighWaterMark( NULL );
-//				SEGGER_RTT_printf("[%d] %s->%d\r\n",__LINE__,__func__,uxHighWaterMark);
-//			}
-//#endif
 		vTaskDelay(pdMS_TO_TICKS(10));
 		if(HAL_Is100msTickTimeout())
 		{
@@ -48,9 +38,6 @@ void MainTask(void *pvParameters)
 		}
 		if(TimerCounter%1000==0)
 		{
-#if SEGGER_PRINTF==2
-	SEGGER_RTT_printf("[%d] TimerCounter=%d,eol=%d\r\n",__LINE__,TimerCounter,AppConfigInfo.eolFlg);
-#endif
 			if(AppConfigInfo.eolFlg==true)
 			{
 				Dio_FlipChannel(DioConf_DioChannel_PTE9_GPIO_OUT_MCU_LED5);
@@ -65,9 +52,9 @@ void MainTask(void *pvParameters)
 			AppConfigInfo.appSaveFlg = false;
 			HAL_EEP_Write(0,(uint8 *)&AppConfigInfo,sizeof(AppConfigInfo));
 		}
-		if(Fota_update_flag || Fota_error_flag)//升级指令发出,进行重启,或者FTP服务器出现问题,进行重启
+		if(Fota_update_flag || Fota_error_flag)//鍗囩骇鎸囦护鍙戝嚭锛岃繘琛岄噸鍚�,鎴栬€匜TP鏈嶅姟鍣ㄥ嚭鐜伴棶棰橈紝杩涜�閲嶅惎
 		{
-			//重启前保存数据
+			//閲嶅惎鍓嶄繚瀛樻暟鎹�
 			AppConfigInfo.appSaveFlg = false;
 			HAL_EEP_Write(0,(uint8 *)&AppConfigInfo,sizeof(AppConfigInfo));
 			SystemSoftwareReset();

+ 19 - 0
code/app/AppTaskMain.h

@@ -0,0 +1,19 @@
+/*** 
+ * @Author: chenjie
+ * @Date: 2022-06-06
+ * @LastEditTime: 2022-10-27
+ * @LastEditors: chenjie
+ * @Description: 
+ * @FilePath: \S32K146_4G\code\app\AppTaskMain.h
+ * @Copyright (c) 2022 by chenjie, All Rights Reserved.
+ */
+
+#ifndef APPTASKMAIN_H_
+#define APPTASKMAIN_H_
+#include "hal_adapter.h"
+#include "AppFunclib.h"
+#include "AppGlobalVar.h"
+#include "Hal_Wdg.h"
+void MainTask(void *pvParameters);
+
+#endif /* APPTASKMAIN_H_ */

+ 261 - 0
code/app/AppTaskUart0.c

@@ -0,0 +1,261 @@
+/*
+ * @Author: chenjie
+ * @Date: 2022-06-06
+ * @LastEditTime: 2022-10-27
+ * @LastEditors: chenjie
+ * @Description: 
+ * @FilePath: \S32K146_4G\code\app\AppTaskUart0.c
+ * Copyright (c) 2022 by chenjie, All Rights Reserved.
+ */
+#include "AppTaskUart0.h"
+#ifdef APP_UART0_ENABLE
+static process_Uart0 gProcess_Uart0_Task = PROCESS_UART_STATE_IDLE;
+#define PROC_UART0_STATE_SWITCH(a) (gProcess_Uart0_Task = a)
+bool bmsCellInfoDecode1(uint8 *dataPtr);
+bool bmsCellInfoDecode2(uint8 *dataPtr);
+bool bmsTempInfoDecode(uint8 *dataPtr);
+bool bmsOtherInfoDecode(uint8 *dataPtr);
+void UartBusReadDataFunc(uint16 RegAddrBegin, uint16 Reg_Num, bool (*decodeFunc)(uint8 *dataPtr));
+// void battDataCalFunc(void);
+static uint16 UartNoDataReadCounter = 0;
+void Uart0Task(void *pvParameters)
+{
+	(void)pvParameters;
+	UartAnsType UartAnsData;
+	uint16 pReadLen = 0;
+	static uint8 writecounter = 0;
+	while (1)
+	{
+		switch (gProcess_Uart0_Task)
+		{
+		case PROCESS_UART_STATE_IDLE:
+		{
+			vTaskDelay(pdMS_TO_TICKS(10));
+			if ((TimerCounter % 1000) == 0)
+			{
+				PROC_UART0_STATE_SWITCH(PROCESS_UART_STATE_READ);
+			}
+			else if (TimerCounter % 100 == 0)
+			{
+				PROC_UART0_STATE_SWITCH(PROCESS_UART_STATE_WRITE);
+			}
+			break;
+		}
+		case PROCESS_UART_STATE_READ:
+		{
+			/*01 04 00 01 00 38 A0 18
+			01 04 00 64 00 3C B1 C4
+			01 04 01 90 00 28 F1 C5 */
+			Dio_FlipChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2);
+			//其他参数读取
+			UartBusReadDataFunc(0x01, 0x38, bmsOtherInfoDecode);
+			//电压读取
+			UartBusReadDataFunc(0x64, 60, bmsCellInfoDecode1);
+			UartBusReadDataFunc(0x64 + 60, 60, bmsCellInfoDecode2);
+			//温度读取
+			UartBusReadDataFunc(0x190, 40, bmsTempInfoDecode);
+			//没有读到数据时的默认值
+			if (UartNoDataReadCounter > 10)
+			{
+				memset((uint8 *)&UartAnsData, 0x00, sizeof(UartAnsData));
+				bmsCellInfoDecode1(UartAnsData.Data);
+				bmsCellInfoDecode2(UartAnsData.Data);
+				bmsTempInfoDecode(UartAnsData.Data);
+				bmsOtherInfoDecode(UartAnsData.Data);
+				PutErrorNum(ErrorArray, sizeof(ErrorArray) / 2, 1);
+				vTaskDelay(pdMS_TO_TICKS(2000));
+			}
+			PROC_UART0_STATE_SWITCH(PROCESS_UART_STATE_IDLE);
+			break;
+		}
+		case PROCESS_UART_STATE_WRITE:
+		{
+			if (battSeparateEnable) //最多重新写5次
+			{
+				uint16 RegAddress = 0;
+				uint16 CRC_chk_buffer = 0;
+				uint8 WriteData[2] = {0x00, 0x00};
+				uint8 UartRecvBuffer[10];
+				if (!battSeparateCtlState)
+				{
+					WriteData[1] = 0x55;
+				}
+				else
+				{
+					WriteData[1] = 0xAA;
+				}
+				RegAddress = 100;
+				UartWriteMsgType Uart_Write_Msg;
+				Uart_Write_Msg.Bms_Address = BMS_ADDRESS_CODE;
+				Uart_Write_Msg.Bms_Funcode = UART_WRITE_CODE;
+				Uart_Write_Msg.Reg_Begin_H = RegAddress >> 8;
+				Uart_Write_Msg.Reg_Begin_L = RegAddress;
+				Uart_Write_Msg.Reg_Num_H = 0x00;
+				Uart_Write_Msg.Reg_Num_L = 0x01;
+				Uart_Write_Msg.Data_Count = 0x02; //要写入的字节数
+				memcpy(Uart_Write_Msg.Data, WriteData, 2);
+				CRC_chk_buffer = crc_chk((uint8 *)&Uart_Write_Msg, sizeof(Uart_Write_Msg) - 2);
+				Uart_Write_Msg.CRC_L = CRC_chk_buffer;
+				Uart_Write_Msg.CRC_H = CRC_chk_buffer >> 8;
+				UART_Query_Data(UART_LPUART0, UART_LPUART0, (uint8 *)&Uart_Write_Msg, sizeof(Uart_Write_Msg), UartRecvBuffer, &pReadLen, 500);
+				if (pReadLen > 3 && *(UartRecvBuffer + 1) == 0x10)
+				{
+					writecounter = 0;
+					battSeparateEnable = 0;
+				}
+				else
+				{
+					writecounter++;
+				}
+			}
+			if (writecounter >= 5)
+			{
+				battSeparateEnable = 0;
+				writecounter = 0;
+			}
+			PROC_UART0_STATE_SWITCH(PROCESS_UART_STATE_IDLE);
+			break;
+		}
+		case PROCESS_UART_STATE_SLEEP:
+		{
+			break;
+		}
+		default:
+			break;
+		}
+	}
+}
+bool bmsCellInfoDecode1(uint8 *dataPtr) //电压数据解码1
+{
+	for (uint8 i = 0; i < 60; i++)
+	{
+		battCellU[i] = ((dataPtr[(0x00 + i) * 2] << 8) | dataPtr[(0x00 + i) * 2 + 1]);
+	}
+	return true;
+}
+bool bmsCellInfoDecode2(uint8 *dataPtr) //电压数据解码2
+{
+	for (uint8 i = 60; i < BMS_CELLNUM; i++)
+	{
+		battCellU[i] = ((dataPtr[(0x00 + i) * 2] << 8) | dataPtr[(0x00 + i) * 2 + 1]);
+	}
+	return true;
+}
+bool bmsTempInfoDecode(uint8 *dataPtr) //温度数据解码
+{
+	for (uint8 i = 0; i < BMS_TEMPNUM; i++)
+	{
+		battCellTemp[i] = dataPtr[(0x00 + i) * 2 + 1];
+	}
+	return true;
+}
+bool bmsOtherInfoDecode(uint8 *dataPtr) //其他数据解析
+{
+	uint16 Batt_current;
+	battPackVol = (dataPtr[(0x00) * 2]) << 8 | (dataPtr[(0x00) * 2 + 1]);
+	Batt_current = (dataPtr[(0x01) * 2] << 8) | (dataPtr[(0x01) * 2 + 1]);
+	if(battPackVol==0)
+	{
+		Batt_current=16000;
+	}
+	battI = Batt_current - 6000; //电流偏移量不同
+	battSOC = dataPtr[(0x02) * 2 + 1];
+	battSOH = dataPtr[(0x03) * 2 + 1];
+	battWorkState = (dataPtr[(0x06) * 2 + 1]) & 0x03; //电池状态(原始数据),3表示开路,2表示放电,1表示充电
+	switch (battWorkState)							  //电池状态(上传数据),0表示开路,1表示放电,2表示充电
+	{
+	case 0:
+		battWorkState = 0;
+		break;
+	case 1:
+		battWorkState = 2;
+		break;
+	case 2:
+		battWorkState = 1;
+		break;
+	case 3:
+		battWorkState = 0;
+		break;
+	default:
+		break;
+	}
+	maxCellVol = (dataPtr[(0x13) * 2] << 8) | dataPtr[(0x13) * 2 + 1];
+	minCellVol = (dataPtr[(0x16) * 2] << 8) | dataPtr[(0x16) * 2 + 1];
+	AppConfigInfo.AppDataInfo.battDischrgAccEnrg = (dataPtr[(0x34) * 2] << 8) | dataPtr[(0x34) * 2 + 1];
+	AppConfigInfo.AppDataInfo.battCycleTimes = AppConfigInfo.AppDataInfo.battDischrgAccEnrg / 49000;
+	return true;
+}
+void UartBusReadDataFunc(uint16 RegAddrBegin, uint16 Reg_Num, bool (*decodeFunc)(uint8 *dataPtr))
+{
+	// argv In
+	UartQueryType Uart0AskMsg;
+	uint16 ReadLen1 = 0;
+	uint16 ReadLenTar = 0;
+	uint8 ReadDelayCounter = 0;
+	uint16 CRC_chk_buffer = 0;
+	uint16 pReadLen = 0;
+	UartAnsType UartAnsData;
+	uint8 UartDataRecv[256];
+
+	Uart0AskMsg.Bms_Address = BMS_ADDRESS_CODE;
+	Uart0AskMsg.Bms_Funcode = UART_READ_CODE;
+	Uart0AskMsg.Reg_Begin_H = RegAddrBegin >> 8;
+	Uart0AskMsg.Reg_Begin_L = RegAddrBegin;
+	Uart0AskMsg.Reg_Num_H = Reg_Num >> 8;
+	Uart0AskMsg.Reg_Num_L = Reg_Num;
+	CRC_chk_buffer = crc_chk((uint8 *)&Uart0AskMsg, 6);
+	Uart0AskMsg.CRC_L = CRC_chk_buffer;
+	Uart0AskMsg.CRC_H = CRC_chk_buffer >> 8;
+	UART_Send_Data(UART_LPUART0, (uint8 *)&Uart0AskMsg, sizeof(Uart0AskMsg), 100);
+	ReadLenTar = (Reg_Num)*2 + 5;
+	memset((uint8 *)&UartAnsData, 0x00, sizeof(UartAnsData));
+	while (1)
+	{
+		UART_Receive_Data(UART_LPUART0, UartDataRecv, &pReadLen, 100);
+		if (pReadLen > 2)
+		{
+			memcpy((uint8 *)&UartAnsData + ReadLen1, UartDataRecv, pReadLen);
+			ReadLen1 = ReadLen1 + pReadLen;
+		}
+		else
+		{
+			ReadDelayCounter++;
+		}
+		if (ReadLen1 >= ReadLenTar)
+		{
+			ReadDelayCounter = 0;
+			pReadLen = ReadLen1;
+			ReadLen1 = 0;
+			break;
+		}
+		if (ReadDelayCounter >= 20)
+		{
+			ReadDelayCounter = 0;
+			pReadLen = 0;
+			ReadLen1 = 0;
+			break;
+		}
+	}
+	if (pReadLen > 0)
+	{
+		uint16 CrcChkGet = 0xffff;
+		uint16 CrcChkCal = 0x0000;
+		CrcChkCal = crc_chk((uint8 *)&UartAnsData, pReadLen - 2);
+		CrcChkGet = ((uint16)(UartAnsData.Data[pReadLen - 1 - 3]) << 8) | ((uint16)(UartAnsData.Data[pReadLen - 2 - 3]));
+		if (CrcChkCal == CrcChkGet)
+		{
+			decodeFunc(UartAnsData.Data);
+			UartNoDataReadCounter = 0;
+		}
+		else
+		{
+			UartNoDataReadCounter++;
+		}
+	}
+	else
+	{
+		UartNoDataReadCounter++;
+	}
+}
+
+#endif

+ 18 - 16
src/AppTaskUart0.h → code/app/AppTaskUart0.h

@@ -1,10 +1,12 @@
-/*
- * AppTaskUart0.h
- *
- *  Created on: 2022Äê2ÔÂ22ÈÕ
- *      Author: QiXiang_CHENJIE
+/*** 
+ * @Author: chenjie
+ * @Date: 2022-06-06
+ * @LastEditTime: 2022-10-27
+ * @LastEditors: chenjie
+ * @Description: 
+ * @FilePath: \S32K146_4G\code\app\AppTaskUart0.h
+ * @Copyright (c) 2022 by chenjie, All Rights Reserved.
  */
-
 #ifndef APPTASKUART0_H_
 #define APPTASKUART0_H_
 #include "hal_adapter.h"
@@ -13,24 +15,24 @@
 #ifdef APP_UART0_ENABLE
 #define BMS_ADDRESS_CODE 0x01
 #define METER1_ADDRESS_CODE 0x04
-#define UART_READ_CODE 0x03
-#define UART_WRITE_CODE 0x10
+#define UART_READ_CODE 0x04
+#define UART_WRITE_CODE 0x06
 #define UART_ENCRYPT_CODE 0x05
 #define UART_WRITE_FLAG 0x01
 #define UART_READ_FLAG 0x00
 void Uart0Task(void *pvParameters);
 typedef struct _UartAnsType
 {
-	uint8 BmsAdd;
-	uint8 FunCode;
-	uint8 Datalen;
+    uint8 BmsAdd;
+    uint8 FunCode;
+    uint8 Datalen;
     uint8 Data[300];
-}UartAnsType;
+} UartAnsType;
 typedef enum
 {
     PROCESS_UART_STATE_IDLE = 0,
     PROCESS_UART_STATE_READ,
-	PROCESS_UART_STATE_WRITE,
+    PROCESS_UART_STATE_WRITE,
     PROCESS_UART_STATE_SLEEP
 } process_Uart0;
 typedef struct _UartQueryType
@@ -46,9 +48,9 @@ typedef struct _UartQueryType
 } UartQueryType;
 typedef struct _UartWriteMsgType
 {
-	uint8 Bms_Address;
-	uint8 Bms_Funcode;
-	uint8 Reg_Begin_H;
+    uint8 Bms_Address;
+    uint8 Bms_Funcode;
+    uint8 Reg_Begin_H;
     uint8 Reg_Begin_L;
     uint8 Reg_Num_H;
     uint8 Reg_Num_L;

+ 150 - 151
src/AppTaskUart1.c → code/app/AppTaskUart1.c

@@ -1,17 +1,11 @@
 /*
- * @Author       : ChenJie
- * @Date         : 2022-02-10 11:43:56
- * @Version      : V3.0
- * @LastEditors  : ChenJie
- * @LastEditTime : 2022-02-23 15:51:23
- * @Description  : file content
- * @FilePath     : \S32K146_4G\src\AppTaskUart1.c
- */
-/*
- * AppTaskUart2.c
- *  4G的串口函数
- *  Created on: 2022年2月10日
- *      Author: QiXiang_CHENJIE
+ * @Author: chenjie
+ * @Date: 2022-06-06
+ * @LastEditTime: 2022-10-27
+ * @LastEditors: chenjie
+ * @Description: 
+ * @FilePath: \S32K146_4G\code\app\AppTaskUart1.c
+ * Copyright (c) 2022 by chenjie, All Rights Reserved.
  */
 #include "AppTaskUart1.h"
 #include "hal_fls.h"
@@ -56,8 +50,8 @@ void Uart_4G_Task(void *pvParameters)
 	uint8 UartRecvPtr[512];
 	volatile uint16 tcpErrorCounter = 0;
 	uint16 pReadLen = 0;
-	// 4G开机
-	Dio_LevelType _4G_Status = 0; // 0-关机,1-开机
+	// 4G寮€鏈�
+	Dio_LevelType _4G_Status = 0; // 0-鍏虫満锛�1-寮€鏈�
 	Dio_WriteChannel(DioConf_DioChannel_PTA6_GPIO_OUT_MCU_4G_POW_EN, STD_ON);
 	vTaskDelay(pdMS_TO_TICKS(50));
 	Dio_WriteChannel(DioConf_DioChannel_PTA7_GPIO_OUT_MCU_4G_PWRKEY, STD_ON);
@@ -65,7 +59,7 @@ void Uart_4G_Task(void *pvParameters)
 	AtcmdDelayRecvFunc(UART_LPUART1,(char *)("SMS DONE"),30000);
 	Dio_WriteChannel(DioConf_DioChannel_PTA7_GPIO_OUT_MCU_4G_PWRKEY, STD_OFF);
 	_4G_Status = Dio_ReadChannel(DioConf_DioChannel_PTB1_GPIO_IN_MCU_4G_STATUS);
-	InitFunc(); // 4G模块初始化,注:AT同步不通过,没有进行次数判定及跳转
+	InitFunc(); // 4G妯″潡鍒濆�鍖�,娉�細AT鍚屾�涓嶉€氳繃锛屾病鏈夎繘琛屾�鏁板垽瀹氬強璺宠浆
 	TimerHandle_t monitorTimer1000ms;
 	monitorTimer1000ms = xTimerCreate("monitor1000ms",1000,pdTRUE,(void *)0,vTimer1000msCallback);
 	xTimerStart(monitorTimer1000ms,0);
@@ -73,9 +67,9 @@ void Uart_4G_Task(void *pvParameters)
 	{
 		switch (gProcess_Tcp_Task)
 		{
-		case PROCESS_TCP_IDLE: //空闲状态
+		case PROCESS_TCP_IDLE: //绌洪棽鐘舵€�
 		{
-			UART_Receive_Data(UART_LPUART1, UartRecvPtr, &pReadLen, 100);//100ms检测
+			UART_Receive_Data(UART_LPUART1, UartRecvPtr, &pReadLen, 100);//100ms妫€娴�
 			if (SocketId < 0)
 			{
 				PROC_TCP_STATE_SWITCH(PROCESS_TCP_REGCHK);
@@ -90,7 +84,7 @@ void Uart_4G_Task(void *pvParameters)
 				SendTimerFlg = false;
 				PROC_TCP_STATE_SWITCH(PROCESS_TCP_SEND);
 			}
-			if((TimerCounter-RecvTimerDelay)>=30000 && TcpWorkState==1)//10s内没有命令下发,进行正常发送任务
+			if((TimerCounter-RecvTimerDelay)>=30000 && TcpWorkState==1)//10s鍐呮病鏈夊懡浠や笅鍙戯紝杩涜�姝e父鍙戦€佷换鍔�
 			{
 				TcpWorkState = 0;
 			}
@@ -110,10 +104,10 @@ void Uart_4G_Task(void *pvParameters)
 			}
 			break;
 		}
-		case PROCESS_TCP_REGCHK: //驻网检查,包括SIM,CPIN检查,ICCID获取
+		case PROCESS_TCP_REGCHK: //椹荤綉妫€鏌ワ紝鍖呮嫭SIM锛孋PIN妫€鏌�,ICCID鑾峰彇
 		{
 			RegChkRet = TcpRegisterChkFunc();
-			if (RegChkRet > 0) //检查通过,SIM卡已就绪,已进行驻网
+			if (RegChkRet > 0) //妫€鏌ラ€氳繃锛孲IM鍗″凡灏辩华锛屽凡杩涜�椹荤綉
 			{
 				PROC_TCP_STATE_SWITCH(PROCESS_TCP_CONNECT);
 			}
@@ -123,7 +117,7 @@ void Uart_4G_Task(void *pvParameters)
 			}
 			break;
 		}
-		case PROCESS_TCP_CONNECT: //网络连接,包括域名转换
+		case PROCESS_TCP_CONNECT: //缃戠粶杩炴帴锛屽寘鎷�煙鍚嶈浆鎹�
 		{
 			if (SocketId < 0)
 			{
@@ -140,7 +134,7 @@ void Uart_4G_Task(void *pvParameters)
 			}
 			break;
 		}
-		case PROCESS_TCP_SEND: //网络数据发送
+		case PROCESS_TCP_SEND: //缃戠粶鏁版嵁鍙戦€�
 		{
 			sint8 SendRet = -1;
 			SendRet = TcpDataSendFunc(SocketId);
@@ -156,7 +150,7 @@ void Uart_4G_Task(void *pvParameters)
 			}
 			break;
 		}
-		case PROCESS_TCP_RECV: //网络数据接收,100ms空闲状态下即可接收
+		case PROCESS_TCP_RECV: //缃戠粶鏁版嵁鎺ユ敹,100ms绌洪棽鐘舵€佷笅鍗冲彲鎺ユ敹
 		{
 			Dio_FlipChannel(DioConf_DioChannel_PTE0_GPIO_OUT_MCU_LED1);
 
@@ -167,19 +161,19 @@ void Uart_4G_Task(void *pvParameters)
 			PROC_TCP_STATE_SWITCH(PROCESS_TCP_IDLE);
 			break;
 		}
-		case PROCESS_TCP_HEART: //心跳包发送
+		case PROCESS_TCP_HEART: //蹇冭烦鍖呭彂閫�
 		{
 			break;
 		}
-		case PROCESS_TCP_SLEEP: //网络休眠状态
+		case PROCESS_TCP_SLEEP: //缃戠粶浼戠湢鐘舵€�
 		{
 			break;
 		}
-		case PROCESS_TCP_ERROR: //错误状态
+		case PROCESS_TCP_ERROR: //閿欒�鐘舵€�
 		{
 			vTaskDelay(pdMS_TO_TICKS(1000));
 			tcpErrorCounter++;
-			if(tcpErrorCounter>60&&TcpSysReboot == 1)//无法驻网或者联网
+			if(tcpErrorCounter>60&&TcpSysReboot == 1)//鏃犳硶椹荤綉鎴栬€呰仈缃�
 			{
 				Dio_WriteChannel(DioConf_DioChannel_PTA7_GPIO_OUT_MCU_4G_PWRKEY, STD_ON);
 				vTaskDelay(pdMS_TO_TICKS(2500));
@@ -208,12 +202,12 @@ sint8 TcpDataSendFunc(sint8 ConnectId)
 	sint8 outValue = -1;
 	uint32 pSendDataAddr = 0;
 	uint16 DataSendLen = 0;
-	TcpDataEncode(&pSendDataAddr, &DataSendLen); //数据组包,malloc申请在里面,pSendData指向申请的地址
+	TcpDataEncode(&pSendDataAddr, &DataSendLen); //鏁版嵁缁勫寘锛宮alloc鐢宠�鍦ㄩ噷闈�,pSendData鎸囧悜鐢宠�鐨勫湴鍧€
 	if (DataSendLen == 0)
 	{
-		return 0; //暂时无数据可以发
+		return 0; //鏆傛椂鏃犳暟鎹�彲浠ュ彂
 	}
-	outValue = tcpipConnectionSend(ConnectId, (uint8 *)pSendDataAddr, DataSendLen); //发送函数
+	outValue = tcpipConnectionSend(ConnectId, (uint8 *)pSendDataAddr, DataSendLen); //鍙戦€佸嚱鏁�
 	if (pSendDataAddr != 0)
 	{
 		vPortFree((uint8 *)(pSendDataAddr));
@@ -228,26 +222,23 @@ sint8 tcpipConnectionSend(uint8 TcpConnectId, uint8 *SendDataPtr, uint16 SendDat
 	uint16 ReadLen = 0;
 	char AtCmdSend[30] = {0};
 	uint8 AtCmdSendTotalLen = 0;
-	uint8 UartRecvPtr[128];//暂存buffer改大
+	uint8 UartRecvPtr[128];//鏆傚瓨buffer鏀瑰ぇ
 	uint8 ret = 0;
 	sprintf(AtCmdSend, "AT+CIPSEND=%d,%d\r\n", TcpConnectId, SendDataLen);
 	AtCmdSendTotalLen = mstrlen(AtCmdSend);
 	while(outValue!=0&&sendErrConuter<3)
 	{
 		ret = UART_Query_Data(UART_LPUART1, UART_LPUART1, (uint8 *)AtCmdSend, AtCmdSendTotalLen, UartRecvPtr, &ReadLen, 1000);
-		if (((ret==0)&&(ReadLen>0)&&((uint8 *)strstr((char *)UartRecvPtr, (char *)(">"))))||1)//此IF条件默认通过
+		if (((ret==0)&&(ReadLen>0)&&((uint8 *)strstr((char *)UartRecvPtr, (char *)(">"))))||1)//姝�F鏉′欢榛樿�閫氳繃
 		{
 			UART_Send_Data(UART_LPUART1, (uint8 *)SendDataPtr, SendDataLen, 1000);
-			sint8 ret = AtcmdDelayRecvFunc(UART_LPUART1,(char *)("+CIPSEND"),5000);
+			sint8 ret = AtcmdDelayRecvFunc(UART_LPUART1,(char *)("+CIPSEND"),2000);
 			if (ret==0)
 			{
 				outValue = 0;
 			}
 			else
 			{
-#if SEGGER_PRINTF==1
-			SEGGER_RTT_printf("[%d]sendFault!!!\r\n",__LINE__);
-#endif
 				outValue = -2;
 				sendErrConuter++;
 			}
@@ -257,9 +248,6 @@ sint8 tcpipConnectionSend(uint8 TcpConnectId, uint8 *SendDataPtr, uint16 SendDat
 			outValue = -1;
 			sendErrConuter++;
 		}
-#if SEGGER_PRINTF==1
-			SEGGER_RTT_printf("[%d]outValue=%d,sendErrConuter=%d\r\n",__LINE__,outValue,sendErrConuter);
-#endif
 	}
 	return outValue;
 }
@@ -273,7 +261,7 @@ sint8 TcpConnectFunc(sint8 *ConnectId)
 	{
 		switch (ConnectStep)
 		{
-		case 0: // AT指令同步
+		case 0: // AT鎸囦护鍚屾�
 		{
 			char *ATCmdSend = (char *)("ATE0\r\n");
 			uint8 ATCmdSendLen = mstrlen(ATCmdSend);
@@ -314,9 +302,9 @@ sint8 TcpConnectFunc(sint8 *ConnectId)
 			}
 			break;
 		}
-		case 2: //连接检查
+		case 2: //杩炴帴妫€鏌�
 		{
-			AtcmdTransmit(AT_CONNECTCHK, NULL, 0, &ATRet,1000); // ATret返回的值是连接id,如果未连接返回-1
+			AtcmdTransmit(AT_CONNECTCHK, NULL, 0, &ATRet,1000); // ATret杩斿洖鐨勫€兼槸杩炴帴id锛屽�鏋滄湭杩炴帴杩斿洖-1
 			if (ATRet >= 0)
 			{
 				*ConnectId = ATRet;
@@ -328,7 +316,7 @@ sint8 TcpConnectFunc(sint8 *ConnectId)
 			}
 			break;
 		}
-		case 3: //域名转换
+		case 3: //鍩熷悕杞�崲
 		{
 			char AtCmdSend[30] = {0};
 			uint8 AtCmdSendLen = 0;
@@ -348,18 +336,18 @@ sint8 TcpConnectFunc(sint8 *ConnectId)
 			}
 			break;
 		}
-		case 4: //创建连接
+		case 4: //鍒涘缓杩炴帴
 		{
 			char AtCmdSend[50] = {0};
 			uint8 AtCmdSendTotalLen = 0;
 			*ConnectId = 0;
-			/*IP测试更改*/
+			/*IP娴嬭瘯鏇存敼*/
 //			char *ATCmdSend = (char *)("\"120.26.68.165\"");
 //			memset(WebSiteIp,0x00,sizeof(WebSiteIp));
 //			memcpy(WebSiteIp ,ATCmdSend,strlen(ATCmdSend));
 //			WebSitePort = 14401;
 			/**/
-			sprintf(AtCmdSend, "AT+CIPOPEN=%d,\"TCP\",%s,%d\r\n", *ConnectId, WebSiteIp, WebSitePort); //此处需要优化
+			sprintf(AtCmdSend, "AT+CIPOPEN=%d,\"TCP\",%s,%d\r\n", *ConnectId, WebSiteIp, WebSitePort); //姝ゅ�闇€瑕佷紭鍖�
 			AtCmdSendTotalLen = mstrlen(AtCmdSend);
 			UART_Send_Data(UART_LPUART1, AtCmdSend, AtCmdSendTotalLen, pdMS_TO_TICKS(100));
 			ATRet = AtcmdDelayRecvFunc(UART_LPUART1,(char *)("+CIPOPEN: 0,0"),20000);
@@ -384,13 +372,13 @@ sint8 TcpConnectFunc(sint8 *ConnectId)
 sint8 TcpRegisterChkFunc(void)
 {
 	uint8 RegChkStep = 0;
-	sint8 ChkState = 0; //默认为0
+	sint8 ChkState = 0; //榛樿�涓�0
 	sint8 ATRet = -1;
 	while (1)
 	{
 		switch (RegChkStep)
 		{
-		case 0: // AT指令同步
+		case 0: // AT鎸囦护鍚屾�
 		{
 			AtcmdTransmit(AT_CMD_TEST, NULL, 0, &ATRet,100);
 			if (ATRet == 0)
@@ -404,7 +392,7 @@ sint8 TcpRegisterChkFunc(void)
 			}
 			break;
 		}
-		case 1: // CPIN检查
+		case 1: // CPIN妫€鏌�
 		{
 			AtcmdTransmit(AT_SIMREADY, NULL, 0, &ATRet,100);
 			if (ATRet == 0)
@@ -420,7 +408,7 @@ sint8 TcpRegisterChkFunc(void)
 		}
 		case 2:
 		{
-			AtcmdTransmit(AT_CGREG, NULL, 0, &ATRet,1000); //驻网检查,返回值1和5是驻网成功
+			AtcmdTransmit(AT_CGREG, NULL, 0, &ATRet,1000); //椹荤綉妫€鏌ワ紝杩斿洖鍊�1鍜�5鏄�┗缃戞垚鍔�
 			if (ATRet == 1 || ATRet == 5)
 			{
 				RegChkStep++;
@@ -441,7 +429,7 @@ sint8 TcpRegisterChkFunc(void)
 }
 void InitFunc(void)
 {
-	// 4G模块初始化
+	// 4G妯″潡鍒濆�鍖�
 	uint8 _4G_InitStep = 0;
 	sint8 ATRet = -1;
 	uint16 ReadLen = 0;
@@ -454,7 +442,7 @@ void InitFunc(void)
 	{
 		switch (_4G_InitStep)
 		{
-		case 0: // AT指令同步
+		case 0: // AT鎸囦护鍚屾�
 		{
 			AtcmdTransmit(AT_CMD_TEST, NULL, 0, &ATRet,100);
 			if (ATRet == 0)
@@ -473,7 +461,7 @@ void InitFunc(void)
 			}
 			break;
 		}
-		case 1: //关闭回显
+		case 1: //鍏抽棴鍥炴樉
 		{
 			ATCmdSend = (char *)("ATE0\r\n");
 			ATCmdSendLen = mstrlen(ATCmdSend);
@@ -496,7 +484,7 @@ void InitFunc(void)
 			}
 			break;
 		}
-		case 2: // IMEI获取
+		case 2: // IMEI鑾峰彇
 		{
 			ATCmdSend = (char *)("AT+SIMEI?\r\n");
 			ATCmdSendLen = mstrlen(ATCmdSend);
@@ -520,7 +508,7 @@ void InitFunc(void)
 			}
 			break;
 		}
-		case 3: // 打开时间自动更新
+		case 3: // 鎵撳紑鏃堕棿鑷�姩鏇存柊
 		{
 			ATCmdSend = (char *)("AT+CTZU=1\r\n");
 			ATCmdSendLen = mstrlen(ATCmdSend);
@@ -539,7 +527,7 @@ void InitFunc(void)
 			}
 			break;
 		}
-		case 4: // ICCID获取
+		case 4: // ICCID鑾峰彇
 		{
 			AtcmdTransmit(AT_GETICCID, NULL, 0, &ATRet,1000);
 			if (ATRet == 0)
@@ -669,7 +657,7 @@ sint8 at_callbackFunc(char *PSendStr, char *pReadStr, uint8 CmdIdx, uint16 pRead
 		{
 			OutValue = 0;
 		}
-		retptr = (uint8 *)strstr((char *)pReadStr, (char *)("opened")); //重复打开
+		retptr = (uint8 *)strstr((char *)pReadStr, (char *)("opened")); //閲嶅�鎵撳紑
 		if (retptr)
 		{
 			OutValue = 0;
@@ -742,47 +730,56 @@ void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen)
 	static UTC8TimeType UTC8TimeTcp;
 	uint8 *SendBuffer = NULL;
 	uint8 DataIdx = 0;
-#if SEGGER_PRINTF==1
-	SEGGER_RTT_printf("[%d] TcpSendTimeCounter=%d\r\n",__LINE__,TcpSendTimeCounter);
-#endif
 	if (TcpSendTimeCounter == 5)
 	{
-		DataIdx = VerMsg; //版本信息发送
+		DataIdx = VerMsg; //鐗堟湰淇℃伅鍙戦€�
 	}
 	else if (TcpSendTimeCounter % 10 == 1)
 	{
-		DataIdx = BattMsg; //电池信息发送
+		DataIdx = BattMsg; //鐢垫睜淇℃伅鍙戦€�
 	}
 	else if ((TcpSendTimeCounter) % 10 == 2)
 	{
-		DataIdx = 0x83; //储能开关信息发送
+		DataIdx = 0x83; //鍌ㄨ兘寮€鍏充俊鎭�彂閫�
 	}
 	else if ((TcpSendTimeCounter) % 240 == 3)
 	{
-		DataIdx = GpsMsg; //定位信息发送
+		DataIdx = GpsMsg; //瀹氫綅淇℃伅鍙戦€�
 	}
 	else if ((TcpSendTimeCounter) % 240 == 4)
 	{
-		DataIdx = 0x93; //储能电量信息发送
+		DataIdx = 0x93; //鍌ㄨ兘鐢甸噺淇℃伅鍙戦€�
 	}
 	else if ((TcpSendTimeCounter) % 60 == 5)
 	{
-		DataIdx = 0x8A; //累计信息发送
+		DataIdx = 0x8A; //绱��淇℃伅鍙戦€�
 	}
+//	else if ((TcpSendTimeCounter) % (60*60*2) == 6)
+//	{
+//		DataIdx = 0x01; //鏃堕棿鏍″噯
+//	}
+//鏆傛椂涓嶈繘琛屾椂闂存牎鍑嗭紝娴嬭瘯鏃堕棿鍑嗙‘
 	else
 	{
 		*SendLen = 0;
-		DataIdx = 0; //不发送,返回
+		DataIdx = 0; //涓嶅彂閫�,杩斿洖
 		return;
 	}
-#if SEGGER_PRINTF==1
-	SEGGER_RTT_printf("\r\n[%d] DataIdx -%X\r\n",__LINE__,DataIdx);
-#endif
 	memcpy(TcpbattSN, AppConfigInfo.deviceSn, 17);
-	GetUtc8Time(&UTC8TimeTcp); //时间获取
+	GetUtc8Time(&UTC8TimeTcp); //鏃堕棿鑾峰彇
 	vTaskDelay(pdMS_TO_TICKS(100));
 	switch (DataIdx)
 	{
+	case 0x01://鏃堕棿鏍″噯
+	{
+		char *ATCmdSend = (char *)("AT+CNTP\r\n");
+		uint8 ATCmdSendLen = mstrlen(ATCmdSend);
+		uint8 ReadLen = 0;
+		uint8 UartRecvPtr[20];
+		UART_Query_Data(UART_LPUART1, UART_LPUART1, (uint8 *)ATCmdSend, ATCmdSendLen,UartRecvPtr, &ReadLen, pdMS_TO_TICKS(500));
+		*SendLen = 0;//涓嶅彂閫侊紝闀垮害涓�0
+		return;
+	}
 	case 0x82:
 	{
 		GPSInfo GpsRecvData;
@@ -827,26 +824,25 @@ void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen)
 		GpsToTcpInfo.gpsInfo.CellID[0] = cellId >> 16;
 		GpsToTcpInfo.gpsInfo.CellID[0] = cellId >> 8;
 		GpsToTcpInfo.gpsInfo.CellID[0] = cellId;
-		uint16 xyzDatacahce[3] = {0};
-		memcpy(xyzDatacahce, xyzData, 3);
+		uint16 xyzDatacache[3] = {0};
+		memcpy(xyzDatacache, xyzData, 3*sizeof(uint16));
 		for (uint8 i = 0; i < 3; i++)
 		{
-			if (xyzDatacahce[i] > 0x8000) // 数据为负
+			if (xyzDatacache[i] > 0x8000) // 鏁版嵁涓鸿礋
 			{
-				xyzDatacahce[i] = (uint16)((uint16)(~(xyzDatacahce[i])) + 1);
-				xyzDatacahce[i] = 20000U - xyzDatacahce[i];
+				xyzDatacache[i] = 20000U + (sint16)xyzDatacache[i];
 			}
 			else
 			{
-				xyzDatacahce[i] = xyzDatacahce[i] + 20000U;
+				xyzDatacache[i] = xyzDatacache[i] + 20000U;
 			}
 		}
-		GpsToTcpInfo.gpsInfo.xData[0] = xyzDatacahce[0] >> 8;
-		GpsToTcpInfo.gpsInfo.xData[1] = xyzDatacahce[0];
-		GpsToTcpInfo.gpsInfo.yData[0] = xyzDatacahce[1] >> 8;
-		GpsToTcpInfo.gpsInfo.yData[1] = xyzDatacahce[1];
-		GpsToTcpInfo.gpsInfo.zData[0] = xyzDatacahce[2] >> 8;
-		GpsToTcpInfo.gpsInfo.zData[1] = xyzDatacahce[2];
+		GpsToTcpInfo.gpsInfo.xData[0] = xyzDatacache[0] >> 8;
+		GpsToTcpInfo.gpsInfo.xData[1] = xyzDatacache[0];
+		GpsToTcpInfo.gpsInfo.yData[0] = xyzDatacache[1] >> 8;
+		GpsToTcpInfo.gpsInfo.yData[1] = xyzDatacache[1];
+		GpsToTcpInfo.gpsInfo.zData[0] = xyzDatacache[2] >> 8;
+		GpsToTcpInfo.gpsInfo.zData[1] = xyzDatacache[2];
 		GpsToTcpInfo.CRC = bcc_chk((uint8 *)&GpsToTcpInfo, sizeof(GPSMsgtoTcpType) - 1);
 		memcpy(SendBuffer, &GpsToTcpInfo, sizeof(GpsToTcpInfo));
 		*PtrSendAddr = (uint32)SendBuffer;
@@ -888,23 +884,23 @@ void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen)
 		VerMsgToTcpInfo.VerInfo.BMSSwVersion[1] = bmsSwVersion>>16;
 		VerMsgToTcpInfo.VerInfo.BMSSwVersion[2] = bmsSwVersion>>8;
 		VerMsgToTcpInfo.VerInfo.BMSSwVersion[3] = bmsSwVersion;
-		VerMsgToTcpInfo.VerInfo.HwVersion[0] = (HWVERSION >> 8) & 0xFF;
-		VerMsgToTcpInfo.VerInfo.HwVersion[1] = (HWVERSION)&0xFF;
-		VerMsgToTcpInfo.VerInfo.BLVersion[0] = (BLSWVERSION >> 24) & 0xFF;
-		VerMsgToTcpInfo.VerInfo.BLVersion[1] = (BLSWVERSION >> 16) & 0xFF;
-		VerMsgToTcpInfo.VerInfo.BLVersion[2] = (BLSWVERSION >> 8) & 0xFF;
-		VerMsgToTcpInfo.VerInfo.BLVersion[3] = (BLSWVERSION)&0xFF;
-		VerMsgToTcpInfo.VerInfo.DRVVersion[0] = (DRVSWVERSION >> 24) & 0xFF;
-		VerMsgToTcpInfo.VerInfo.DRVVersion[1] = (DRVSWVERSION >> 16) & 0xFF;
-		VerMsgToTcpInfo.VerInfo.DRVVersion[2] = (DRVSWVERSION >> 8) & 0xFF;
-		VerMsgToTcpInfo.VerInfo.DRVVersion[3] = (DRVSWVERSION)&0xFF;
-		VerMsgToTcpInfo.VerInfo.APPVersion[0] = (APPSWVERSION >> 24) & 0xFF;
-		VerMsgToTcpInfo.VerInfo.APPVersion[1] = (APPSWVERSION >> 16) & 0xFF;
-		VerMsgToTcpInfo.VerInfo.APPVersion[2] = (APPSWVERSION >> 8) & 0xFF;
-		VerMsgToTcpInfo.VerInfo.APPVersion[3] = (APPSWVERSION)&0xFF;
-		VerMsgToTcpInfo.VerInfo.BmsType = BMS_MANUFACTURE;
-		VerMsgToTcpInfo.VerInfo.BmsInfo = BMS_INFO;
-		VerMsgToTcpInfo.VerInfo.DataModuleType = DATA_MODULE_TYPE;
+		VerMsgToTcpInfo.VerInfo.HwVersion[0] = (HwVersion >> 8) & 0xFF;
+		VerMsgToTcpInfo.VerInfo.HwVersion[1] = (HwVersion)&0xFF;
+		VerMsgToTcpInfo.VerInfo.BLVersion[0] = (BlSwVersion >> 24) & 0xFF;
+		VerMsgToTcpInfo.VerInfo.BLVersion[1] = (BlSwVersion >> 16) & 0xFF;
+		VerMsgToTcpInfo.VerInfo.BLVersion[2] = (BlSwVersion >> 8) & 0xFF;
+		VerMsgToTcpInfo.VerInfo.BLVersion[3] = (BlSwVersion)&0xFF;
+		VerMsgToTcpInfo.VerInfo.DRVVersion[0] = (DrvSwVersion >> 24) & 0xFF;
+		VerMsgToTcpInfo.VerInfo.DRVVersion[1] = (DrvSwVersion >> 16) & 0xFF;
+		VerMsgToTcpInfo.VerInfo.DRVVersion[2] = (DrvSwVersion >> 8) & 0xFF;
+		VerMsgToTcpInfo.VerInfo.DRVVersion[3] = (DrvSwVersion)&0xFF;
+		VerMsgToTcpInfo.VerInfo.APPVersion[0] = (AppSwVersion >> 24) & 0xFF;
+		VerMsgToTcpInfo.VerInfo.APPVersion[1] = (AppSwVersion >> 16) & 0xFF;
+		VerMsgToTcpInfo.VerInfo.APPVersion[2] = (AppSwVersion >> 8) & 0xFF;
+		VerMsgToTcpInfo.VerInfo.APPVersion[3] = (AppSwVersion)&0xFF;
+		VerMsgToTcpInfo.VerInfo.BmsType = BmsManuFacture;
+		VerMsgToTcpInfo.VerInfo.BmsInfo = BmsInfo;
+		VerMsgToTcpInfo.VerInfo.DataModuleType = DataModuleType;
 		VerMsgToTcpInfo.CRC = bcc_chk((uint8 *)&VerMsgToTcpInfo, sizeof(VerMsgToTcpInfo) - 1);
 		memcpy(SendBuffer, &VerMsgToTcpInfo, sizeof(VersionMsgtoTcpType));
 		*PtrSendAddr = (uint32)SendBuffer;
@@ -914,74 +910,74 @@ void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen)
 	{
 		uint16 ErrorTemp;
 		ErrorTemp = GetErrorNum(ErrorArray,sizeof(ErrorArray)/2);
-		uint8 ProtocolHeaderLen = 25;																					  //电池信息协议头部加校验码长度,此长度不更改
-		uint8 ProtocolFixedLen = 60;																					  //电池信息协议固定总长度 如协议新增,需要更改此长度
-		uint16 ProtocolFluctedLen = AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount + BmsOtherTemp + OtherTemp; //电池信息协议变动长度
+		uint8 ProtocolHeaderLen = 25;																					  //鐢垫睜淇℃伅鍗忚�澶撮儴鍔犳牎楠岀爜闀垮害锛屾�闀垮害涓嶆洿鏀�
+		uint8 ProtocolFixedLen = 60;																					  //鐢垫睜淇℃伅鍗忚�鍥哄畾鎬婚暱搴� 濡傚崗璁�柊澧烇紝闇€瑕佹洿鏀规�闀垮害
+		uint16 ProtocolFluctedLen = AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount + BmsOtherTemp + OtherTemp; //鐢垫睜淇℃伅鍗忚�鍙樺姩闀垮害
 		uint16 DataLen;
 		*SendLen = ProtocolFixedLen + ProtocolFluctedLen;
 		SendBuffer = pvPortMalloc(*SendLen);
 		GetCSQValue(&CSQValue);
-		*(SendBuffer + 0) = TCP_START_SYM1;									 //起始码-1
-		*(SendBuffer + 1) = TCP_START_SYM2;									 //起始码-2
-		*(SendBuffer + 2) = TCP_CMD_SYM;									 //命令标识-3
-		*(SendBuffer + 3) = TCP_ANS_SYM;									 //应答标识-4
-		memcpy(SendBuffer + 4, TcpbattSN, BATT_SN_LEN);						 // SN 5-21
-		*(SendBuffer + 21) = TCP_ENCPT_DISABLE;								 //加密方式-22
-		DataLen = ProtocolFixedLen + ProtocolFluctedLen - ProtocolHeaderLen; //电池信息单元协议固定长度
-		*(SendBuffer + 22) = (DataLen >> 8) & 0xFF;							 //数据长度H-23
-		*(SendBuffer + 23) = DataLen & 0xFF;								 //数据长度L-24
+		*(SendBuffer + 0) = TCP_START_SYM1;									 //璧峰�鐮�-1
+		*(SendBuffer + 1) = TCP_START_SYM2;									 //璧峰�鐮�-2
+		*(SendBuffer + 2) = TCP_CMD_SYM;									 //鍛戒护鏍囪瘑-3
+		*(SendBuffer + 3) = TCP_ANS_SYM;									 //搴旂瓟鏍囪瘑-4
+		memcpy(SendBuffer + 4, TcpbattSN, BATT_SN_LEN);						 // SN鐮� 5-21
+		*(SendBuffer + 21) = TCP_ENCPT_DISABLE;								 //鍔犲瘑鏂瑰紡-22
+		DataLen = ProtocolFixedLen + ProtocolFluctedLen - ProtocolHeaderLen; //鐢垫睜淇℃伅鍗曞厓鍗忚�鍥哄畾闀垮害
+		*(SendBuffer + 22) = (DataLen >> 8) & 0xFF;							 //鏁版嵁闀垮害H-23
+		*(SendBuffer + 23) = DataLen & 0xFF;								 //鏁版嵁闀垮害L-24
 		*(SendBuffer + 24) = (UTC8TimeTcp.year) & 0xFF;						 // year-25
 		*(SendBuffer + 25) = UTC8TimeTcp.month & 0xFF;						 // month-26
 		*(SendBuffer + 26) = UTC8TimeTcp.day & 0xFF;						 // day-27
 		*(SendBuffer + 27) = UTC8TimeTcp.hour & 0xFF;						 // hour-28
 		*(SendBuffer + 28) = UTC8TimeTcp.minute & 0xFF;						 // mins-29
 		*(SendBuffer + 29) = UTC8TimeTcp.second & 0xFF;						 // sec-30
-		*(SendBuffer + 30) = DataIdx;										 //电池信息发送-31
+		*(SendBuffer + 30) = DataIdx;										 //鐢垫睜淇℃伅鍙戦€�-31
 		*(SendBuffer + 31) = (UTC8TimeTcp.year) & 0xFF;						 // year-32
 		*(SendBuffer + 32) = UTC8TimeTcp.month & 0xFF;						 // month-33
 		*(SendBuffer + 33) = UTC8TimeTcp.day & 0xFF;						 // day-34
 		*(SendBuffer + 34) = UTC8TimeTcp.hour & 0xFF;						 // hour-35
 		*(SendBuffer + 35) = UTC8TimeTcp.minute & 0xFF;						 // mins-36
 		*(SendBuffer + 36) = UTC8TimeTcp.second & 0xFF;						 // sec-37
-		*(SendBuffer + 37) = CSQValue;										 //信号强度-38
-		*(SendBuffer + 38) = 0;												 //故障等级-39
-		*(SendBuffer + 39) = ErrorTemp >> 8;								 //故障代码H-40
-		*(SendBuffer + 40) = ErrorTemp & 0xFF;								 //故障代码L-41
-		*(SendBuffer + 41) = battI >> 8;									 //电流-42
-		*(SendBuffer + 42) = battI & 0xFF;									 //电流-43
-		*(SendBuffer + 43) = battPackVol >> 8;								 //电压-44
-		*(SendBuffer + 44) = battPackVol & 0xFF;							 //电压-45
-		*(SendBuffer + 45) = battPackVol >> 8;								 //电压-46
-		*(SendBuffer + 46) = battPackVol & 0xFF;							 //电压-47
-		*(SendBuffer + 47) = battMOSSwitchState;							 // mos状态-48
+		*(SendBuffer + 37) = CSQValue;										 //淇″彿寮哄害-38
+		*(SendBuffer + 38) = 0;												 //鏁呴殰绛夌骇-39
+		*(SendBuffer + 39) = ErrorTemp >> 8;								 //鏁呴殰浠g爜H-40
+		*(SendBuffer + 40) = ErrorTemp & 0xFF;								 //鏁呴殰浠g爜L-41
+		*(SendBuffer + 41) = battI >> 8;									 //鐢垫祦-42
+		*(SendBuffer + 42) = battI & 0xFF;									 //鐢垫祦-43
+		*(SendBuffer + 43) = battPackVol >> 8;								 //鐢靛帇-44
+		*(SendBuffer + 44) = battPackVol & 0xFF;							 //鐢靛帇-45
+		*(SendBuffer + 45) = battPackVol >> 8;								 //鐢靛帇-46
+		*(SendBuffer + 46) = battPackVol & 0xFF;							 //鐢靛帇-47
+		*(SendBuffer + 47) = battMOSSwitchState;							 // mos鐘舵€�-48
 		*(SendBuffer + 48) = (uint8)(battSOC);					 // soc-49
 		*(SendBuffer + 49) = (uint8)(battSOH);					 // soh-50
 		*(SendBuffer + 50) = (battBalanceoInfo >> 24) & 0xFF;
 		*(SendBuffer + 51) = (battBalanceoInfo >> 16) & 0xFF;
 		*(SendBuffer + 52) = (battBalanceoInfo >> 8) & 0xFF;
-		*(SendBuffer + 53) = battBalanceoInfo & 0xFF;		  //均衡状态-51-54
-		*(SendBuffer + 54) = AppDataInfo.BattCellCount;		  //电压个数-55
-		for (uint8 i = 0; i < AppDataInfo.BattCellCount; i++) //单体电压
+		*(SendBuffer + 53) = battBalanceoInfo & 0xFF;		  //鍧囪 鐘舵€�-51-54
+		*(SendBuffer + 54) = AppDataInfo.BattCellCount;		  //鐢靛帇涓�暟-55
+		for (uint8 i = 0; i < AppDataInfo.BattCellCount; i++) //鍗曚綋鐢靛帇
 		{
 			*(SendBuffer + 54 + i * 2 + 1) = (battCellU[i] >> 8) & 0xFF;
 			*(SendBuffer + 54 + i * 2 + 2) = battCellU[i] & 0xFF;
 		}
-		*(SendBuffer + 55 + AppDataInfo.BattCellCount * 2) = AppDataInfo.BattTempCount;							   //模组温度个数
-		memcpy((SendBuffer + 55 + AppDataInfo.BattCellCount * 2 + 1), &battCellTemp, AppDataInfo.BattTempCount);   //模组温度
-		*(SendBuffer + 56 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount) = battWorkState;			   //电池工作状态
-		*(SendBuffer + 57 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount) = battHeatEnableState;	   //电池加热使能状态
-		*(SendBuffer + 58 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount) = BmsOtherTemp + OtherTemp; //其他温度个数
-		// *(SendBuffer + 58 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount + 1) = MOSTemp;																						  // mos温度
-		// *(SendBuffer + 58 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount + 2) = packTemp;																						  //环境温度
-		// *(SendBuffer + 58 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount + 3) = fastChargeTemp;																				  //快充温度
-		// *(SendBuffer + 58 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount + 4) = normalChargeTemp;																				  //慢充温度
-		// *(SendBuffer + 58 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount + 5) = heatTemp1;																						  //加热温度1
-		// *(SendBuffer + 58 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount + 6) = heatTemp2;																						  //加热温度2
-		*(SendBuffer + 59 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount + BmsOtherTemp + OtherTemp) = bcc_chk(SendBuffer, ProtocolFixedLen + ProtocolFluctedLen - 1); //校验码
+		*(SendBuffer + 55 + AppDataInfo.BattCellCount * 2) = AppDataInfo.BattTempCount;							   //妯$粍娓╁害涓�暟
+		memcpy((SendBuffer + 55 + AppDataInfo.BattCellCount * 2 + 1), &battCellTemp, AppDataInfo.BattTempCount);   //妯$粍娓╁害
+		*(SendBuffer + 56 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount) = battWorkState;			   //鐢垫睜宸ヤ綔鐘舵€�
+		*(SendBuffer + 57 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount) = battHeatEnableState;	   //鐢垫睜鍔犵儹浣胯兘鐘舵€�
+		*(SendBuffer + 58 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount) = BmsOtherTemp + OtherTemp; //鍏朵粬娓╁害涓�暟
+		// *(SendBuffer + 58 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount + 1) = MOSTemp;																						  // mos娓╁害
+		// *(SendBuffer + 58 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount + 2) = packTemp;																						  //鐜��娓╁害
+		// *(SendBuffer + 58 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount + 3) = fastChargeTemp;																				  //蹇�厖娓╁害
+		// *(SendBuffer + 58 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount + 4) = normalChargeTemp;																				  //鎱㈠厖娓╁害
+		// *(SendBuffer + 58 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount + 5) = heatTemp1;																						  //鍔犵儹娓╁害1
+		// *(SendBuffer + 58 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount + 6) = heatTemp2;																						  //鍔犵儹娓╁害2
+		*(SendBuffer + 59 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount + BmsOtherTemp + OtherTemp) = bcc_chk(SendBuffer, ProtocolFixedLen + ProtocolFluctedLen - 1); //鏍¢獙鐮�
 		*PtrSendAddr = (uint32)SendBuffer;
 		break;
 	}
-	case 0x83://储能场景的开关信息
+	case 0x83://鍌ㄨ兘鍦烘櫙鐨勫紑鍏充俊鎭�
 	{
 		StorageInfoToTcp StorageInfo;
 		*SendLen = sizeof(StorageInfo);
@@ -1018,7 +1014,7 @@ void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen)
 		*PtrSendAddr = (uint32)SendBuffer;
 		break;
 	}
-	case 0x93://储能场景的电量信息
+	case 0x93://鍌ㄨ兘鍦烘櫙鐨勭數閲忎俊鎭�
 	{
 		StorageInfoToTcp2 StorageInfo2;
 		*SendLen = sizeof(StorageInfo2);
@@ -1219,12 +1215,12 @@ static void TcpDataInfoRecvHandle(uint8 *DataRecv, uint16 DataRecvLen)
 	if (TcpDataLen > 0)
 	{
 		Ptr = retptr + 2;
-		if ((*(Ptr + 0) == TCP_START_SYM1) && (*(Ptr + 1) == TCP_START_SYM2)) //服务器起始信息
+		if ((*(Ptr + 0) == TCP_START_SYM1) && (*(Ptr + 1) == TCP_START_SYM2)) //鏈嶅姟鍣ㄨ捣濮嬩俊鎭�
 		{
-			Tcp_Cmd = *(Ptr + 2); //命令标志
+			Tcp_Cmd = *(Ptr + 2); //鍛戒护鏍囧織
 			if (*(Ptr + 3) == 0xFE)
 			{
-				TcpWorkState = 0x01;//需要暂停发送,进行命令应答的标志
+				TcpWorkState = 0x01;//闇€瑕佹殏鍋滃彂閫侊紝杩涜�鍛戒护搴旂瓟鐨勬爣蹇�
 			}
 			else
 			{
@@ -1241,7 +1237,7 @@ static void TcpDataInfoRecvHandle(uint8 *DataRecv, uint16 DataRecvLen)
 				TcpCmdAnswer[0] = TCP_START_SYM1;
 				TcpCmdAnswer[1] = TCP_START_SYM1;
 				TcpCmdAnswer[2] = TCP_CONCMD_SYM;
-				if (*(Ptr + 30) == 0x83) //远程升级指令
+				if (*(Ptr + 30) == 0x83) //杩滅▼鍗囩骇鎸囦护
 				{
                     TcpCmdAnswer[3] = 0x01;
                     memcpy(&TcpCmdAnswer[4], (Ptr + 4), BATT_SN_LEN);
@@ -1254,7 +1250,7 @@ static void TcpDataInfoRecvHandle(uint8 *DataRecv, uint16 DataRecvLen)
 					vTaskDelay(pdMS_TO_TICKS(5000));
 					Fota_Ftp(Ptr + 32);
 				}
-                else if (*(Ptr + 30) == 0x80) //远程锁定命令
+                else if (*(Ptr + 30) == 0x80) //杩滅▼閿佸畾鍛戒护
                 {
                     TcpCmdAnswer[3] = 0x01;
                     memcpy(&TcpCmdAnswer[4], (Ptr + 4), BATT_SN_LEN);
@@ -1263,13 +1259,13 @@ static void TcpDataInfoRecvHandle(uint8 *DataRecv, uint16 DataRecvLen)
                     TcpCmdAnswer[23] = 0x06;
                     memcpy(&TcpCmdAnswer[24], (Ptr + 24), 6);
                     TcpCmdAnswer[30] = bcc_chk(TcpCmdAnswer, 30);
-                    if (*(Ptr + 31) == 0x01) // 0x01代表锁定
+                    if (*(Ptr + 31) == 0x01) // 0x01浠h〃閿佸畾
                     {
                     	battSeparateEnable = 1;
                     	battSeparateCtlState = 1;
                         tcpipConnectionSend(SocketId, TcpCmdAnswer, 31 );
                     }
-                    else if (*(Ptr + 31) == 0x02) // 0x02代表解锁
+                    else if (*(Ptr + 31) == 0x02) // 0x02浠h〃瑙i攣
                     {
                     	battSeparateEnable = 1;
                     	battSeparateCtlState = 0;
@@ -1390,6 +1386,9 @@ void tcpUdsFunc(uint8 *Ptr,uint8 *AnsPtr)
 	*(AnsPtr+36) = 0x31;
 	*(AnsPtr+37) = bcc_chk(AnsPtr, 37);
 }
+
+
+/***************************************************************************************/
 void Fota_Ftp(uint8 *dataPtrIn)
 {
 	static uint8 ftp_process = 0;
@@ -1400,7 +1399,7 @@ void Fota_Ftp(uint8 *dataPtrIn)
 	uint16 ReadLen = 0;
 	uint8 *retptr = NULL;
 //	char temp[70]=",qx,qx900,120.27.243.131,21,0,0.0.1.5,0.0.1.5,/Debug/V0.0.1.5.bin,";
-	/*URL信息解析*/
+	/*URL淇℃伅瑙f瀽*/
 	char *databuffer[20];
 	char *accountPtr;
 	char *passwordPtr;
@@ -1416,7 +1415,7 @@ void Fota_Ftp(uint8 *dataPtrIn)
 	while (p&&index<20)
 	{
 		databuffer[index] = p;
-		p = strtok(NULL, ",");//报硬件错误
+		p = strtok(NULL, ",");//鎶ョ‖浠堕敊璇�
 		index++;
 	}
 	accountPtr = databuffer[0];

+ 14 - 19
src/AppTaskUart1.h → code/app/AppTaskUart1.h

@@ -1,19 +1,14 @@
-/*
- * @Author       : ChenJie
- * @Date         : 2022-02-10 11:44:08
- * @Version      : V3.0
- * @LastEditors  : ChenJie
- * @LastEditTime : 2022-05-17 16:22:56
- * @Description  : file content
- * @FilePath     : \S32K146_4G\src\AppTaskUart1.h
- */
-/*
- * AppTaskUart2.h
- *4G的串口函数
- *  Created on: 2022年2月10日
- *      Author: QiXiang_CHENJIE
+/*** 
+ * @Author: chenjie
+ * @Date: 2022-06-06
+ * @LastEditTime: 2022-10-27
+ * @LastEditors: chenjie
+ * @Description: 
+ * @FilePath: \S32K146_4G\code\app\AppTaskUart1.h
+ * @Copyright (c) 2022 by chenjie, All Rights Reserved.
  */
 
+
 #ifndef APPTASKUART1_H_
 #define APPTASKUART1_H_
 #include "hal_adapter.h"
@@ -24,8 +19,8 @@
 #define BATT_SN_LEN 17
 #define TCP_START_SYM1 0x23
 #define TCP_START_SYM2 0x23
-#define TCP_CMD_SYM 0x02   //实时信息上报是0x02
-#define TCP_HEART_SYM 0x07 //心跳包标志
+#define TCP_CMD_SYM 0x02   //瀹炴椂淇℃伅涓婃姤鏄�0x02
+#define TCP_HEART_SYM 0x07 //蹇冭烦鍖呮爣蹇�
 #define TCP_ANS_SYM 0xFE
 #define TCP_ENCPT_ENABLE 0x00
 #define TCP_ENCPT_DISABLE 0x01
@@ -191,9 +186,9 @@ typedef sint8 (*pFunc)(char *PSendStr, char *pReadStr, uint8 CmdIdx, uint16 pRea
 sint8 at_callbackFunc(char *PSendStr, char *pReadStr, uint8 CmdIdx, uint16 pReadLen);
 typedef struct
 {
-	ATCmd cmd; /*指令序号*/
-	char *str; /*指令内容*/
-	pFunc cb;  /*对应的执行*/
+	ATCmd cmd; /*鎸囦护搴忓彿*/
+	char *str; /*鎸囦护鍐呭�*/
+	pFunc cb;  /*瀵瑰簲鐨勬墽琛�*/
 } ATCmdFunc;
 typedef enum
 {

+ 1 - 1
src/UDSTask.c → code/app/UDSTask.c

@@ -1,7 +1,7 @@
 /*
  * UDSTask.c
  *
- *  Created on: 2022Äê3ÔÂ14ÈÕ
+ *  Created on: 2022Äê3ÔÂ14ÈÕ
  *      Author: Zhengchao
  */
 #include "UDSTask.h"

+ 1 - 1
src/UDSTask.h → code/app/UDSTask.h

@@ -1,7 +1,7 @@
 /*
  * UDSTask.h
  *
- *  Created on: 2022Äê3ÔÂ14ÈÕ
+ *  Created on: 2022Äê3ÔÂ14ÈÕ
  *      Author: Zhengchao
  */
 

+ 1 - 1
src/USER_CONFIG.h → code/app/USER_CONFIG.h

@@ -1,7 +1,7 @@
 /*
  * USER_CONFIG.h
  *
- *  Created on: 2022Äê4ÔÂ27ÈÕ
+ *  Created on: 2022Äê4ÔÂ27ÈÕ
  *      Author: Zhengchao
  */
 

+ 39 - 46
src/AppFuncLib.c → code/app/lib/AppFuncLib.c

@@ -1,25 +1,18 @@
 /*
- * @Author       : ChenJie
- * @Date         : 2022-01-21 09:28:20
- * @Version      : V3.0
- * @LastEditors  : ChenJie
- * @LastEditTime : 2022-02-14 15:23:30
- * @Description  : file content
- * @FilePath     : \S32K146_4G\src\AppFuncLib.c
+ * @Author: chenjie
+ * @Date: 2022-06-06
+ * @LastEditTime: 2022-10-27
+ * @LastEditors: chenjie
+ * @Description: 
+ * @FilePath: \S32K146_4G\code\app\lib\AppFuncLib.c
+ * Copyright (c) 2022 by chenjie, All Rights Reserved.
  */
-/*
- * AppFuncLib.c
- *应用层函数库
- *  Created on: 2022年1月21日
- *      Author: QiXiang_CHENJIE
- */
-
 #include "AppFuncLib.h"
 #include "AppGlobalVar.h"
 #include "Hal_Fls.h"
 #include "AppTaskUart1.h"
 /**
- * @brief : 获取故障码函数,从故障数组中获取故障码,并将之前的故障码向前移动
+ * @brief : 鑾峰彇鏁呴殰鐮佸嚱鏁帮紝浠庢晠闅滄暟缁勪腑鑾峰彇鏁呴殰鐮侊紝骞跺皢涔嬪墠鐨勬晠闅滅爜鍚戝墠绉诲姩
  * @param {UINT16} *ErrorArray
  * @param {UINT8} Errorlen
  * @return {*}
@@ -112,7 +105,7 @@ unsigned char HexToChar(unsigned char bHex)
 {
     if ((bHex >= 0) && (bHex <= 9))
         bHex += 0x30;
-    else if ((bHex >= 10) && (bHex <= 15)) //大写字母
+    else if ((bHex >= 10) && (bHex <= 15)) //澶у啓瀛楁瘝
         bHex += 0x37;
     else
         bHex = 0xff;
@@ -122,9 +115,9 @@ unsigned char CharToHex(unsigned char bChar)
 {
     if ((bChar >= 0x30) && (bChar <= 0x39))
         bChar -= 0x30;
-    else if ((bChar >= 0x41) && (bChar <= 0x46)) //大写字母
+    else if ((bChar >= 0x41) && (bChar <= 0x46)) //澶у啓瀛楁瘝
         bChar -= 0x37;
-    else if ((bChar >= 0x61) && (bChar <= 0x66)) //小写字母
+    else if ((bChar >= 0x61) && (bChar <= 0x66)) //灏忓啓瀛楁瘝
         bChar -= 0x57;
     else
         bChar = 0xff;
@@ -135,7 +128,7 @@ uint8 AtStrCompare(const char *a, const char *b)
     uint8 out = 1;
     while (1)
     {
-        if (*a == '\0' || *b == '\0') //判断其中是否有字符串结束
+        if (*a == '\0' || *b == '\0') //鍒ゆ柇鍏朵腑鏄�惁鏈夊瓧绗︿覆缁撴潫
         {
             if (strlen(a) == strlen(b))
             {
@@ -219,10 +212,10 @@ char *Myitoa(int value, char *result, int base)
 }
 
 /************************************************************************
- * @brief 整数转字符串
- * @param[in] num 整数
- * @param[out] buf 字符串
- * @return 返回字符串长度
+ * @brief 鏁存暟杞�瓧绗︿覆
+ * @param[in] num 鏁存暟
+ * @param[out] buf 瀛楃�涓�
+ * @return 杩斿洖瀛楃�涓查暱搴�
  ************************************************************************/
 inline int _itoa(int num, char buf[32])
 {
@@ -230,11 +223,11 @@ inline int _itoa(int num, char buf[32])
 }
 
 /************************************************************************
- * @brief 整数转字符串
- * @param[in] num 整数
- * @param[out] buf 字符串
- * @param[in] radix 进位制整数
- * @return 返回字符串长度
+ * @brief 鏁存暟杞�瓧绗︿覆
+ * @param[in] num 鏁存暟
+ * @param[out] buf 瀛楃�涓�
+ * @param[in] radix 杩涗綅鍒舵暣鏁�
+ * @return 杩斿洖瀛楃�涓查暱搴�
  ************************************************************************/
 int _i2a(int num, char buf[32], int radix)
 {
@@ -268,11 +261,11 @@ int _i2a(int num, char buf[32], int radix)
 }
 
 /************************************************************************
- * @brief 浮点数转字符串
- * @param[in] val 浮点数
- * @param[out] buf 字符串
- * @param[in] eps 精度(小数位)
- * @return 返回字符串长度
+ * @brief 娴�偣鏁拌浆瀛楃�涓�
+ * @param[in] val 娴�偣鏁�
+ * @param[out] buf 瀛楃�涓�
+ * @param[in] eps 绮惧害(灏忔暟浣�)
+ * @return 杩斿洖瀛楃�涓查暱搴�
  ************************************************************************/
 int _ftoa(double val, char buf[32], int eps)
 {
@@ -289,11 +282,11 @@ int _ftoa(double val, char buf[32], int eps)
 }
 
 /************************************************************************
- * @brief 浮点数转字符串:范围(-1, 1)
- * @param[in] val 浮点数
- * @param[out] buf 字符串
- * @param[in] eps 精度(小数位)
- * @return 返回字符串长度
+ * @brief 娴�偣鏁拌浆瀛楃�涓诧細鑼冨洿(-1, 1)
+ * @param[in] val 娴�偣鏁�
+ * @param[out] buf 瀛楃�涓�
+ * @param[in] eps 绮惧害(灏忔暟浣�)
+ * @return 杩斿洖瀛楃�涓查暱搴�
  ************************************************************************/
 int __ftoa(double val, char buf[32], int eps)
 {
@@ -313,8 +306,8 @@ int __ftoa(double val, char buf[32], int eps)
 }
 
 /************************************************************************
- * @brief 替换sprintf
- * @ref 可变长参数列表误区与陷阱——va_arg不可接受的类型
+ * @brief 鏇挎崲sprintf
+ * @ref 鍙�彉闀垮弬鏁板垪琛ㄨ�鍖轰笌闄烽槺鈥斺€攙a_arg涓嶅彲鎺ュ彈鐨勭被鍨�
  * http://www.cppblog.com/ownwaterloo/archive/2009/04/21/80655.aspx
  ************************************************************************/
 int _sprintf(char *dst, const char *format, ...)
@@ -336,7 +329,7 @@ int _sprintf(char *dst, const char *format, ...)
             ++f;
             switch (*f)
             {
-            case 's': // 字符串
+            case 's': // 瀛楃�涓�
             {
                 const char *p = va_arg(ap, char *);
                 n = strlen(p);
@@ -345,7 +338,7 @@ int _sprintf(char *dst, const char *format, ...)
             break;
 
             case 'd':
-            case 'u': // 整数
+            case 'u': // 鏁存暟
             {
                 char buf[32];
                 n = _itoa(va_arg(ap, int), buf);
@@ -353,7 +346,7 @@ int _sprintf(char *dst, const char *format, ...)
             }
             break;
 
-            case 'f': // 浮点数
+            case 'f': // 娴�偣鏁�
             {
                 char buf[32];
                 n = _ftoa(va_arg(ap, double), buf, 6);
@@ -361,7 +354,7 @@ int _sprintf(char *dst, const char *format, ...)
             }
             break;
 
-            case 'x': // 16进制数
+            case 'x': // 16杩涘埗鏁�
             {
                 char buf[32];
                 n = _i2a(va_arg(ap, int), buf, 16);
@@ -369,13 +362,13 @@ int _sprintf(char *dst, const char *format, ...)
             }
             break;
 
-            case 'c': // 字符
+            case 'c': // 瀛楃�
             {
                 *s = va_arg(ap, int);
             }
             break;
 
-            case '%': // 百分号
+            case '%': // 鐧惧垎鍙�
             {
                 *s = '%';
             }

+ 13 - 19
src/AppFuncLib.h → code/app/lib/AppFuncLib.h

@@ -1,17 +1,11 @@
-/*
- * @Author       : ChenJie
- * @Date         : 2022-01-23 13:45:09
- * @Version      : V3.0
- * @LastEditors  : ChenJie
- * @LastEditTime : 2022-02-14 15:24:03
- * @Description  : file content
- * @FilePath     : \S32K146_4G\src\AppFuncLib.h
- */
-/*
- * AppFunc.h
- *应用层函数库
- *  Created on: 2022年1月21日
- *      Author: QiXiang_CHENJIE
+/*** 
+ * @Author: chenjie
+ * @Date: 2022-06-06
+ * @LastEditTime: 2022-10-27
+ * @LastEditors: chenjie
+ * @Description: 
+ * @FilePath: \S32K146_4G\code\app\lib\AppFuncLib.h
+ * @Copyright (c) 2022 by chenjie, All Rights Reserved.
  */
 
 #ifndef APPFUNCLIB_H_
@@ -33,19 +27,19 @@ uint8 AtStrCompare(const char *a, const char *b);
 unsigned short CRC16_Modbus(unsigned char *pdata, int len);
 uint8 bcc_chk(uint8 *data, uint16 length);
 char *Myitoa(int value, char *result, int base);
-// 整数转字符串
+// 鏁存暟杞�瓧绗︿覆
 int _itoa(int num, char buf[32]);
 
 int _i2a(int num, char buf[32], int radix);
 
-// 浮点转字符串
+// 娴�偣杞�瓧绗︿覆
 int _ftoa(double val, char buf[32], int eps);
 
-// 浮点转字符串,范围(-1,1)
+// 娴�偣杞�瓧绗︿覆锛岃寖鍥达紙-1锛�1锛�
 int __ftoa(double val, char buf[32], int eps);
 
-// 替代sprintf
+// 鏇夸唬sprintf
 int _sprintf(char *dst, const char *format, ...);
-//串口校验
+//涓插彛鏍¢獙
 uint16 crc_chk(uint8 *data, uint8 length);
 #endif /* APPFUNCLIB_H_ */

+ 113 - 0
code/debug/SEGGER/Global.h

@@ -0,0 +1,113 @@
+/*********************************************************************
+*                    SEGGER Microcontroller GmbH                     *
+*                        The Embedded Experts                        *
+**********************************************************************
+*                                                                    *
+*            (c) 1995 - 2021 SEGGER Microcontroller GmbH             *
+*                                                                    *
+*       www.segger.com     Support: support@segger.com               *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+*       SEGGER SystemView * Real-time application analysis           *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+* All rights reserved.                                               *
+*                                                                    *
+* SEGGER strongly recommends to not make any changes                 *
+* to or modify the source code of this software in order to stay     *
+* compatible with the SystemView and RTT protocol, and J-Link.       *
+*                                                                    *
+* Redistribution and use in source and binary forms, with or         *
+* without modification, are permitted provided that the following    *
+* condition is met:                                                  *
+*                                                                    *
+* o Redistributions of source code must retain the above copyright   *
+*   notice, this condition and the following disclaimer.             *
+*                                                                    *
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND             *
+* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,        *
+* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF           *
+* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE           *
+* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR           *
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT  *
+* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;    *
+* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF      *
+* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT          *
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE  *
+* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH   *
+* DAMAGE.                                                            *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+*       SystemView version: 3.32                                    *
+*                                                                    *
+**********************************************************************
+----------------------------------------------------------------------
+File    : Global.h
+Purpose : Global types
+          In case your application already has a Global.h, you should
+          merge the files. In order to use Segger code, the types
+          U8, U16, U32, I8, I16, I32 need to be defined in Global.h;
+          additional definitions do not hurt.
+Revision: $Rev: 12501 $
+---------------------------END-OF-HEADER------------------------------
+*/
+
+#ifndef GLOBAL_H            // Guard against multiple inclusion
+#define GLOBAL_H
+
+#define U8    unsigned char
+#define I8    signed char
+#define U16   unsigned short
+#define I16   signed short
+#ifdef __x86_64__
+#define U32   unsigned
+#define I32   int
+#else
+#define U32   unsigned long
+#define I32   signed long
+#endif
+
+//
+// CC_NO_LONG_SUPPORT can be defined to compile test
+// without long support for compilers that do not
+// support C99 and its long type.
+//
+#ifdef CC_NO_LONG_SUPPORT
+  #define PTR_ADDR  U32
+#else  // Supports long type.
+#if defined(_WIN32) && !defined(__clang__) && !defined(__MINGW32__)
+  //
+  // Microsoft VC6 compiler related
+  //
+  #define U64   unsigned __int64
+  #define U128  unsigned __int128
+  #define I64   __int64
+  #define I128  __int128
+  #if _MSC_VER <= 1200
+    #define U64_C(x) x##UI64
+  #else
+    #define U64_C(x) x##ULL
+  #endif
+#else
+  //
+  // C99 compliant compiler
+  //
+  #define U64   unsigned long long
+  #define I64   signed long long
+  #define U64_C(x) x##ULL
+#endif
+
+#if (defined(_WIN64) || defined(__LP64__))  // 64-bit symbols used by Visual Studio and GCC, maybe others as well.
+  #define PTR_ADDR  U64
+#else
+  #define PTR_ADDR  U32
+#endif
+#endif  // Supports long type.
+
+#endif                      // Avoid multiple inclusion
+
+/*************************** End of file ****************************/

+ 248 - 0
code/debug/SEGGER/SEGGER.h

@@ -0,0 +1,248 @@
+/*********************************************************************
+*                    SEGGER Microcontroller GmbH                     *
+*                        The Embedded Experts                        *
+**********************************************************************
+*                                                                    *
+*            (c) 1995 - 2021 SEGGER Microcontroller GmbH             *
+*                                                                    *
+*       www.segger.com     Support: support@segger.com               *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+*       SEGGER SystemView * Real-time application analysis           *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+* All rights reserved.                                               *
+*                                                                    *
+* SEGGER strongly recommends to not make any changes                 *
+* to or modify the source code of this software in order to stay     *
+* compatible with the SystemView and RTT protocol, and J-Link.       *
+*                                                                    *
+* Redistribution and use in source and binary forms, with or         *
+* without modification, are permitted provided that the following    *
+* condition is met:                                                  *
+*                                                                    *
+* o Redistributions of source code must retain the above copyright   *
+*   notice, this condition and the following disclaimer.             *
+*                                                                    *
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND             *
+* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,        *
+* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF           *
+* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE           *
+* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR           *
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT  *
+* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;    *
+* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF      *
+* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT          *
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE  *
+* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH   *
+* DAMAGE.                                                            *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+*       SystemView version: 3.32                                    *
+*                                                                    *
+**********************************************************************
+----------------------------------------------------------------------
+File    : SEGGER.h
+Purpose : Global types etc & general purpose utility functions
+Revision: $Rev: 18102 $
+---------------------------END-OF-HEADER------------------------------
+*/
+
+#ifndef SEGGER_H            // Guard against multiple inclusion
+#define SEGGER_H
+
+#include <stdarg.h>         // For va_list.
+#include "Global.h"         // Type definitions: U8, U16, U32, I8, I16, I32
+
+#if defined(__cplusplus)
+extern "C" {     /* Make sure we have C-declarations in C++ programs */
+#endif
+
+/*********************************************************************
+*
+*       Keywords/specifiers
+*
+**********************************************************************
+*/
+
+#ifndef INLINE
+  #if (defined(__ICCARM__) || defined(__RX) || defined(__ICCRX__))
+    //
+    // Other known compilers.
+    //
+    #define INLINE  inline
+  #else
+    #if (defined(_WIN32) && !defined(__clang__))
+      //
+      // Microsoft VC6 and newer.
+      // Force inlining without cost checking.
+      //
+      #define INLINE  __forceinline
+    #elif defined(__GNUC__) || defined(__clang__)
+      //
+      // Force inlining with GCC + clang
+      //
+      #define INLINE inline __attribute__((always_inline))
+    #elif (defined(__CC_ARM))
+      //
+      // Force inlining with ARMCC (Keil)
+      //
+      #define INLINE  __inline
+    #else
+      //
+      // Unknown compilers.
+      //
+      #define INLINE
+    #endif
+  #endif
+#endif
+
+/*********************************************************************
+*
+*       Function-like macros
+*
+**********************************************************************
+*/
+
+#define SEGGER_COUNTOF(a)          (sizeof((a))/sizeof((a)[0]))
+#define SEGGER_MIN(a,b)            (((a) < (b)) ? (a) : (b))
+#define SEGGER_MAX(a,b)            (((a) > (b)) ? (a) : (b))
+
+#ifndef   SEGGER_USE_PARA                   // Some compiler complain about unused parameters.
+  #define SEGGER_USE_PARA(Para) (void)Para  // This works for most compilers.
+#endif
+
+#define SEGGER_ADDR2PTR(Type, Addr)  (/*lint -e(923) -e(9078)*/((Type*)((PTR_ADDR)(Addr))))    // Allow cast from address to pointer.
+#define SEGGER_PTR2ADDR(p)           (/*lint -e(923) -e(9078)*/((PTR_ADDR)(p)))                // Allow cast from pointer to address.
+#define SEGGER_PTR2PTR(Type, p)      (/*lint -e(740) -e(826) -e(9079) -e(9087)*/((Type*)(p)))  // Allow cast from one pointer type to another (ignore different size).
+#define SEGGER_PTR_DISTANCE(p0, p1)  (SEGGER_PTR2ADDR(p0) - SEGGER_PTR2ADDR(p1))
+
+/*********************************************************************
+*
+*       Defines
+*
+**********************************************************************
+*/
+
+#define SEGGER_PRINTF_FLAG_ADJLEFT    (1 << 0)
+#define SEGGER_PRINTF_FLAG_SIGNFORCE  (1 << 1)
+#define SEGGER_PRINTF_FLAG_SIGNSPACE  (1 << 2)
+#define SEGGER_PRINTF_FLAG_PRECEED    (1 << 3)
+#define SEGGER_PRINTF_FLAG_ZEROPAD    (1 << 4)
+#define SEGGER_PRINTF_FLAG_NEGATIVE   (1 << 5)
+
+/*********************************************************************
+*
+*       Types
+*
+**********************************************************************
+*/
+
+typedef struct {
+  char* pBuffer;
+  int   BufferSize;
+  int   Cnt;
+} SEGGER_BUFFER_DESC;
+
+typedef struct {
+  unsigned int CacheLineSize;                             // 0: No Cache. Most Systems such as ARM9 use a 32 bytes cache line size.
+  void (*pfDMB)       (void);                             // Optional DMB function for Data Memory Barrier to make sure all memory operations are completed.
+  void (*pfClean)     (void *p, unsigned long NumBytes);  // Optional clean function for cached memory.
+  void (*pfInvalidate)(void *p, unsigned long NumBytes);  // Optional invalidate function for cached memory.
+} SEGGER_CACHE_CONFIG;
+
+typedef struct SEGGER_SNPRINTF_CONTEXT_struct SEGGER_SNPRINTF_CONTEXT;
+
+struct SEGGER_SNPRINTF_CONTEXT_struct {
+  void*               pContext;                       // Application specific context.
+  SEGGER_BUFFER_DESC* pBufferDesc;                    // Buffer descriptor to use for output.
+  void (*pfFlush)(SEGGER_SNPRINTF_CONTEXT* pContext); // Callback executed once the buffer is full. Callback decides if the buffer gets cleared to store more or not.
+};
+
+typedef struct {
+  void (*pfStoreChar)       (SEGGER_BUFFER_DESC* pBufferDesc, SEGGER_SNPRINTF_CONTEXT* pContext, char c);
+  int  (*pfPrintUnsigned)   (SEGGER_BUFFER_DESC* pBufferDesc, SEGGER_SNPRINTF_CONTEXT* pContext, U32 v, unsigned Base, char Flags, int Width, int Precision);
+  int  (*pfPrintInt)        (SEGGER_BUFFER_DESC* pBufferDesc, SEGGER_SNPRINTF_CONTEXT* pContext, I32 v, unsigned Base, char Flags, int Width, int Precision);
+} SEGGER_PRINTF_API;
+
+typedef void (*SEGGER_pFormatter)(SEGGER_BUFFER_DESC* pBufferDesc, SEGGER_SNPRINTF_CONTEXT* pContext, const SEGGER_PRINTF_API* pApi, va_list* pParamList, char Lead, int Width, int Precision);
+
+typedef struct SEGGER_PRINTF_FORMATTER {
+  struct SEGGER_PRINTF_FORMATTER* pNext;              // Pointer to next formatter.
+  SEGGER_pFormatter               pfFormatter;        // Formatter function.
+  char                            Specifier;          // Format specifier.
+} SEGGER_PRINTF_FORMATTER;
+
+typedef struct {
+  U32 (*pfGetHPTimestamp)(void);          // Mandatory, pfGetHPTimestamp
+  int (*pfGetUID)        (U8 abUID[16]);  // Optional,  pfGetUID
+} SEGGER_BSP_API;
+
+/*********************************************************************
+*
+*       Utility functions
+*
+**********************************************************************
+*/
+
+//
+// Memory operations.
+//
+void SEGGER_ARM_memcpy(void* pDest, const void* pSrc, int NumBytes);
+void SEGGER_memcpy    (void* pDest, const void* pSrc, unsigned NumBytes);
+void SEGGER_memxor    (void* pDest, const void* pSrc, unsigned NumBytes);
+
+//
+// String functions.
+//
+int      SEGGER_atoi       (const char* s);
+int      SEGGER_isalnum    (int c);
+int      SEGGER_isalpha    (int c);
+unsigned SEGGER_strlen     (const char* s);
+int      SEGGER_tolower    (int c);
+int      SEGGER_strcasecmp (const char* sText1, const char* sText2);
+int      SEGGER_strncasecmp(const char *sText1, const char *sText2, unsigned Count);
+
+//
+// Buffer/printf related.
+//
+void SEGGER_StoreChar    (SEGGER_BUFFER_DESC* pBufferDesc, char c);
+void SEGGER_PrintUnsigned(SEGGER_BUFFER_DESC* pBufferDesc, U32 v, unsigned Base, int Precision);
+void SEGGER_PrintInt     (SEGGER_BUFFER_DESC* pBufferDesc, I32 v, unsigned Base, int Precision);
+int  SEGGER_snprintf     (char* pBuffer, int BufferSize, const char* sFormat, ...);
+int  SEGGER_vsnprintf    (char* pBuffer, int BufferSize, const char* sFormat, va_list ParamList);
+int  SEGGER_vsnprintfEx  (SEGGER_SNPRINTF_CONTEXT* pContext, const char* sFormat, va_list ParamList);
+
+int  SEGGER_PRINTF_AddFormatter       (SEGGER_PRINTF_FORMATTER* pFormatter, SEGGER_pFormatter pfFormatter, char c);
+void SEGGER_PRINTF_AddDoubleFormatter (void);
+void SEGGER_PRINTF_AddIPFormatter     (void);
+void SEGGER_PRINTF_AddBLUEFormatter   (void);
+void SEGGER_PRINTF_AddCONNECTFormatter(void);
+void SEGGER_PRINTF_AddSSLFormatter    (void);
+void SEGGER_PRINTF_AddSSHFormatter    (void);
+void SEGGER_PRINTF_AddHTMLFormatter   (void);
+
+//
+// BSP abstraction API.
+//
+int  SEGGER_BSP_GetUID  (U8 abUID[16]);
+int  SEGGER_BSP_GetUID32(U32* pUID);
+void SEGGER_BSP_SetAPI  (const SEGGER_BSP_API* pAPI);
+void SEGGER_BSP_SeedUID (void);
+
+//
+// Other API.
+//
+void SEGGER_VERSION_GetString(char acText[8], unsigned Version);
+
+#if defined(__cplusplus)
+}                /* Make sure we have C-declarations in C++ programs */
+#endif
+
+#endif                      // Avoid multiple inclusion
+
+/*************************** End of file ****************************/

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 667 - 144
code/debug/SEGGER/SEGGER_RTT.c


+ 492 - 0
code/debug/SEGGER/SEGGER_RTT.h

@@ -0,0 +1,492 @@
+/*********************************************************************
+*                    SEGGER Microcontroller GmbH                     *
+*                        The Embedded Experts                        *
+**********************************************************************
+*                                                                    *
+*            (c) 1995 - 2021 SEGGER Microcontroller GmbH             *
+*                                                                    *
+*       www.segger.com     Support: support@segger.com               *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+*       SEGGER SystemView * Real-time application analysis           *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+* All rights reserved.                                               *
+*                                                                    *
+* SEGGER strongly recommends to not make any changes                 *
+* to or modify the source code of this software in order to stay     *
+* compatible with the SystemView and RTT protocol, and J-Link.       *
+*                                                                    *
+* Redistribution and use in source and binary forms, with or         *
+* without modification, are permitted provided that the following    *
+* condition is met:                                                  *
+*                                                                    *
+* o Redistributions of source code must retain the above copyright   *
+*   notice, this condition and the following disclaimer.             *
+*                                                                    *
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND             *
+* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,        *
+* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF           *
+* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE           *
+* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR           *
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT  *
+* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;    *
+* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF      *
+* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT          *
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE  *
+* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH   *
+* DAMAGE.                                                            *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+*       SystemView version: 3.32                                    *
+*                                                                    *
+**********************************************************************
+---------------------------END-OF-HEADER------------------------------
+File    : SEGGER_RTT.h
+Purpose : Implementation of SEGGER real-time transfer which allows
+          real-time communication on targets which support debugger 
+          memory accesses while the CPU is running.
+Revision: $Rev: 25842 $
+----------------------------------------------------------------------
+*/
+
+#ifndef SEGGER_RTT_H
+#define SEGGER_RTT_H
+
+#include "SEGGER_RTT_Conf.h"
+
+/*********************************************************************
+*
+*       Defines, defaults
+*
+**********************************************************************
+*/
+
+#ifndef RTT_USE_ASM
+  //
+  // Some cores support out-of-order memory accesses (reordering of memory accesses in the core)
+  // For such cores, we need to define a memory barrier to guarantee the order of certain accesses to the RTT ring buffers.
+  // Needed for:
+  //   Cortex-M7 (ARMv7-M)
+  //   Cortex-M23 (ARM-v8M)
+  //   Cortex-M33 (ARM-v8M)
+  //   Cortex-A/R (ARM-v7A/R)
+  //
+  // We do not explicitly check for "Embedded Studio" as the compiler in use determines what we support.
+  // You can use an external toolchain like IAR inside ES. So there is no point in checking for "Embedded Studio"
+  //
+  #if (defined __CROSSWORKS_ARM)                  // Rowley Crossworks
+    #define _CC_HAS_RTT_ASM_SUPPORT 1
+    #if (defined __ARM_ARCH_7M__)                 // Cortex-M3
+      #define _CORE_HAS_RTT_ASM_SUPPORT 1
+    #elif (defined __ARM_ARCH_7EM__)              // Cortex-M4/M7
+      #define _CORE_HAS_RTT_ASM_SUPPORT 1
+      #define _CORE_NEEDS_DMB           1
+      #define RTT__DMB() __asm volatile ("dmb\n" : : :);
+    #elif (defined __ARM_ARCH_8M_BASE__)          // Cortex-M23
+      #define _CORE_HAS_RTT_ASM_SUPPORT 0
+      #define _CORE_NEEDS_DMB           1
+      #define RTT__DMB() __asm volatile ("dmb\n" : : :);
+    #elif (defined __ARM_ARCH_8M_MAIN__)          // Cortex-M33
+      #define _CORE_HAS_RTT_ASM_SUPPORT 1
+      #define _CORE_NEEDS_DMB           1
+      #define RTT__DMB() __asm volatile ("dmb\n" : : :);
+    #else
+      #define _CORE_HAS_RTT_ASM_SUPPORT 0
+    #endif
+  #elif (defined __ARMCC_VERSION)
+    //
+    // ARM compiler
+    // ARM compiler V6.0 and later is clang based.
+    // Our ASM part is compatible to clang.
+    //
+    #if (__ARMCC_VERSION >= 6000000)
+      #define _CC_HAS_RTT_ASM_SUPPORT 1
+    #else
+      #define _CC_HAS_RTT_ASM_SUPPORT 0
+    #endif
+    #if (defined __ARM_ARCH_6M__)                 // Cortex-M0 / M1
+      #define _CORE_HAS_RTT_ASM_SUPPORT 0         // No ASM support for this architecture
+    #elif (defined __ARM_ARCH_7M__)               // Cortex-M3
+      #define _CORE_HAS_RTT_ASM_SUPPORT 1
+    #elif (defined __ARM_ARCH_7EM__)              // Cortex-M4/M7
+      #define _CORE_HAS_RTT_ASM_SUPPORT 1
+      #define _CORE_NEEDS_DMB           1
+      #define RTT__DMB() __asm volatile ("dmb\n" : : :);
+    #elif (defined __ARM_ARCH_8M_BASE__)          // Cortex-M23
+      #define _CORE_HAS_RTT_ASM_SUPPORT 0
+      #define _CORE_NEEDS_DMB           1
+      #define RTT__DMB() __asm volatile ("dmb\n" : : :);
+    #elif (defined __ARM_ARCH_8M_MAIN__)          // Cortex-M33
+      #define _CORE_HAS_RTT_ASM_SUPPORT 1
+      #define _CORE_NEEDS_DMB           1
+      #define RTT__DMB() __asm volatile ("dmb\n" : : :);
+    #elif ((defined __ARM_ARCH_7A__) || (defined __ARM_ARCH_7R__))  // Cortex-A/R 32-bit ARMv7-A/R
+      #define _CORE_NEEDS_DMB           1
+      #define RTT__DMB() __asm volatile ("dmb\n" : : :);
+    #else
+      #define _CORE_HAS_RTT_ASM_SUPPORT 0
+    #endif
+  #elif ((defined __GNUC__) || (defined __clang__))
+    //
+    // GCC / Clang
+    //
+    #define _CC_HAS_RTT_ASM_SUPPORT 1
+    // ARM 7/9: __ARM_ARCH_5__ / __ARM_ARCH_5E__ / __ARM_ARCH_5T__ / __ARM_ARCH_5T__ / __ARM_ARCH_5TE__
+    #if (defined __ARM_ARCH_7M__)                 // Cortex-M3
+      #define _CORE_HAS_RTT_ASM_SUPPORT 1
+    #elif (defined __ARM_ARCH_7EM__)              // Cortex-M4/M7
+      #define _CORE_HAS_RTT_ASM_SUPPORT 1
+      #define _CORE_NEEDS_DMB           1         // Only Cortex-M7 needs a DMB but we cannot distinguish M4 and M7 here...
+      #define RTT__DMB() __asm volatile ("dmb\n" : : :);
+    #elif (defined __ARM_ARCH_8M_BASE__)          // Cortex-M23
+      #define _CORE_HAS_RTT_ASM_SUPPORT 0
+      #define _CORE_NEEDS_DMB           1
+      #define RTT__DMB() __asm volatile ("dmb\n" : : :);
+    #elif (defined __ARM_ARCH_8M_MAIN__)          // Cortex-M33
+      #define _CORE_HAS_RTT_ASM_SUPPORT 1
+      #define _CORE_NEEDS_DMB           1
+      #define RTT__DMB() __asm volatile ("dmb\n" : : :);
+    #elif ((defined __ARM_ARCH_7A__) || (defined __ARM_ARCH_7R__))  // Cortex-A/R 32-bit ARMv7-A/R
+      #define _CORE_NEEDS_DMB           1
+      #define RTT__DMB() __asm volatile ("dmb\n" : : :);
+    #else
+      #define _CORE_HAS_RTT_ASM_SUPPORT 0
+    #endif
+  #elif ((defined __IASMARM__) || (defined __ICCARM__))
+    //
+    // IAR assembler/compiler
+    //
+    #define _CC_HAS_RTT_ASM_SUPPORT 1
+    #if (__VER__ < 6300000)
+      #define VOLATILE
+    #else
+      #define VOLATILE volatile
+    #endif
+    #if (defined __ARM7M__)                            // Needed for old versions that do not know the define yet
+      #if (__CORE__ == __ARM7M__)                      // Cortex-M3
+        #define _CORE_HAS_RTT_ASM_SUPPORT 1
+      #endif
+    #endif
+    #if (defined __ARM7EM__)
+      #if (__CORE__ == __ARM7EM__)                     // Cortex-M4/M7
+        #define _CORE_HAS_RTT_ASM_SUPPORT 1
+        #define _CORE_NEEDS_DMB 1
+        #define RTT__DMB() asm VOLATILE ("DMB");
+      #endif
+    #endif
+    #if (defined __ARM8M_BASELINE__)
+      #if (__CORE__ == __ARM8M_BASELINE__)             // Cortex-M23
+        #define _CORE_HAS_RTT_ASM_SUPPORT 0
+        #define _CORE_NEEDS_DMB 1
+        #define RTT__DMB() asm VOLATILE ("DMB");
+      #endif
+    #endif
+    #if (defined __ARM8M_MAINLINE__)
+      #if (__CORE__ == __ARM8M_MAINLINE__)             // Cortex-M33
+        #define _CORE_HAS_RTT_ASM_SUPPORT 1
+        #define _CORE_NEEDS_DMB 1
+        #define RTT__DMB() asm VOLATILE ("DMB");
+      #endif
+    #endif
+    #if (defined __ARM8EM_MAINLINE__)
+      #if (__CORE__ == __ARM8EM_MAINLINE__)            // Cortex-???
+        #define _CORE_HAS_RTT_ASM_SUPPORT 1
+        #define _CORE_NEEDS_DMB 1
+        #define RTT__DMB() asm VOLATILE ("DMB");
+      #endif
+    #endif
+    #if (defined __ARM7A__)
+      #if (__CORE__ == __ARM7A__)                      // Cortex-A 32-bit ARMv7-A
+        #define _CORE_NEEDS_DMB 1
+        #define RTT__DMB() asm VOLATILE ("DMB");
+      #endif
+    #endif
+    #if (defined __ARM7R__)
+      #if (__CORE__ == __ARM7R__)                      // Cortex-R 32-bit ARMv7-R
+        #define _CORE_NEEDS_DMB 1
+        #define RTT__DMB() asm VOLATILE ("DMB");
+      #endif
+    #endif
+// TBD: __ARM8A__ => Cortex-A 64-bit ARMv8-A
+// TBD: __ARM8R__ => Cortex-R 64-bit ARMv8-R
+  #else
+    //
+    // Other compilers
+    //
+    #define _CC_HAS_RTT_ASM_SUPPORT   0
+    #define _CORE_HAS_RTT_ASM_SUPPORT 0
+  #endif
+  //
+  // If IDE and core support the ASM version, enable ASM version by default
+  //
+  #ifndef _CORE_HAS_RTT_ASM_SUPPORT
+    #define _CORE_HAS_RTT_ASM_SUPPORT 0              // Default for unknown cores
+  #endif
+  #if (_CC_HAS_RTT_ASM_SUPPORT && _CORE_HAS_RTT_ASM_SUPPORT)
+    #define RTT_USE_ASM                           (0)
+  #else
+    #define RTT_USE_ASM                           (0)
+  #endif
+#endif
+
+#ifndef _CORE_NEEDS_DMB
+  #define _CORE_NEEDS_DMB 0
+#endif
+
+#ifndef RTT__DMB
+  #if _CORE_NEEDS_DMB
+    #error "Don't know how to place inline assembly for DMB"
+  #else
+    #define RTT__DMB()
+  #endif
+#endif
+
+#ifndef SEGGER_RTT_CPU_CACHE_LINE_SIZE
+  #define SEGGER_RTT_CPU_CACHE_LINE_SIZE (0)   // On most target systems where RTT is used, we do not have a CPU cache, therefore 0 is a good default here
+#endif
+
+#ifndef SEGGER_RTT_UNCACHED_OFF
+  #if SEGGER_RTT_CPU_CACHE_LINE_SIZE
+    #error "SEGGER_RTT_UNCACHED_OFF must be defined when setting SEGGER_RTT_CPU_CACHE_LINE_SIZE != 0"
+  #else
+    #define SEGGER_RTT_UNCACHED_OFF (0)
+  #endif
+#endif
+#if RTT_USE_ASM
+  #if SEGGER_RTT_CPU_CACHE_LINE_SIZE
+    #error "RTT_USE_ASM is not available if SEGGER_RTT_CPU_CACHE_LINE_SIZE != 0"
+  #endif
+#endif
+
+#ifndef SEGGER_RTT_ASM  // defined when SEGGER_RTT.h is included from assembly file
+#include <stdlib.h>
+#include <stdarg.h>
+
+/*********************************************************************
+*
+*       Defines, fixed
+*
+**********************************************************************
+*/
+
+//
+// Determine how much we must pad the control block to make it a multiple of a cache line in size
+// Assuming: U8 = 1B
+//           U16 = 2B
+//           U32 = 4B
+//           U8/U16/U32* = 4B
+//
+#if SEGGER_RTT_CPU_CACHE_LINE_SIZE    // Avoid division by zero in case we do not have any cache
+  #define SEGGER_RTT__ROUND_UP_2_CACHE_LINE_SIZE(NumBytes) (((NumBytes + SEGGER_RTT_CPU_CACHE_LINE_SIZE - 1) / SEGGER_RTT_CPU_CACHE_LINE_SIZE) * SEGGER_RTT_CPU_CACHE_LINE_SIZE)
+#else
+  #define SEGGER_RTT__ROUND_UP_2_CACHE_LINE_SIZE(NumBytes) (NumBytes)
+#endif
+#define SEGGER_RTT__CB_SIZE                              (16 + 4 + 4 + (SEGGER_RTT_MAX_NUM_UP_BUFFERS * 24) + (SEGGER_RTT_MAX_NUM_DOWN_BUFFERS * 24))
+#define SEGGER_RTT__CB_PADDING                           (SEGGER_RTT__ROUND_UP_2_CACHE_LINE_SIZE(SEGGER_RTT__CB_SIZE) - SEGGER_RTT__CB_SIZE)
+
+/*********************************************************************
+*
+*       Types
+*
+**********************************************************************
+*/
+
+//
+// Description for a circular buffer (also called "ring buffer")
+// which is used as up-buffer (T->H)
+//
+typedef struct {
+  const     char*    sName;         // Optional name. Standard names so far are: "Terminal", "SysView", "J-Scope_t4i4"
+            char*    pBuffer;       // Pointer to start of buffer
+            unsigned SizeOfBuffer;  // Buffer size in bytes. Note that one byte is lost, as this implementation does not fill up the buffer in order to avoid the problem of being unable to distinguish between full and empty.
+            unsigned WrOff;         // Position of next item to be written by either target.
+  volatile  unsigned RdOff;         // Position of next item to be read by host. Must be volatile since it may be modified by host.
+            unsigned Flags;         // Contains configuration flags. Flags[31:24] are used for validity check and must be zero. Flags[23:2] are reserved for future use. Flags[1:0] = RTT operating mode.
+} SEGGER_RTT_BUFFER_UP;
+
+//
+// Description for a circular buffer (also called "ring buffer")
+// which is used as down-buffer (H->T)
+//
+typedef struct {
+  const     char*    sName;         // Optional name. Standard names so far are: "Terminal", "SysView", "J-Scope_t4i4"
+            char*    pBuffer;       // Pointer to start of buffer
+            unsigned SizeOfBuffer;  // Buffer size in bytes. Note that one byte is lost, as this implementation does not fill up the buffer in order to avoid the problem of being unable to distinguish between full and empty.
+  volatile  unsigned WrOff;         // Position of next item to be written by host. Must be volatile since it may be modified by host.
+            unsigned RdOff;         // Position of next item to be read by target (down-buffer).
+            unsigned Flags;         // Contains configuration flags. Flags[31:24] are used for validity check and must be zero. Flags[23:2] are reserved for future use. Flags[1:0] = RTT operating mode. 
+} SEGGER_RTT_BUFFER_DOWN;
+
+//
+// RTT control block which describes the number of buffers available
+// as well as the configuration for each buffer
+//
+//
+typedef struct {
+  char                    acID[16];                                 // Initialized to "SEGGER RTT"
+  int                     MaxNumUpBuffers;                          // Initialized to SEGGER_RTT_MAX_NUM_UP_BUFFERS (type. 2)
+  int                     MaxNumDownBuffers;                        // Initialized to SEGGER_RTT_MAX_NUM_DOWN_BUFFERS (type. 2)
+  SEGGER_RTT_BUFFER_UP    aUp[SEGGER_RTT_MAX_NUM_UP_BUFFERS];       // Up buffers, transferring information up from target via debug probe to host
+  SEGGER_RTT_BUFFER_DOWN  aDown[SEGGER_RTT_MAX_NUM_DOWN_BUFFERS];   // Down buffers, transferring information down from host via debug probe to target
+#if SEGGER_RTT__CB_PADDING
+  unsigned char           aDummy[SEGGER_RTT__CB_PADDING];
+#endif
+} SEGGER_RTT_CB;
+
+/*********************************************************************
+*
+*       Global data
+*
+**********************************************************************
+*/
+extern SEGGER_RTT_CB _SEGGER_RTT;
+
+/*********************************************************************
+*
+*       RTT API functions
+*
+**********************************************************************
+*/
+#ifdef __cplusplus
+  extern "C" {
+#endif
+int          SEGGER_RTT_AllocDownBuffer         (const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
+int          SEGGER_RTT_AllocUpBuffer           (const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
+int          SEGGER_RTT_ConfigUpBuffer          (unsigned BufferIndex, const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
+int          SEGGER_RTT_ConfigDownBuffer        (unsigned BufferIndex, const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
+int          SEGGER_RTT_GetKey                  (void);
+unsigned     SEGGER_RTT_HasData                 (unsigned BufferIndex);
+int          SEGGER_RTT_HasKey                  (void);
+unsigned     SEGGER_RTT_HasDataUp               (unsigned BufferIndex);
+void         SEGGER_RTT_Init                    (void);
+unsigned     SEGGER_RTT_Read                    (unsigned BufferIndex,       void* pBuffer, unsigned BufferSize);
+unsigned     SEGGER_RTT_ReadNoLock              (unsigned BufferIndex,       void* pData,   unsigned BufferSize);
+int          SEGGER_RTT_SetNameDownBuffer       (unsigned BufferIndex, const char* sName);
+int          SEGGER_RTT_SetNameUpBuffer         (unsigned BufferIndex, const char* sName);
+int          SEGGER_RTT_SetFlagsDownBuffer      (unsigned BufferIndex, unsigned Flags);
+int          SEGGER_RTT_SetFlagsUpBuffer        (unsigned BufferIndex, unsigned Flags);
+int          SEGGER_RTT_WaitKey                 (void);
+unsigned     SEGGER_RTT_Write                   (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
+unsigned     SEGGER_RTT_WriteNoLock             (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
+unsigned     SEGGER_RTT_WriteSkipNoLock         (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
+unsigned     SEGGER_RTT_ASM_WriteSkipNoLock     (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
+unsigned     SEGGER_RTT_WriteString             (unsigned BufferIndex, const char* s);
+void         SEGGER_RTT_WriteWithOverwriteNoLock(unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
+unsigned     SEGGER_RTT_PutChar                 (unsigned BufferIndex, char c);
+unsigned     SEGGER_RTT_PutCharSkip             (unsigned BufferIndex, char c);
+unsigned     SEGGER_RTT_PutCharSkipNoLock       (unsigned BufferIndex, char c);
+unsigned     SEGGER_RTT_GetAvailWriteSpace      (unsigned BufferIndex);
+unsigned     SEGGER_RTT_GetBytesInBuffer        (unsigned BufferIndex);
+//
+// Function macro for performance optimization
+//
+#define      SEGGER_RTT_HASDATA(n)       (((SEGGER_RTT_BUFFER_DOWN*)((char*)&_SEGGER_RTT.aDown[n] + SEGGER_RTT_UNCACHED_OFF))->WrOff - ((SEGGER_RTT_BUFFER_DOWN*)((char*)&_SEGGER_RTT.aDown[n] + SEGGER_RTT_UNCACHED_OFF))->RdOff)
+
+#if RTT_USE_ASM
+  #define SEGGER_RTT_WriteSkipNoLock  SEGGER_RTT_ASM_WriteSkipNoLock
+#endif
+
+/*********************************************************************
+*
+*       RTT transfer functions to send RTT data via other channels.
+*
+**********************************************************************
+*/
+unsigned     SEGGER_RTT_ReadUpBuffer            (unsigned BufferIndex, void* pBuffer, unsigned BufferSize);
+unsigned     SEGGER_RTT_ReadUpBufferNoLock      (unsigned BufferIndex, void* pData, unsigned BufferSize);
+unsigned     SEGGER_RTT_WriteDownBuffer         (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
+unsigned     SEGGER_RTT_WriteDownBufferNoLock   (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
+
+#define      SEGGER_RTT_HASDATA_UP(n)    (((SEGGER_RTT_BUFFER_UP*)((char*)&_SEGGER_RTT.aUp[n] + SEGGER_RTT_UNCACHED_OFF))->WrOff - ((SEGGER_RTT_BUFFER_UP*)((char*)&_SEGGER_RTT.aUp[n] + SEGGER_RTT_UNCACHED_OFF))->RdOff)   // Access uncached to make sure we see changes made by the J-Link side and all of our changes go into HW directly
+
+/*********************************************************************
+*
+*       RTT "Terminal" API functions
+*
+**********************************************************************
+*/
+int     SEGGER_RTT_SetTerminal        (unsigned char TerminalId);
+int     SEGGER_RTT_TerminalOut        (unsigned char TerminalId, const char* s);
+
+/*********************************************************************
+*
+*       RTT printf functions (require SEGGER_RTT_printf.c)
+*
+**********************************************************************
+*/
+int SEGGER_RTT_printf(const char * sFormat, ...);
+int SEGGER_RTT_vprintf(unsigned BufferIndex, const char * sFormat, va_list * pParamList);
+
+#ifdef __cplusplus
+  }
+#endif
+
+#endif // ifndef(SEGGER_RTT_ASM)
+
+/*********************************************************************
+*
+*       Defines
+*
+**********************************************************************
+*/
+
+//
+// Operating modes. Define behavior if buffer is full (not enough space for entire message)
+//
+#define SEGGER_RTT_MODE_NO_BLOCK_SKIP         (0)     // Skip. Do not block, output nothing. (Default)
+#define SEGGER_RTT_MODE_NO_BLOCK_TRIM         (1)     // Trim: Do not block, output as much as fits.
+#define SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL    (2)     // Block: Wait until there is space in the buffer.
+#define SEGGER_RTT_MODE_MASK                  (3)
+
+//
+// Control sequences, based on ANSI.
+// Can be used to control color, and clear the screen
+//
+#define RTT_CTRL_RESET                "\x1B[0m"         // Reset to default colors
+#define RTT_CTRL_CLEAR                "\x1B[2J"         // Clear screen, reposition cursor to top left
+
+#define RTT_CTRL_TEXT_BLACK           "\x1B[2;30m"
+#define RTT_CTRL_TEXT_RED             "\x1B[2;31m"
+#define RTT_CTRL_TEXT_GREEN           "\x1B[2;32m"
+#define RTT_CTRL_TEXT_YELLOW          "\x1B[2;33m"
+#define RTT_CTRL_TEXT_BLUE            "\x1B[2;34m"
+#define RTT_CTRL_TEXT_MAGENTA         "\x1B[2;35m"
+#define RTT_CTRL_TEXT_CYAN            "\x1B[2;36m"
+#define RTT_CTRL_TEXT_WHITE           "\x1B[2;37m"
+
+#define RTT_CTRL_TEXT_BRIGHT_BLACK    "\x1B[1;30m"
+#define RTT_CTRL_TEXT_BRIGHT_RED      "\x1B[1;31m"
+#define RTT_CTRL_TEXT_BRIGHT_GREEN    "\x1B[1;32m"
+#define RTT_CTRL_TEXT_BRIGHT_YELLOW   "\x1B[1;33m"
+#define RTT_CTRL_TEXT_BRIGHT_BLUE     "\x1B[1;34m"
+#define RTT_CTRL_TEXT_BRIGHT_MAGENTA  "\x1B[1;35m"
+#define RTT_CTRL_TEXT_BRIGHT_CYAN     "\x1B[1;36m"
+#define RTT_CTRL_TEXT_BRIGHT_WHITE    "\x1B[1;37m"
+
+#define RTT_CTRL_BG_BLACK             "\x1B[24;40m"
+#define RTT_CTRL_BG_RED               "\x1B[24;41m"
+#define RTT_CTRL_BG_GREEN             "\x1B[24;42m"
+#define RTT_CTRL_BG_YELLOW            "\x1B[24;43m"
+#define RTT_CTRL_BG_BLUE              "\x1B[24;44m"
+#define RTT_CTRL_BG_MAGENTA           "\x1B[24;45m"
+#define RTT_CTRL_BG_CYAN              "\x1B[24;46m"
+#define RTT_CTRL_BG_WHITE             "\x1B[24;47m"
+
+#define RTT_CTRL_BG_BRIGHT_BLACK      "\x1B[4;40m"
+#define RTT_CTRL_BG_BRIGHT_RED        "\x1B[4;41m"
+#define RTT_CTRL_BG_BRIGHT_GREEN      "\x1B[4;42m"
+#define RTT_CTRL_BG_BRIGHT_YELLOW     "\x1B[4;43m"
+#define RTT_CTRL_BG_BRIGHT_BLUE       "\x1B[4;44m"
+#define RTT_CTRL_BG_BRIGHT_MAGENTA    "\x1B[4;45m"
+#define RTT_CTRL_BG_BRIGHT_CYAN       "\x1B[4;46m"
+#define RTT_CTRL_BG_BRIGHT_WHITE      "\x1B[4;47m"
+
+
+#endif
+
+/*************************** End of file ****************************/

+ 428 - 0
code/debug/SEGGER/SEGGER_RTT_Conf.h

@@ -0,0 +1,428 @@
+/*********************************************************************
+*                    SEGGER Microcontroller GmbH                     *
+*                        The Embedded Experts                        *
+**********************************************************************
+*                                                                    *
+*            (c) 1995 - 2021 SEGGER Microcontroller GmbH             *
+*                                                                    *
+*       www.segger.com     Support: support@segger.com               *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+*       SEGGER SystemView * Real-time application analysis           *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+* All rights reserved.                                               *
+*                                                                    *
+* SEGGER strongly recommends to not make any changes                 *
+* to or modify the source code of this software in order to stay     *
+* compatible with the SystemView and RTT protocol, and J-Link.       *
+*                                                                    *
+* Redistribution and use in source and binary forms, with or         *
+* without modification, are permitted provided that the following    *
+* condition is met:                                                  *
+*                                                                    *
+* o Redistributions of source code must retain the above copyright   *
+*   notice, this condition and the following disclaimer.             *
+*                                                                    *
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND             *
+* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,        *
+* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF           *
+* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE           *
+* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR           *
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT  *
+* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;    *
+* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF      *
+* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT          *
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE  *
+* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH   *
+* DAMAGE.                                                            *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+*       SystemView version: 3.32                                    *
+*                                                                    *
+**********************************************************************
+---------------------------END-OF-HEADER------------------------------
+File    : SEGGER_RTT_Conf.h
+Purpose : Implementation of SEGGER real-time transfer (RTT) which
+          allows real-time communication on targets which support
+          debugger memory accesses while the CPU is running.
+Revision: $Rev: 24316 $
+
+*/
+
+#ifndef SEGGER_RTT_CONF_H
+#define SEGGER_RTT_CONF_H
+
+#ifdef __IAR_SYSTEMS_ICC__
+  #include <intrinsics.h>
+#endif
+
+/*********************************************************************
+*
+*       Defines, configurable
+*
+**********************************************************************
+*/
+
+//
+// Take in and set to correct values for Cortex-A systems with CPU cache
+//
+//#define SEGGER_RTT_CPU_CACHE_LINE_SIZE            (32)          // Largest cache line size (in bytes) in the current system
+//#define SEGGER_RTT_UNCACHED_OFF                   (0xFB000000)  // Address alias where RTT CB and buffers can be accessed uncached
+//
+// Most common case:
+// Up-channel 0: RTT
+// Up-channel 1: SystemView
+//
+#ifndef   SEGGER_RTT_MAX_NUM_UP_BUFFERS
+  #define SEGGER_RTT_MAX_NUM_UP_BUFFERS             (3)     // Max. number of up-buffers (T->H) available on this target    (Default: 3)
+#endif
+//
+// Most common case:
+// Down-channel 0: RTT
+// Down-channel 1: SystemView
+//
+#ifndef   SEGGER_RTT_MAX_NUM_DOWN_BUFFERS
+  #define SEGGER_RTT_MAX_NUM_DOWN_BUFFERS           (3)     // Max. number of down-buffers (H->T) available on this target  (Default: 3)
+#endif
+
+#ifndef   BUFFER_SIZE_UP
+  #define BUFFER_SIZE_UP                            (1024)  // Size of the buffer for terminal output of target, up to host (Default: 1k)
+#endif
+
+#ifndef   BUFFER_SIZE_DOWN
+  #define BUFFER_SIZE_DOWN                          (16)    // Size of the buffer for terminal input to target from host (Usually keyboard input) (Default: 16)
+#endif
+
+#ifndef   SEGGER_RTT_PRINTF_BUFFER_SIZE
+  #define SEGGER_RTT_PRINTF_BUFFER_SIZE             (64u)    // Size of buffer for RTT printf to bulk-send chars via RTT     (Default: 64)
+#endif
+
+#ifndef   SEGGER_RTT_MODE_DEFAULT
+  #define SEGGER_RTT_MODE_DEFAULT                   SEGGER_RTT_MODE_NO_BLOCK_SKIP // Mode for pre-initialized terminal channel (buffer 0)
+#endif
+
+/*********************************************************************
+*
+*       RTT memcpy configuration
+*
+*       memcpy() is good for large amounts of data,
+*       but the overhead is big for small amounts, which are usually stored via RTT.
+*       With SEGGER_RTT_MEMCPY_USE_BYTELOOP a simple byte loop can be used instead.
+*
+*       SEGGER_RTT_MEMCPY() can be used to replace standard memcpy() in RTT functions.
+*       This is may be required with memory access restrictions,
+*       such as on Cortex-A devices with MMU.
+*/
+#ifndef   SEGGER_RTT_MEMCPY_USE_BYTELOOP
+  #define SEGGER_RTT_MEMCPY_USE_BYTELOOP              0 // 0: Use memcpy/SEGGER_RTT_MEMCPY, 1: Use a simple byte-loop
+#endif
+//
+// Example definition of SEGGER_RTT_MEMCPY to external memcpy with GCC toolchains and Cortex-A targets
+//
+//#if ((defined __SES_ARM) || (defined __CROSSWORKS_ARM) || (defined __GNUC__)) && (defined (__ARM_ARCH_7A__))
+//  #define SEGGER_RTT_MEMCPY(pDest, pSrc, NumBytes)      SEGGER_memcpy((pDest), (pSrc), (NumBytes))
+//#endif
+
+//
+// Target is not allowed to perform other RTT operations while string still has not been stored completely.
+// Otherwise we would probably end up with a mixed string in the buffer.
+// If using  RTT from within interrupts, multiple tasks or multi processors, define the SEGGER_RTT_LOCK() and SEGGER_RTT_UNLOCK() function here.
+//
+// SEGGER_RTT_MAX_INTERRUPT_PRIORITY can be used in the sample lock routines on Cortex-M3/4.
+// Make sure to mask all interrupts which can send RTT data, i.e. generate SystemView events, or cause task switches.
+// When high-priority interrupts must not be masked while sending RTT data, SEGGER_RTT_MAX_INTERRUPT_PRIORITY needs to be adjusted accordingly.
+// (Higher priority = lower priority number)
+// Default value for embOS: 128u
+// Default configuration in FreeRTOS: configMAX_SYSCALL_INTERRUPT_PRIORITY: ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
+// In case of doubt mask all interrupts: 1 << (8 - BASEPRI_PRIO_BITS) i.e. 1 << 5 when 3 bits are implemented in NVIC
+// or define SEGGER_RTT_LOCK() to completely disable interrupts.
+//
+#ifndef   SEGGER_RTT_MAX_INTERRUPT_PRIORITY
+  #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY         (0x20)   // Interrupt priority to lock on SEGGER_RTT_LOCK on Cortex-M3/4 (Default: 0x20)
+#endif
+
+/*********************************************************************
+*
+*       RTT lock configuration for SEGGER Embedded Studio,
+*       Rowley CrossStudio and GCC
+*/
+#if ((defined(__SES_ARM) || defined(__SES_RISCV) || defined(__CROSSWORKS_ARM) || defined(__GNUC__) || defined(__clang__)) && !defined (__CC_ARM) && !defined(WIN32))
+  #if (defined(__ARM_ARCH_6M__) || defined(__ARM_ARCH_8M_BASE__))
+    #define SEGGER_RTT_LOCK()   {                                                                   \
+                                    unsigned int _SEGGER_RTT__LockState;                                         \
+                                  __asm volatile ("mrs   %0, primask  \n\t"                         \
+                                                  "movs  r1, #1       \n\t"                         \
+                                                  "msr   primask, r1  \n\t"                         \
+                                                  : "=r" (_SEGGER_RTT__LockState)                                \
+                                                  :                                                 \
+                                                  : "r1", "cc"                                      \
+                                                  );
+
+    #define SEGGER_RTT_UNLOCK()   __asm volatile ("msr   primask, %0  \n\t"                         \
+                                                  :                                                 \
+                                                  : "r" (_SEGGER_RTT__LockState)                                 \
+                                                  :                                                 \
+                                                  );                                                \
+                                }
+  #elif (defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) || defined(__ARM_ARCH_8M_MAIN__))
+    #ifndef   SEGGER_RTT_MAX_INTERRUPT_PRIORITY
+      #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY   (0x20)
+    #endif
+    #define SEGGER_RTT_LOCK()   {                                                                   \
+                                    unsigned int _SEGGER_RTT__LockState;                                         \
+                                  __asm volatile ("mrs   %0, basepri  \n\t"                         \
+                                                  "mov   r1, %1       \n\t"                         \
+                                                  "msr   basepri, r1  \n\t"                         \
+                                                  : "=r" (_SEGGER_RTT__LockState)                                \
+                                                  : "i"(SEGGER_RTT_MAX_INTERRUPT_PRIORITY)          \
+                                                  : "r1", "cc"                                      \
+                                                  );
+
+    #define SEGGER_RTT_UNLOCK()   __asm volatile ("msr   basepri, %0  \n\t"                         \
+                                                  :                                                 \
+                                                  : "r" (_SEGGER_RTT__LockState)                                 \
+                                                  :                                                 \
+                                                  );                                                \
+                                }
+
+  #elif (defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__))
+    #define SEGGER_RTT_LOCK() {                                                \
+                                 unsigned int _SEGGER_RTT__LockState;                       \
+                                 __asm volatile ("mrs r1, CPSR \n\t"           \
+                                                 "mov %0, r1 \n\t"             \
+                                                 "orr r1, r1, #0xC0 \n\t"      \
+                                                 "msr CPSR_c, r1 \n\t"         \
+                                                 : "=r" (_SEGGER_RTT__LockState)            \
+                                                 :                             \
+                                                 : "r1", "cc"                  \
+                                                 );
+
+    #define SEGGER_RTT_UNLOCK() __asm volatile ("mov r0, %0 \n\t"              \
+                                                "mrs r1, CPSR \n\t"            \
+                                                "bic r1, r1, #0xC0 \n\t"       \
+                                                "and r0, r0, #0xC0 \n\t"       \
+                                                "orr r1, r1, r0 \n\t"          \
+                                                "msr CPSR_c, r1 \n\t"          \
+                                                :                              \
+                                                : "r" (_SEGGER_RTT__LockState)              \
+                                                : "r0", "r1", "cc"             \
+                                                );                             \
+                            }
+  #elif defined(__riscv) || defined(__riscv_xlen)
+    #define SEGGER_RTT_LOCK()  {                                               \
+                                 unsigned int _SEGGER_RTT__LockState;                       \
+                                 __asm volatile ("csrr  %0, mstatus  \n\t"     \
+                                                 "csrci mstatus, 8   \n\t"     \
+                                                 "andi  %0, %0,  8   \n\t"     \
+                                                 : "=r" (_SEGGER_RTT__LockState)            \
+                                                 :                             \
+                                                 :                             \
+                                                );
+
+  #define SEGGER_RTT_UNLOCK()    __asm volatile ("csrr  a1, mstatus  \n\t"     \
+                                                 "or    %0, %0, a1   \n\t"     \
+                                                 "csrs  mstatus, %0  \n\t"     \
+                                                 :                             \
+                                                 : "r"  (_SEGGER_RTT__LockState)            \
+                                                 : "a1"                        \
+                                                );                             \
+                               }
+  #else
+    #define SEGGER_RTT_LOCK()
+    #define SEGGER_RTT_UNLOCK()
+  #endif
+#endif
+
+/*********************************************************************
+*
+*       RTT lock configuration for IAR EWARM
+*/
+#ifdef __ICCARM__
+  #if (defined (__ARM6M__)          && (__CORE__ == __ARM6M__))             ||                      \
+      (defined (__ARM8M_BASELINE__) && (__CORE__ == __ARM8M_BASELINE__))
+    #define SEGGER_RTT_LOCK()   {                                                                   \
+                                  unsigned int _SEGGER_RTT__LockState;                                           \
+                                  _SEGGER_RTT__LockState = __get_PRIMASK();                                      \
+                                  __set_PRIMASK(1);
+
+    #define SEGGER_RTT_UNLOCK()   __set_PRIMASK(_SEGGER_RTT__LockState);                                         \
+                                }
+  #elif (defined (__ARM7EM__)         && (__CORE__ == __ARM7EM__))          ||                      \
+        (defined (__ARM7M__)          && (__CORE__ == __ARM7M__))           ||                      \
+        (defined (__ARM8M_MAINLINE__) && (__CORE__ == __ARM8M_MAINLINE__))  ||                      \
+        (defined (__ARM8M_MAINLINE__) && (__CORE__ == __ARM8M_MAINLINE__))
+    #ifndef   SEGGER_RTT_MAX_INTERRUPT_PRIORITY
+      #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY   (0x20)
+    #endif
+    #define SEGGER_RTT_LOCK()   {                                                                   \
+                                  unsigned int _SEGGER_RTT__LockState;                                           \
+                                  _SEGGER_RTT__LockState = __get_BASEPRI();                                      \
+                                  __set_BASEPRI(SEGGER_RTT_MAX_INTERRUPT_PRIORITY);
+
+    #define SEGGER_RTT_UNLOCK()   __set_BASEPRI(_SEGGER_RTT__LockState);                                         \
+                                }
+  #elif (defined (__ARM7A__) && (__CORE__ == __ARM7A__))                    ||                      \
+        (defined (__ARM7R__) && (__CORE__ == __ARM7R__))
+    #define SEGGER_RTT_LOCK() {                                                                     \
+                                 unsigned int _SEGGER_RTT__LockState;                                            \
+                                 __asm volatile ("mrs r1, CPSR \n\t"                                \
+                                                 "mov %0, r1 \n\t"                                  \
+                                                 "orr r1, r1, #0xC0 \n\t"                           \
+                                                 "msr CPSR_c, r1 \n\t"                              \
+                                                 : "=r" (_SEGGER_RTT__LockState)                                 \
+                                                 :                                                  \
+                                                 : "r1", "cc"                                       \
+                                                 );
+
+    #define SEGGER_RTT_UNLOCK() __asm volatile ("mov r0, %0 \n\t"                                   \
+                                                "mrs r1, CPSR \n\t"                                 \
+                                                "bic r1, r1, #0xC0 \n\t"                            \
+                                                "and r0, r0, #0xC0 \n\t"                            \
+                                                "orr r1, r1, r0 \n\t"                               \
+                                                "msr CPSR_c, r1 \n\t"                               \
+                                                :                                                   \
+                                                : "r" (_SEGGER_RTT__LockState)                                   \
+                                                : "r0", "r1", "cc"                                  \
+                                                );                                                  \
+                            }
+  #endif
+#endif
+
+/*********************************************************************
+*
+*       RTT lock configuration for IAR RX
+*/
+#ifdef __ICCRX__
+  #define SEGGER_RTT_LOCK()   {                                                                     \
+                                unsigned long _SEGGER_RTT__LockState;                                            \
+                                _SEGGER_RTT__LockState = __get_interrupt_state();                                \
+                                __disable_interrupt();
+
+  #define SEGGER_RTT_UNLOCK()   __set_interrupt_state(_SEGGER_RTT__LockState);                                   \
+                              }
+#endif
+
+/*********************************************************************
+*
+*       RTT lock configuration for IAR RL78
+*/
+#ifdef __ICCRL78__
+  #define SEGGER_RTT_LOCK()   {                                                                     \
+                                __istate_t _SEGGER_RTT__LockState;                                               \
+                                _SEGGER_RTT__LockState = __get_interrupt_state();                                \
+                                __disable_interrupt();
+
+  #define SEGGER_RTT_UNLOCK()   __set_interrupt_state(_SEGGER_RTT__LockState);                                   \
+                              }
+#endif
+
+/*********************************************************************
+*
+*       RTT lock configuration for KEIL ARM
+*/
+#ifdef __CC_ARM
+  #if (defined __TARGET_ARCH_6S_M)
+    #define SEGGER_RTT_LOCK()   {                                                                   \
+                                  unsigned int _SEGGER_RTT__LockState;                                           \
+                                  register unsigned char _SEGGER_RTT__PRIMASK __asm( "primask");                 \
+                                  _SEGGER_RTT__LockState = _SEGGER_RTT__PRIMASK;                                              \
+                                  _SEGGER_RTT__PRIMASK = 1u;                                                     \
+                                  __schedule_barrier();
+
+    #define SEGGER_RTT_UNLOCK()   _SEGGER_RTT__PRIMASK = _SEGGER_RTT__LockState;                                              \
+                                  __schedule_barrier();                                             \
+                                }
+  #elif (defined(__TARGET_ARCH_7_M) || defined(__TARGET_ARCH_7E_M))
+    #ifndef   SEGGER_RTT_MAX_INTERRUPT_PRIORITY
+      #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY   (0x20)
+    #endif
+    #define SEGGER_RTT_LOCK()   {                                                                   \
+                                  unsigned int _SEGGER_RTT__LockState;                                           \
+                                  register unsigned char BASEPRI __asm( "basepri");                 \
+                                  _SEGGER_RTT__LockState = BASEPRI;                                              \
+                                  BASEPRI = SEGGER_RTT_MAX_INTERRUPT_PRIORITY;                      \
+                                  __schedule_barrier();
+
+    #define SEGGER_RTT_UNLOCK()   BASEPRI = _SEGGER_RTT__LockState;                                              \
+                                  __schedule_barrier();                                             \
+                                }
+  #endif
+#endif
+
+/*********************************************************************
+*
+*       RTT lock configuration for TI ARM
+*/
+#ifdef __TI_ARM__
+  #if defined (__TI_ARM_V6M0__)
+    #define SEGGER_RTT_LOCK()   {                                                                   \
+                                  unsigned int _SEGGER_RTT__LockState;                                           \
+                                  _SEGGER_RTT__LockState = __get_PRIMASK();                                      \
+                                  __set_PRIMASK(1);
+
+    #define SEGGER_RTT_UNLOCK()   __set_PRIMASK(_SEGGER_RTT__LockState);                                         \
+                                }
+  #elif (defined (__TI_ARM_V7M3__) || defined (__TI_ARM_V7M4__))
+    #ifndef   SEGGER_RTT_MAX_INTERRUPT_PRIORITY
+      #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY   (0x20)
+    #endif
+    #define SEGGER_RTT_LOCK()   {                                                                   \
+                                  unsigned int _SEGGER_RTT__LockState;                                           \
+                                  _SEGGER_RTT__LockState = _set_interrupt_priority(SEGGER_RTT_MAX_INTERRUPT_PRIORITY);
+
+    #define SEGGER_RTT_UNLOCK()   _set_interrupt_priority(_SEGGER_RTT__LockState);                               \
+                                }
+  #endif
+#endif
+
+/*********************************************************************
+*
+*       RTT lock configuration for CCRX
+*/
+#ifdef __RX
+  #include <machine.h>
+  #define SEGGER_RTT_LOCK()   {                                                                     \
+                                unsigned long _SEGGER_RTT__LockState;                                            \
+                                _SEGGER_RTT__LockState = get_psw() & 0x010000;                                   \
+                                clrpsw_i();
+
+  #define SEGGER_RTT_UNLOCK()   set_psw(get_psw() | _SEGGER_RTT__LockState);                                     \
+                              }
+#endif
+
+/*********************************************************************
+*
+*       RTT lock configuration for embOS Simulation on Windows
+*       (Can also be used for generic RTT locking with embOS)
+*/
+#if defined(WIN32) || defined(SEGGER_RTT_LOCK_EMBOS)
+
+void OS_SIM_EnterCriticalSection(void);
+void OS_SIM_LeaveCriticalSection(void);
+
+#define SEGGER_RTT_LOCK()       {                                                                   \
+                                  OS_SIM_EnterCriticalSection();
+
+#define SEGGER_RTT_UNLOCK()       OS_SIM_LeaveCriticalSection();                                    \
+                                }
+#endif
+
+/*********************************************************************
+*
+*       RTT lock configuration fallback
+*/
+#ifndef   SEGGER_RTT_LOCK
+  #define SEGGER_RTT_LOCK()                // Lock RTT (nestable)   (i.e. disable interrupts)
+#endif
+
+#ifndef   SEGGER_RTT_UNLOCK
+  #define SEGGER_RTT_UNLOCK()              // Unlock RTT (nestable) (i.e. enable previous interrupt lock state)
+#endif
+
+#endif
+/*************************** End of file ****************************/

+ 124 - 0
code/debug/SEGGER/SEGGER_RTT_Syscalls_GCC.c

@@ -0,0 +1,124 @@
+/*********************************************************************
+*                    SEGGER Microcontroller GmbH                     *
+*                        The Embedded Experts                        *
+**********************************************************************
+*                                                                    *
+*            (c) 1995 - 2021 SEGGER Microcontroller GmbH             *
+*                                                                    *
+*       www.segger.com     Support: support@segger.com               *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+*       SEGGER SystemView * Real-time application analysis           *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+* All rights reserved.                                               *
+*                                                                    *
+* SEGGER strongly recommends to not make any changes                 *
+* to or modify the source code of this software in order to stay     *
+* compatible with the SystemView and RTT protocol, and J-Link.       *
+*                                                                    *
+* Redistribution and use in source and binary forms, with or         *
+* without modification, are permitted provided that the following    *
+* condition is met:                                                  *
+*                                                                    *
+* o Redistributions of source code must retain the above copyright   *
+*   notice, this condition and the following disclaimer.             *
+*                                                                    *
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND             *
+* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,        *
+* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF           *
+* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE           *
+* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR           *
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT  *
+* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;    *
+* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF      *
+* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT          *
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE  *
+* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH   *
+* DAMAGE.                                                            *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+*       SystemView version: 3.32                                    *
+*                                                                    *
+**********************************************************************
+---------------------------END-OF-HEADER------------------------------
+File    : SEGGER_RTT_Syscalls_GCC.c
+Purpose : Low-level functions for using printf() via RTT in GCC.
+          To use RTT for printf output, include this file in your 
+          application.
+Revision: $Rev: 24316 $
+----------------------------------------------------------------------
+*/
+#if (defined __GNUC__) && !(defined __SES_ARM) && !(defined __CROSSWORKS_ARM) && !(defined __ARMCC_VERSION) && !(defined __CC_ARM)
+
+#include <reent.h>  // required for _write_r
+#include "SEGGER_RTT.h"
+
+
+/*********************************************************************
+*
+*       Types
+*
+**********************************************************************
+*/
+//
+// If necessary define the _reent struct
+// to match the one passed by the used standard library.
+//
+struct _reent;
+
+/*********************************************************************
+*
+*       Function prototypes
+*
+**********************************************************************
+*/
+_ssize_t _write  (int file, const void *ptr, size_t len);
+_ssize_t _write_r(struct _reent *r, int file, const void *ptr, size_t len);
+
+/*********************************************************************
+*
+*       Global functions
+*
+**********************************************************************
+*/
+
+/*********************************************************************
+*
+*       _write()
+*
+* Function description
+*   Low-level write function.
+*   libc subroutines will use this system routine for output to all files,
+*   including stdout.
+*   Write data via RTT.
+*/
+_ssize_t _write(int file, const void *ptr, size_t len) {
+  (void) file;  /* Not used, avoid warning */
+  SEGGER_RTT_Write(0, ptr, len);
+  return len;
+}
+
+/*********************************************************************
+*
+*       _write_r()
+*
+* Function description
+*   Low-level reentrant write function.
+*   libc subroutines will use this system routine for output to all files,
+*   including stdout.
+*   Write data via RTT.
+*/
+_ssize_t _write_r(struct _reent *r, int file, const void *ptr, size_t len) {
+  (void) file;  /* Not used, avoid warning */
+  (void) r;     /* Not used, avoid warning */
+  SEGGER_RTT_Write(0, ptr, len);
+  return len;
+}
+
+#endif
+/****** End Of File *************************************************/

+ 119 - 0
code/debug/SEGGER/SEGGER_RTT_Syscalls_IAR.c

@@ -0,0 +1,119 @@
+/*********************************************************************
+*                    SEGGER Microcontroller GmbH                     *
+*                        The Embedded Experts                        *
+**********************************************************************
+*                                                                    *
+*            (c) 1995 - 2021 SEGGER Microcontroller GmbH             *
+*                                                                    *
+*       www.segger.com     Support: support@segger.com               *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+*       SEGGER SystemView * Real-time application analysis           *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+* All rights reserved.                                               *
+*                                                                    *
+* SEGGER strongly recommends to not make any changes                 *
+* to or modify the source code of this software in order to stay     *
+* compatible with the SystemView and RTT protocol, and J-Link.       *
+*                                                                    *
+* Redistribution and use in source and binary forms, with or         *
+* without modification, are permitted provided that the following    *
+* condition is met:                                                  *
+*                                                                    *
+* o Redistributions of source code must retain the above copyright   *
+*   notice, this condition and the following disclaimer.             *
+*                                                                    *
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND             *
+* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,        *
+* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF           *
+* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE           *
+* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR           *
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT  *
+* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;    *
+* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF      *
+* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT          *
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE  *
+* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH   *
+* DAMAGE.                                                            *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+*       SystemView version: 3.32                                    *
+*                                                                    *
+**********************************************************************
+---------------------------END-OF-HEADER------------------------------
+File    : SEGGER_RTT_Syscalls_IAR.c
+Purpose : Low-level functions for using printf() via RTT in IAR.
+          To use RTT for printf output, include this file in your
+          application and set the Library Configuration to Normal.
+Revision: $Rev: 24316 $
+----------------------------------------------------------------------
+*/
+#ifdef __IAR_SYSTEMS_ICC__
+
+//
+// Since IAR EWARM V8 and EWRX V4, yfuns.h is considered as deprecated and LowLevelIOInterface.h
+// shall be used instead. To not break any compatibility with older compiler versions, we have a
+// version check in here.
+//
+#if ((defined __ICCARM__) && (__VER__ >= 8000000)) || ((defined __ICCRX__)  && (__VER__ >= 400))
+  #include <LowLevelIOInterface.h>
+#else
+  #include <yfuns.h>
+#endif
+
+#include "SEGGER_RTT.h"
+#pragma module_name = "?__write"
+
+/*********************************************************************
+*
+*       Function prototypes
+*
+**********************************************************************
+*/
+size_t __write(int handle, const unsigned char * buffer, size_t size);
+
+/*********************************************************************
+*
+*       Global functions
+*
+**********************************************************************
+*/
+/*********************************************************************
+*
+*       __write()
+*
+* Function description
+*   Low-level write function.
+*   Standard library subroutines will use this system routine
+*   for output to all files, including stdout.
+*   Write data via RTT.
+*/
+size_t __write(int handle, const unsigned char * buffer, size_t size) {
+  (void) handle;  /* Not used, avoid warning */
+  SEGGER_RTT_Write(0, (const char*)buffer, size);
+  return size;
+}
+
+/*********************************************************************
+*
+*       __write_buffered()
+*
+* Function description
+*   Low-level write function.
+*   Standard library subroutines will use this system routine
+*   for output to all files, including stdout.
+*   Write data via RTT.
+*/
+size_t __write_buffered(int handle, const unsigned char * buffer, size_t size) {
+  (void) handle;  /* Not used, avoid warning */
+  SEGGER_RTT_Write(0, (const char*)buffer, size);
+  return size;
+}
+
+#endif
+/****** End Of File *************************************************/

+ 393 - 0
code/debug/SEGGER/SEGGER_RTT_Syscalls_KEIL.c

@@ -0,0 +1,393 @@
+/*********************************************************************
+*                    SEGGER Microcontroller GmbH                     *
+*                        The Embedded Experts                        *
+**********************************************************************
+*                                                                    *
+*            (c) 1995 - 2021 SEGGER Microcontroller GmbH             *
+*                                                                    *
+*       www.segger.com     Support: support@segger.com               *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+*       SEGGER SystemView * Real-time application analysis           *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+* All rights reserved.                                               *
+*                                                                    *
+* SEGGER strongly recommends to not make any changes                 *
+* to or modify the source code of this software in order to stay     *
+* compatible with the SystemView and RTT protocol, and J-Link.       *
+*                                                                    *
+* Redistribution and use in source and binary forms, with or         *
+* without modification, are permitted provided that the following    *
+* condition is met:                                                  *
+*                                                                    *
+* o Redistributions of source code must retain the above copyright   *
+*   notice, this condition and the following disclaimer.             *
+*                                                                    *
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND             *
+* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,        *
+* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF           *
+* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE           *
+* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR           *
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT  *
+* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;    *
+* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF      *
+* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT          *
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE  *
+* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH   *
+* DAMAGE.                                                            *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+*       SystemView version: 3.32                                    *
+*                                                                    *
+**********************************************************************
+---------------------------END-OF-HEADER------------------------------
+File    : RTT_Syscalls_KEIL.c
+Purpose : Retargeting module for KEIL MDK-CM3.
+          Low-level functions for using printf() via RTT
+Revision: $Rev: 24316 $
+Notes   : (1) https://wiki.segger.com/Keil_MDK-ARM#RTT_in_uVision
+----------------------------------------------------------------------
+*/
+#if (defined __CC_ARM) || (defined __ARMCC_VERSION)
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <rt_sys.h>
+#include <rt_misc.h>
+
+#include "SEGGER_RTT.h"
+/*********************************************************************
+*
+*       #pragmas
+*
+**********************************************************************
+*/
+#if __ARMCC_VERSION < 6000000
+#pragma import(__use_no_semihosting)
+#endif
+
+#ifdef _MICROLIB
+  #pragma import(__use_full_stdio)
+#endif
+
+/*********************************************************************
+*
+*       Defines non-configurable
+*
+**********************************************************************
+*/
+
+/* Standard IO device handles - arbitrary, but any real file system handles must be
+   less than 0x8000. */
+#define STDIN             0x8001    // Standard Input Stream
+#define STDOUT            0x8002    // Standard Output Stream
+#define STDERR            0x8003    // Standard Error Stream
+
+/*********************************************************************
+*
+*       Public const
+*
+**********************************************************************
+*/
+#if __ARMCC_VERSION < 5000000
+//const char __stdin_name[]  = "STDIN";
+const char __stdout_name[] = "STDOUT";
+const char __stderr_name[] = "STDERR";
+#endif
+
+/*********************************************************************
+*
+*       Public code
+*
+**********************************************************************
+*/
+
+/*********************************************************************
+*
+*       _ttywrch
+*
+*  Function description:
+*    Outputs a character to the console
+*
+*  Parameters:
+*    c    - character to output
+*  
+*/
+void _ttywrch(int c) {
+  fputc(c, stdout); // stdout
+  fflush(stdout);
+}
+
+/*********************************************************************
+*
+*       _sys_open
+*
+*  Function description:
+*    Opens the device/file in order to do read/write operations
+*
+*  Parameters:
+*    sName        - sName of the device/file to open
+*    OpenMode    - This parameter is currently ignored
+*  
+*  Return value:
+*    != 0     - Handle to the object to open, otherwise 
+*    == 0     -"device" is not handled by this module
+*
+*/
+FILEHANDLE _sys_open(const char * sName, int OpenMode) {
+  (void)OpenMode;
+  // Register standard Input Output devices.
+  if (strcmp(sName, __stdout_name) == 0) {
+    return (STDOUT);
+  } else if (strcmp(sName, __stderr_name) == 0) {
+    return (STDERR);
+  } else
+  return (0);  // Not implemented
+}
+
+/*********************************************************************
+*
+*       _sys_close
+*
+*  Function description:
+*    Closes the handle to the open device/file
+*
+*  Parameters:
+*    hFile    - Handle to a file opened via _sys_open
+*  
+*  Return value:
+*    0     - device/file closed
+*
+*/
+int _sys_close(FILEHANDLE hFile) {
+  (void)hFile;
+  return 0;  // Not implemented
+}
+
+/*********************************************************************
+*
+*       _sys_write
+*
+*  Function description:
+*    Writes the data to an open handle.
+*    Currently this function only outputs data to the console
+*
+*  Parameters:
+*    hFile    - Handle to a file opened via _sys_open
+*    pBuffer  - Pointer to the data that shall be written
+*    NumBytes      - Number of bytes to write
+*    Mode     - The Mode that shall be used
+*  
+*  Return value:
+*    Number of bytes *not* written to the file/device
+*
+*/
+int _sys_write(FILEHANDLE hFile, const unsigned char * pBuffer, unsigned NumBytes, int Mode) {
+  int r = 0;
+
+  (void)Mode;
+  if (hFile == STDOUT) {
+    SEGGER_RTT_Write(0, (const char*)pBuffer, NumBytes);
+		return 0;
+  }
+  return r;
+}
+
+/*********************************************************************
+*
+*       _sys_read
+*
+*  Function description:
+*    Reads data from an open handle.
+*    Currently this modules does nothing.
+*
+*  Parameters:
+*    hFile    - Handle to a file opened via _sys_open
+*    pBuffer  - Pointer to buffer to store the read data
+*    NumBytes      - Number of bytes to read
+*    Mode     - The Mode that shall be used
+*  
+*  Return value:
+*    Number of bytes read from the file/device
+*
+*/
+int _sys_read(FILEHANDLE hFile, unsigned char * pBuffer, unsigned NumBytes, int Mode) {
+  (void)hFile;
+  (void)pBuffer;
+  (void)NumBytes;
+  (void)Mode;
+  return (0);  // Not implemented
+}
+
+/*********************************************************************
+*
+*       _sys_istty
+*
+*  Function description:
+*    This function shall return whether the opened file 
+*    is a console device or not.
+*
+*  Parameters:
+*    hFile    - Handle to a file opened via _sys_open
+*  
+*  Return value:
+*    1       - Device is     a console
+*    0       - Device is not a console
+*
+*/
+int _sys_istty(FILEHANDLE hFile) {
+  if (hFile > 0x8000) {
+    return (1);
+  }
+  return (0);  // Not implemented
+}
+
+/*********************************************************************
+*
+*       _sys_seek
+*
+*  Function description:
+*    Seeks via the file to a specific position
+*
+*  Parameters:
+*    hFile  - Handle to a file opened via _sys_open
+*    Pos    - 
+*  
+*  Return value:
+*    int       - 
+*
+*/
+int _sys_seek(FILEHANDLE hFile, long Pos) {
+  (void)hFile;
+  (void)Pos;
+  return (0);  // Not implemented
+}
+
+/*********************************************************************
+*
+*       _sys_ensure
+*
+*  Function description:
+*    
+*
+*  Parameters:
+*    hFile    - Handle to a file opened via _sys_open
+*  
+*  Return value:
+*    int       - 
+*
+*/
+int _sys_ensure(FILEHANDLE hFile) {
+  (void)hFile;
+  return (-1);  // Not implemented
+}
+
+/*********************************************************************
+*
+*       _sys_flen
+*
+*  Function description:
+*    Returns the length of the opened file handle
+*
+*  Parameters:
+*    hFile    - Handle to a file opened via _sys_open
+*  
+*  Return value:
+*    Length of the file
+*
+*/
+long _sys_flen(FILEHANDLE hFile) {
+  (void)hFile;
+  return (0);  // Not implemented
+}
+
+/*********************************************************************
+*
+*       _sys_tmpnam
+*
+*  Function description:
+*    This function converts the file number fileno for a temporary 
+*    file to a unique filename, for example, tmp0001.
+*
+*  Parameters:
+*    pBuffer    - Pointer to a buffer to store the name
+*    FileNum    - file number to convert
+*    MaxLen     - Size of the buffer
+*  
+*  Return value:
+*     1 - Error
+*     0 - Success  
+*
+*/
+int _sys_tmpnam(char * pBuffer, int FileNum, unsigned MaxLen) {
+  (void)pBuffer;
+  (void)FileNum;
+  (void)MaxLen;
+  return (1);  // Not implemented
+}
+
+/*********************************************************************
+*
+*       _sys_command_string
+*
+*  Function description:
+*    This function shall execute a system command.
+*
+*  Parameters:
+*    cmd    - Pointer to the command string
+*    len    - Length of the string
+*  
+*  Return value:
+*    == NULL - Command was not successfully executed
+*    == sCmd - Command was passed successfully
+*
+*/
+char * _sys_command_string(char * cmd, int len) {
+  (void)len;
+  return cmd;  // Not implemented
+}
+
+/*********************************************************************
+*
+*       _sys_exit
+*
+*  Function description:
+*    This function is called when the application returns from main
+*
+*  Parameters:
+*    ReturnCode    - Return code from the main function
+*  
+*
+*/
+void _sys_exit(int ReturnCode) {
+  (void)ReturnCode;
+  while (1);  // Not implemented
+}
+
+#if __ARMCC_VERSION >= 5000000
+/*********************************************************************
+*
+*       stdout_putchar
+*
+*  Function description:
+*    Put a character to the stdout
+*
+*  Parameters:
+*    ch    - Character to output
+*  
+*
+*/
+int stdout_putchar(int ch) {
+  (void)ch;
+  return ch;  // Not implemented
+}
+#endif
+
+#endif
+/*************************** End of file ****************************/

+ 251 - 0
code/debug/SEGGER/SEGGER_RTT_Syscalls_SES.c

@@ -0,0 +1,251 @@
+/*********************************************************************
+*                    SEGGER Microcontroller GmbH                     *
+*                        The Embedded Experts                        *
+**********************************************************************
+*                                                                    *
+*            (c) 1995 - 2021 SEGGER Microcontroller GmbH             *
+*                                                                    *
+*       www.segger.com     Support: support@segger.com               *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+*       SEGGER SystemView * Real-time application analysis           *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+* All rights reserved.                                               *
+*                                                                    *
+* SEGGER strongly recommends to not make any changes                 *
+* to or modify the source code of this software in order to stay     *
+* compatible with the SystemView and RTT protocol, and J-Link.       *
+*                                                                    *
+* Redistribution and use in source and binary forms, with or         *
+* without modification, are permitted provided that the following    *
+* condition is met:                                                  *
+*                                                                    *
+* o Redistributions of source code must retain the above copyright   *
+*   notice, this condition and the following disclaimer.             *
+*                                                                    *
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND             *
+* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,        *
+* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF           *
+* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE           *
+* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR           *
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT  *
+* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;    *
+* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF      *
+* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT          *
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE  *
+* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH   *
+* DAMAGE.                                                            *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+*       SystemView version: 3.32                                    *
+*                                                                    *
+**********************************************************************
+---------------------------END-OF-HEADER------------------------------
+File    : SEGGER_RTT_Syscalls_SES.c
+Purpose : Reimplementation of printf, puts and __getchar using RTT
+          in SEGGER Embedded Studio.
+          To use RTT for printf output, include this file in your
+          application.
+Revision: $Rev: 24316 $
+----------------------------------------------------------------------
+*/
+#if (defined __SES_ARM) || (defined __SES_RISCV) || (defined __CROSSWORKS_ARM)
+
+#include "SEGGER_RTT.h"
+#include <stdarg.h>
+#include <stdio.h>
+#include "limits.h"
+#include "__libc.h"
+#include "__vfprintf.h"
+
+/*********************************************************************
+*
+*       Defines, configurable
+*
+**********************************************************************
+*/
+//
+// Select string formatting implementation.
+//
+// RTT printf formatting
+//  - Configurable stack usage. (SEGGER_RTT_PRINTF_BUFFER_SIZE in SEGGER_RTT_Conf.h)
+//  - No maximum string length.
+//  - Limited conversion specifiers and flags. (See SEGGER_RTT_printf.c)
+// Standard library printf formatting
+//  - Configurable formatting capabilities.
+//  - Full conversion specifier and flag support.
+//  - Maximum string length has to be known or (slightly) slower character-wise output.
+//
+// #define PRINTF_USE_SEGGER_RTT_FORMATTING    0 // Use standard library formatting
+// #define PRINTF_USE_SEGGER_RTT_FORMATTING    1 // Use RTT formatting
+//
+#ifndef   PRINTF_USE_SEGGER_RTT_FORMATTING
+  #define PRINTF_USE_SEGGER_RTT_FORMATTING    0
+#endif
+//
+// If using standard library formatting,
+// select maximum output string buffer size or character-wise output.
+//
+// #define PRINTF_BUFFER_SIZE                  0 // Use character-wise output
+// #define PRINTF_BUFFER_SIZE                128 // Default maximum string length
+//
+#ifndef   PRINTF_BUFFER_SIZE
+  #define PRINTF_BUFFER_SIZE                128
+#endif
+
+#if PRINTF_USE_SEGGER_RTT_FORMATTING  // Use SEGGER RTT formatting implementation
+/*********************************************************************
+*
+*       Function prototypes
+*
+**********************************************************************
+*/
+int SEGGER_RTT_vprintf(unsigned BufferIndex, const char * sFormat, va_list * pParamList);
+
+/*********************************************************************
+*
+*       Global functions, printf
+*
+**********************************************************************
+*/
+/*********************************************************************
+*
+*       printf()
+*
+*  Function description
+*    print a formatted string using RTT and SEGGER RTT formatting.
+*/
+int printf(const char *fmt,...) {
+  int     n;
+  va_list args;
+
+  va_start (args, fmt);
+  n = SEGGER_RTT_vprintf(0, fmt, &args);
+  va_end(args);
+  return n;
+}
+
+#elif PRINTF_BUFFER_SIZE == 0 // Use standard library formatting with character-wise output
+
+/*********************************************************************
+*
+*       Static functions
+*
+**********************************************************************
+*/
+static int _putchar(int x, __printf_tag_ptr ctx) {
+  (void)ctx;
+  SEGGER_RTT_Write(0, (char *)&x, 1);
+  return x;
+}
+
+/*********************************************************************
+*
+*       Global functions, printf
+*
+**********************************************************************
+*/
+/*********************************************************************
+*
+*       printf()
+*
+*  Function description
+*    print a formatted string character-wise, using RTT and standard
+*    library formatting.
+*/
+int printf(const char *fmt, ...) {
+  int         n;
+  va_list     args;
+  __printf_t  iod;
+
+  va_start(args, fmt);
+  iod.string    = 0;
+  iod.maxchars  = INT_MAX;
+  iod.output_fn = _putchar;
+  SEGGER_RTT_LOCK();
+  n = __vfprintf(&iod, fmt, args);
+  SEGGER_RTT_UNLOCK();
+  va_end(args);
+  return n;
+}
+
+#else // Use standard library formatting with static buffer
+
+/*********************************************************************
+*
+*       Global functions, printf
+*
+**********************************************************************
+*/
+/*********************************************************************
+*
+*       printf()
+*
+*  Function description
+*    print a formatted string using RTT and standard library formatting.
+*/
+int printf(const char *fmt,...) {
+  int     n;
+  char    aBuffer[PRINTF_BUFFER_SIZE];
+  va_list args;
+
+  va_start (args, fmt);
+  n = vsnprintf(aBuffer, sizeof(aBuffer), fmt, args);
+  if (n > (int)sizeof(aBuffer)) {
+    SEGGER_RTT_Write(0, aBuffer, sizeof(aBuffer));
+  } else if (n > 0) {
+    SEGGER_RTT_Write(0, aBuffer, n);
+  }
+  va_end(args);
+  return n;
+}
+#endif
+
+/*********************************************************************
+*
+*       Global functions
+*
+**********************************************************************
+*/
+/*********************************************************************
+*
+*       puts()
+*
+*  Function description
+*    print a string using RTT.
+*/
+int puts(const char *s) {
+  return SEGGER_RTT_WriteString(0, s);
+}
+
+/*********************************************************************
+*
+*       __putchar()
+*
+*  Function description
+*    Write one character via RTT.
+*/
+int __putchar(int x, __printf_tag_ptr ctx) {
+  (void)ctx;
+  SEGGER_RTT_Write(0, (char *)&x, 1);
+  return x;
+}
+
+/*********************************************************************
+*
+*       __getchar()
+*
+*  Function description
+*    Wait for and get a character via RTT.
+*/
+int __getchar() {
+  return SEGGER_RTT_WaitKey();
+}
+
+#endif
+/****** End Of File *************************************************/

+ 9 - 24
src/SEGGER_RTT_printf.c → code/debug/SEGGER/SEGGER_RTT_printf.c

@@ -1,15 +1,15 @@
 /*********************************************************************
-*                SEGGER Microcontroller GmbH & Co. KG                *
+*                    SEGGER Microcontroller GmbH                     *
 *                        The Embedded Experts                        *
 **********************************************************************
 *                                                                    *
-*       (c) 2014 - 2016  SEGGER Microcontroller GmbH & Co. KG        *
+*            (c) 1995 - 2021 SEGGER Microcontroller GmbH             *
 *                                                                    *
 *       www.segger.com     Support: support@segger.com               *
 *                                                                    *
 **********************************************************************
 *                                                                    *
-*       SEGGER RTT * Real Time Transfer for embedded targets         *
+*       SEGGER SystemView * Real-time application analysis           *
 *                                                                    *
 **********************************************************************
 *                                                                    *
@@ -17,24 +17,14 @@
 *                                                                    *
 * SEGGER strongly recommends to not make any changes                 *
 * to or modify the source code of this software in order to stay     *
-* compatible with the RTT protocol and J-Link.                       *
+* compatible with the SystemView and RTT protocol, and J-Link.       *
 *                                                                    *
 * Redistribution and use in source and binary forms, with or         *
 * without modification, are permitted provided that the following    *
-* conditions are met:                                                *
+* condition is met:                                                  *
 *                                                                    *
 * o Redistributions of source code must retain the above copyright   *
-*   notice, this list of conditions and the following disclaimer.    *
-*                                                                    *
-* o Redistributions in binary form must reproduce the above          *
-*   copyright notice, this list of conditions and the following      *
-*   disclaimer in the documentation and/or other materials provided  *
-*   with the distribution.                                           *
-*                                                                    *
-* o Neither the name of SEGGER Microcontroller GmbH & Co. KG         *
-*   nor the names of its contributors may be used to endorse or      *
-*   promote products derived from this software without specific     *
-*   prior written permission.                                        *
+*   notice, this condition and the following disclaimer.             *
 *                                                                    *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND             *
 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,        *
@@ -52,13 +42,13 @@
 *                                                                    *
 **********************************************************************
 *                                                                    *
-*       RTT version: 6.10i                                           *
+*       SystemView version: 3.32                                    *
 *                                                                    *
 **********************************************************************
 ---------------------------END-OF-HEADER------------------------------
 File    : SEGGER_RTT_printf.c
 Purpose : Replacement for printf to write formatted data via RTT
-Revision: $Rev: 4351 $
+Revision: $Rev: 17697 $
 ----------------------------------------------------------------------
 */
 #include "SEGGER_RTT.h"
@@ -107,7 +97,6 @@ typedef struct {
 *
 **********************************************************************
 */
-int SEGGER_RTT_vprintf(unsigned BufferIndex, const char * sFormat, va_list * pParamList);
 
 /*********************************************************************
 *
@@ -503,16 +492,12 @@ int SEGGER_RTT_vprintf(unsigned BufferIndex, const char * sFormat, va_list * pPa
 *          s: Print the string pointed to by the argument
 *          p: Print the argument as an 8-digit hexadecimal integer. (Argument shall be a pointer to void.)
 */
-
-
-
 int SEGGER_RTT_printf(const char * sFormat, ...) {
   int r;
-	unsigned BufferIndex = 0;
   va_list ParamList;
 
   va_start(ParamList, sFormat);
-  r = SEGGER_RTT_vprintf(BufferIndex, sFormat, &ParamList);
+  r = SEGGER_RTT_vprintf(0, sFormat, &ParamList);
   va_end(ParamList);
   return r;
 }

+ 3102 - 0
code/debug/SEGGER/SEGGER_SYSVIEW.c

@@ -0,0 +1,3102 @@
+/*********************************************************************
+*                    SEGGER Microcontroller GmbH                     *
+*                        The Embedded Experts                        *
+**********************************************************************
+*                                                                    *
+*            (c) 1995 - 2021 SEGGER Microcontroller GmbH             *
+*                                                                    *
+*       www.segger.com     Support: support@segger.com               *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+*       SEGGER SystemView * Real-time application analysis           *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+* All rights reserved.                                               *
+*                                                                    *
+* SEGGER strongly recommends to not make any changes                 *
+* to or modify the source code of this software in order to stay     *
+* compatible with the SystemView and RTT protocol, and J-Link.       *
+*                                                                    *
+* Redistribution and use in source and binary forms, with or         *
+* without modification, are permitted provided that the following    *
+* condition is met:                                                  *
+*                                                                    *
+* o Redistributions of source code must retain the above copyright   *
+*   notice, this condition and the following disclaimer.             *
+*                                                                    *
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND             *
+* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,        *
+* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF           *
+* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE           *
+* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR           *
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT  *
+* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;    *
+* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF      *
+* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT          *
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE  *
+* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH   *
+* DAMAGE.                                                            *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+*       SystemView version: 3.32                                    *
+*                                                                    *
+**********************************************************************
+-------------------------- END-OF-HEADER -----------------------------
+
+File    : SEGGER_SYSVIEW.c
+Purpose : System visualization API implementation.
+Revision: $Rev: 26232 $
+
+Additional information:
+  Packet format:
+    Packets with IDs 0..23 are standard packets with known structure.
+    For efficiency, they do *NOT* contain a length field.
+    <ID><Data><TimeStampDelta>
+
+    Packets with IDs 24..31 are standard packets with extendible
+    structure and contain a length field.
+    <ID><Lenght><Data><TimeStampDelta>
+
+    Packet ID 31 is used for SystemView extended events.
+    <ID><Lenght><ID_EX><Data><TimeStampDelta>
+
+    Packets with IDs >= 32 always contain a length field.
+    <ID><Length><Data><TimeStampDelta>
+
+  Packet IDs:
+       0..  31 : Standard packets, known by SystemView.
+      32..1023 : OS-definable packets, described in a SystemView description file.
+    1024..2047 : User-definable packets, described in a SystemView description file.
+    2048..32767: Undefined.
+
+  Data encoding:
+    Basic types (int, short, char, ...):
+      Basic types are encoded little endian with most-significant bit variant
+      encoding.
+      Each encoded byte contains 7 data bits [6:0] and the MSB continuation bit.
+      The continuation bit indicates whether the next byte belongs to the data
+      (bit set) or this is the last byte (bit clear).
+      The most significant bits of data are encoded first, proceeding to the
+      least significant bits in the final byte (little endian).
+
+      Example encoding:
+        Data: 0x1F4 (500)
+        Encoded: 0xF4 (First 7 data bits 74 | Continuation bit)
+                 0x03 (Second 7 data bits 03, no continuation)
+
+        Data: 0xFFFFFFFF
+        Encoded: 0xFF 0xFF 0xFF 0xFF 0x0F
+
+        Data: 0xA2 (162),   0x03 (3), 0x7000
+        Encoded: 0xA2 0x01  0x03      0x80 0xE0 0x01
+
+    Byte arrays and strings:
+      Byte arrays and strings are encoded as <NumBytes> followed by the raw data.
+      NumBytes is encoded as a basic type with a theoretical maximum of 4G.
+
+      Example encoding:
+        Data: "Hello World\0" (0x48 0x65 0x6C 0x6C 0x6F 0x20 0x57 0x6F 0x72 0x6C 0x64 0x00)
+        Encoded: 0x0B 0x48 0x65 0x6C 0x6C 0x6F 0x20 0x57 0x6F 0x72 0x6C 0x64
+
+  Examples packets:
+  01 F4 03 80 80 10 // Overflow packet. Data is a single U32.
+                       This packet means: 500 packets lost, Timestamp is 0x40000
+
+  02 0F 50          // ISR(15) Enter. Timestamp 80 (0x50)
+
+  03 20             // ISR Exit. Timestamp 32 (0x20) (Shortest possible packet.)
+
+  Sample code for user defined Packets:
+    #define MY_ID   0x400                // Any value between 0x400 and 0x7FF
+    void SendMyPacket(unsigned Para0, unsigned Para1, const char* s) {
+      U8  aPacket[SEGGER_SYSVIEW_INFO_SIZE + 2 * SEGGER_SYSVIEW_QUANTA_U32 + MAX_STR_LEN + 1];
+      U8* pPayload;
+      //
+      pPayload = SEGGER_SYSVIEW_PPREPARE_PACKET(aPacket);               // Prepare the packet for SystemView
+      pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para0);             // Add the first parameter to the packet
+      pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para1);             // Add the second parameter to the packet
+      pPayload = SEGGER_SYSVIEW_EncodeString(pPayload, s, MAX_STR_LEN); // Add the string to the packet
+      //
+      SEGGER_SYSVIEW_SendPacket(&aPacket[0], pPayload, MY_ID);          // Send the packet with EventId = MY_ID
+    }
+
+    #define MY_ID_1 0x401
+    void SendOnePara(unsigned Para0) {
+      SEGGER_SYSVIEW_RecordU32(MY_ID_1, Para0);
+    }
+
+*/
+
+/*********************************************************************
+*
+*       #include section
+*
+**********************************************************************
+*/
+
+#define SEGGER_SYSVIEW_C  // For EXTERN statements in SEGGER_SYSVIEW.h
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include "SEGGER_SYSVIEW_Int.h"
+#include "SEGGER_RTT.h"
+
+/*********************************************************************
+*
+*       Defines, fixed
+*
+**********************************************************************
+*/
+#if SEGGER_SYSVIEW_ID_SHIFT
+  #define SHRINK_ID(Id)   (((Id) - _SYSVIEW_Globals.RAMBaseAddress) >> SEGGER_SYSVIEW_ID_SHIFT)
+#else
+  #define SHRINK_ID(Id)   ((Id) - _SYSVIEW_Globals.RAMBaseAddress)
+#endif
+
+#if SEGGER_SYSVIEW_RTT_CHANNEL > 0
+  #define CHANNEL_ID_UP   SEGGER_SYSVIEW_RTT_CHANNEL
+  #define CHANNEL_ID_DOWN SEGGER_SYSVIEW_RTT_CHANNEL
+#else
+  #define CHANNEL_ID_UP   _SYSVIEW_Globals.UpChannel
+  #define CHANNEL_ID_DOWN _SYSVIEW_Globals.DownChannel
+#endif
+
+#if SEGGER_SYSVIEW_CPU_CACHE_LINE_SIZE
+  #if (SEGGER_SYSVIEW_RTT_BUFFER_SIZE % SEGGER_SYSVIEW_CPU_CACHE_LINE_SIZE)
+    #error "SEGGER_SYSVIEW_RTT_BUFFER_SIZE must be a multiple of SEGGER_SYSVIEW_CPU_CACHE_LINE_SIZE"
+  #endif
+#endif
+
+/*********************************************************************
+*
+*       Defines, configurable
+*
+**********************************************************************
+*/
+// Timestamps may be less than full 32-bits, in which case we need to zero
+// the unused bits to properly handle overflows.
+// Note that this is a quite common scenario, as a 32-bit time such as
+// SysTick might be scaled down to reduce bandwith
+// or a 16-bit hardware time might be used.
+#if SEGGER_SYSVIEW_TIMESTAMP_BITS < 32  // Eliminate unused bits in case hardware timestamps are less than 32 bits
+  #define MAKE_DELTA_32BIT(Delta) Delta <<= 32 - SEGGER_SYSVIEW_TIMESTAMP_BITS; \
+                                  Delta >>= 32 - SEGGER_SYSVIEW_TIMESTAMP_BITS;
+#else
+  #define MAKE_DELTA_32BIT(Delta)
+#endif
+
+#if SEGGER_SYSVIEW_SUPPORT_LONG_ID
+  #define _MAX_ID_BYTES       5u
+#else
+  #define _MAX_ID_BYTES       2u
+#endif
+
+#if SEGGER_SYSVIEW_SUPPORT_LONG_DATA
+  #define _MAX_DATA_BYTES     5u
+#else
+  #define _MAX_DATA_BYTES     2u
+#endif
+
+/*********************************************************************
+*
+*       Defines, fixed
+*
+**********************************************************************
+*/
+#define ENABLE_STATE_OFF        0
+#define ENABLE_STATE_ON         1
+#define ENABLE_STATE_DROPPING   2
+
+#define FORMAT_FLAG_LEFT_JUSTIFY   (1u << 0)
+#define FORMAT_FLAG_PAD_ZERO       (1u << 1)
+#define FORMAT_FLAG_PRINT_SIGN     (1u << 2)
+#define FORMAT_FLAG_ALTERNATE      (1u << 3)
+
+#define MODULE_EVENT_OFFSET        (512)
+
+/*********************************************************************
+*
+*       Types, local
+*
+**********************************************************************
+*/
+typedef struct {
+  U8*       pBuffer;
+  U8*       pPayload;
+  U8*       pPayloadStart;
+  U32       Options;
+  unsigned  Cnt;
+} SEGGER_SYSVIEW_PRINTF_DESC;
+
+typedef struct {
+        U8                      EnableState;   // 0: Disabled, 1: Enabled, (2: Dropping)
+        U8                      UpChannel;
+        U8                      RecursionCnt;
+        U32                     SysFreq;
+        U32                     CPUFreq;
+        U32                     LastTxTimeStamp;
+        U32                     RAMBaseAddress;
+#if (SEGGER_SYSVIEW_POST_MORTEM_MODE == 1)
+        U32                     PacketCount;
+#else
+        U32                     DropCount;
+        U8                      DownChannel;
+#endif
+        U32                     DisabledEvents;
+  const SEGGER_SYSVIEW_OS_API*  pOSAPI;
+        SEGGER_SYSVIEW_SEND_SYS_DESC_FUNC*   pfSendSysDesc;
+} SEGGER_SYSVIEW_GLOBALS;
+
+/*********************************************************************
+*
+*       Function prototypes, required
+*
+**********************************************************************
+*/
+static void _SendPacket(U8* pStartPacket, U8* pEndPacket, unsigned int EventId);
+
+/*********************************************************************
+*
+*       Static data
+*
+**********************************************************************
+*/
+static const U8 _abSync[10] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+
+#if SEGGER_SYSVIEW_CPU_CACHE_LINE_SIZE
+  #ifdef SEGGER_SYSVIEW_SECTION
+    //
+    // Alignment + special section required
+    //
+    #if (defined __GNUC__)
+      __attribute__ ((section (SEGGER_SYSVIEW_SECTION), aligned (SEGGER_SYSVIEW_CPU_CACHE_LINE_SIZE))) static char _UpBuffer  [SEGGER_SYSVIEW_RTT_BUFFER_SIZE];
+      #if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1)
+        __attribute__ ((section (SEGGER_SYSVIEW_SECTION), aligned (SEGGER_SYSVIEW_CPU_CACHE_LINE_SIZE))) static char _DownBuffer[8];  // Small, fixed-size buffer, for back-channel comms
+      #endif
+    #elif (defined __ICCARM__) || (defined __ICCRX__)
+      #pragma location=SEGGER_SYSVIEW_SECTION
+      #pragma data_alignment=SEGGER_RTT_CPU_CACHE_LINE_SIZE
+      static char _UpBuffer  [SEGGER_SYSVIEW_RTT_BUFFER_SIZE];
+      #if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1)
+        #pragma location=SEGGER_SYSVIEW_SECTION
+        #pragma data_alignment=SEGGER_RTT_CPU_CACHE_LINE_SIZE
+        static char _DownBuffer[8];  // Small, fixed-size buffer, for back-channel comms
+      #endif
+    #elif (defined __CC_ARM)
+      __attribute__ ((section (SEGGER_SYSVIEW_SECTION), aligned (SEGGER_SYSVIEW_CPU_CACHE_LINE_SIZE), zero_init)) static char _UpBuffer  [SEGGER_SYSVIEW_RTT_BUFFER_SIZE];
+      #if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1)
+        __attribute__ ((section (SEGGER_SYSVIEW_SECTION), aligned (SEGGER_SYSVIEW_CPU_CACHE_LINE_SIZE), zero_init)) static char _DownBuffer[8];  // Small, fixed-size buffer, for back-channel comms
+      #endif
+    #else
+      #error "Do not know how to place SystemView buffers in specific section"
+    #endif
+  #else
+    //
+    // Only alignment required
+    //
+    #if (defined __GNUC__)
+      __attribute__ ((aligned (SEGGER_SYSVIEW_CPU_CACHE_LINE_SIZE))) static char _UpBuffer  [SEGGER_SYSVIEW_RTT_BUFFER_SIZE];
+      #if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1)
+        __attribute__ ((aligned (SEGGER_SYSVIEW_CPU_CACHE_LINE_SIZE))) static char _DownBuffer[8];  // Small, fixed-size buffer, for back-channel comms
+      #endif
+    #elif (defined __ICCARM__) || (defined __ICCRX__)
+      #pragma data_alignment=SEGGER_RTT_CPU_CACHE_LINE_SIZE
+      static char _UpBuffer  [SEGGER_SYSVIEW_RTT_BUFFER_SIZE];
+      #if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1)
+        #pragma data_alignment=SEGGER_RTT_CPU_CACHE_LINE_SIZE
+        static char _DownBuffer[8];  // Small, fixed-size buffer, for back-channel comms
+      #endif
+    #elif (defined __CC_ARM)
+      __attribute__ ((aligned (SEGGER_SYSVIEW_CPU_CACHE_LINE_SIZE), zero_init)) static char _UpBuffer  [SEGGER_SYSVIEW_RTT_BUFFER_SIZE];
+      #if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1)
+        __attribute__ ((aligned (SEGGER_SYSVIEW_CPU_CACHE_LINE_SIZE), zero_init)) static char _DownBuffer[8];  // Small, fixed-size buffer, for back-channel comms
+      #endif
+    #else
+      #error "Do not know how to align SystemView buffers to cache line size"
+    #endif
+  #endif
+#else
+  #ifdef SEGGER_SYSVIEW_SECTION
+    //
+    // Only special section required
+    //
+    #if (defined __GNUC__)
+      __attribute__ ((section (SEGGER_SYSVIEW_SECTION))) static char _UpBuffer  [SEGGER_SYSVIEW_RTT_BUFFER_SIZE];
+      #if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1)
+        __attribute__ ((section (SEGGER_SYSVIEW_SECTION))) static char _DownBuffer[8];  // Small, fixed-size buffer, for back-channel comms
+      #endif
+    #elif (defined __ICCARM__) || (defined __ICCRX__)
+      #pragma location=SEGGER_SYSVIEW_SECTION
+      static char _UpBuffer  [SEGGER_SYSVIEW_RTT_BUFFER_SIZE];
+      #if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1)
+        #pragma location=SEGGER_SYSVIEW_SECTION
+        static char _DownBuffer[8];  // Small, fixed-size buffer, for back-channel comms
+      #endif
+    #elif (defined __CC_ARM)
+      __attribute__ ((section (SEGGER_SYSVIEW_SECTION), zero_init)) static char _UpBuffer  [SEGGER_SYSVIEW_RTT_BUFFER_SIZE];
+      #if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1)
+        __attribute__ ((section (SEGGER_SYSVIEW_SECTION), zero_init)) static char _DownBuffer[8];  // Small, fixed-size buffer, for back-channel comms
+      #endif
+    #else
+      #error "Do not know how to place SystemView buffers in specific section"
+    #endif
+  #else
+    //
+    // Neither special section nor alignment required
+    //
+    static char _UpBuffer  [SEGGER_SYSVIEW_RTT_BUFFER_SIZE];
+    #if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1)
+      static char _DownBuffer[8];  // Small, fixed-size buffer, for back-channel comms
+    #endif
+  #endif
+#endif
+
+static SEGGER_SYSVIEW_GLOBALS _SYSVIEW_Globals;
+
+static SEGGER_SYSVIEW_MODULE* _pFirstModule;
+static U8                     _NumModules;
+
+/*********************************************************************
+*
+*       Static code
+*
+**********************************************************************
+*/
+
+#define ENCODE_U32(pDest, Value) {                                                  \
+                                   U8* pSysviewPointer;                             \
+                                   U32 SysViewData;                                 \
+                                   pSysviewPointer = pDest;                         \
+                                   SysViewData = Value;                             \
+                                   while(SysViewData > 0x7F) {                      \
+                                     *pSysviewPointer++ = (U8)(SysViewData | 0x80); \
+                                     SysViewData >>= 7;                             \
+                                   };                                               \
+                                   *pSysviewPointer++ = (U8)SysViewData;            \
+                                   pDest = pSysviewPointer;                         \
+                                 };
+
+
+
+#if (SEGGER_SYSVIEW_USE_STATIC_BUFFER == 1)
+static U8 _aPacket[SEGGER_SYSVIEW_MAX_PACKET_SIZE];
+
+#define RECORD_START(PacketSize)  SEGGER_SYSVIEW_LOCK();                            \
+                                  pPayloadStart = _PreparePacket(_aPacket);
+
+#define RECORD_END()              SEGGER_SYSVIEW_UNLOCK()
+
+#else
+
+#define RECORD_START(PacketSize)  U8 aPacket[(PacketSize)];                         \
+                                  pPayloadStart = _PreparePacket(aPacket);          \
+
+#define RECORD_END()
+
+#endif
+
+/*********************************************************************
+*
+*       _EncodeData()
+*
+*  Function description
+*    Encode a byte buffer in variable-length format.
+*
+*  Parameters
+*    pPayload - Pointer to where string will be encoded.
+*    pSrc     - Pointer to data buffer to be encoded.
+*    NumBytes - Number of bytes in the buffer to be encoded.
+*
+*  Return value
+*    Pointer to the byte following the value, i.e. the first free
+*    byte in the payload and the next position to store payload
+*    content.
+*
+*  Additional information
+*    The data is encoded as a count byte followed by the contents
+*    of the data buffer.
+*    Make sure NumBytes + 1 bytes are free for the payload.
+*/
+static U8* _EncodeData(U8* pPayload, const char* pSrc, unsigned int NumBytes) {
+  unsigned int  n;
+  const U8*     p;
+  //
+  n = 0;
+  p = (const U8*)pSrc;
+  //
+  // Write Len
+  //
+  if (NumBytes < 255)  {
+    *pPayload++ = (U8)NumBytes;
+  } else {
+    *pPayload++ = 255;
+    *pPayload++ = (NumBytes & 255);
+    *pPayload++ = ((NumBytes >> 8) & 255);
+  }
+  while (n < NumBytes) {
+    *pPayload++ = *p++;
+    n++;
+  }
+  return pPayload;
+}
+
+/*********************************************************************
+*
+*       _EncodeStr()
+*
+*  Function description
+*    Encode a string in variable-length format.
+*
+*  Parameters
+*    pPayload - Pointer to where string will be encoded.
+*    pText    - String to encode.
+*    Limit    - Maximum number of characters to encode from string.
+*
+*  Return value
+*    Pointer to the byte following the value, i.e. the first free
+*    byte in the payload and the next position to store payload
+*    content.
+*
+*  Additional information
+*    The string is encoded as a count byte followed by the contents
+*    of the string.
+*    No more than 1 + Limit bytes will be encoded to the payload.
+*/
+static U8 *_EncodeStr(U8 *pPayload, const char *pText, unsigned int Limit) {
+  unsigned int n;
+  unsigned int Len;
+  //
+  // Compute string len
+  //
+  Len = 0;
+  if (pText != NULL) {
+    while(*(pText + Len) != 0) {
+      Len++;
+    }
+    if (Len > Limit) {
+      Len = Limit;
+    }
+  }
+  //
+  // Write Len
+  //
+  if (Len < 255)  {
+    *pPayload++ = (U8)Len;
+  } else {
+    *pPayload++ = 255;
+    *pPayload++ = (Len & 255);
+    *pPayload++ = ((Len >> 8) & 255);
+  }
+  //
+  // copy string
+  //
+  n = 0;
+  while (n < Len) {
+    *pPayload++ = *pText++;
+    n++;
+  }
+  return pPayload;
+}
+
+/*********************************************************************
+*
+*       _PreparePacket()
+*
+*  Function description
+*    Prepare a SystemView event packet header.
+*
+*  Parameters
+*    pPacket - Pointer to start of packet to initialize.
+*
+*  Return value
+*    Pointer to first byte of packet payload.
+*
+*  Additional information
+*    The payload length and evnetId are not initialized.
+*    PreparePacket only reserves space for them and they are
+*    computed and filled in by the sending function.
+*/
+static U8* _PreparePacket(U8* pPacket) {
+  return pPacket + _MAX_ID_BYTES + _MAX_DATA_BYTES;
+}
+
+/*********************************************************************
+*
+*       _HandleIncomingPacket()
+*
+*  Function description
+*    Read an incoming command from the down channel and process it.
+*
+*  Additional information
+*    This function is called each time after sending a packet.
+*    Processing incoming packets is done asynchronous. SystemView might
+*    already have sent event packets after the host has sent a command.
+*/
+#if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1)
+static void _HandleIncomingPacket(void) {
+  U8  Cmd;
+  unsigned int Status;
+  //
+  Status = SEGGER_RTT_ReadNoLock(CHANNEL_ID_DOWN, &Cmd, 1);
+  if (Status > 0) {
+    switch (Cmd) {
+    case SEGGER_SYSVIEW_COMMAND_ID_START:
+      SEGGER_SYSVIEW_Start();
+      break;
+    case SEGGER_SYSVIEW_COMMAND_ID_STOP:
+      SEGGER_SYSVIEW_Stop();
+      break;
+    case SEGGER_SYSVIEW_COMMAND_ID_GET_SYSTIME:
+      SEGGER_SYSVIEW_RecordSystime();
+      break;
+    case SEGGER_SYSVIEW_COMMAND_ID_GET_TASKLIST:
+      SEGGER_SYSVIEW_SendTaskList();
+      break;
+    case SEGGER_SYSVIEW_COMMAND_ID_GET_SYSDESC:
+      SEGGER_SYSVIEW_GetSysDesc();
+      break;
+    case SEGGER_SYSVIEW_COMMAND_ID_GET_NUMMODULES:
+      SEGGER_SYSVIEW_SendNumModules();
+      break;
+    case SEGGER_SYSVIEW_COMMAND_ID_GET_MODULEDESC:
+      SEGGER_SYSVIEW_SendModuleDescription();
+      break;
+    case SEGGER_SYSVIEW_COMMAND_ID_GET_MODULE:
+      Status = SEGGER_RTT_ReadNoLock(CHANNEL_ID_DOWN, &Cmd, 1);
+      if (Status > 0) {
+        SEGGER_SYSVIEW_SendModule(Cmd);
+      }
+      break;
+    case SEGGER_SYSVIEW_COMMAND_ID_HEARTBEAT:
+      break;
+    default:
+      if (Cmd >= 128) { // Unknown extended command. Dummy read its parameter.
+        SEGGER_RTT_ReadNoLock(CHANNEL_ID_DOWN, &Cmd, 1);
+      }
+      break;
+    }
+  }
+}
+#endif // (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1)
+
+/*********************************************************************
+*
+*       _TrySendOverflowPacket()
+*
+*  Function description
+*    Try to transmit an SystemView Overflow packet containing the
+*    number of dropped packets.
+*
+*  Additional information
+*    Format as follows:
+*      01 <DropCnt><TimeStamp>  Max. packet len is 1 + 5 + 5 = 11
+*
+*    Example packets sent
+*      01 20 40
+*
+*  Return value
+*    !=0:  Success, Message sent (stored in RTT-Buffer)
+*    ==0:  Buffer full, Message *NOT* stored
+*
+*/
+#if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1)
+static int _TrySendOverflowPacket(void) {
+  U32 TimeStamp;
+  I32 Delta;
+  int Status;
+  U8  aPacket[11];
+  U8* pPayload;
+
+  aPacket[0] = SYSVIEW_EVTID_OVERFLOW;      // 1
+  pPayload   = &aPacket[1];
+  ENCODE_U32(pPayload, _SYSVIEW_Globals.DropCount);
+  //
+  // Compute time stamp delta and append it to packet.
+  //
+  TimeStamp  = SEGGER_SYSVIEW_GET_TIMESTAMP();
+  Delta = TimeStamp - _SYSVIEW_Globals.LastTxTimeStamp;
+  MAKE_DELTA_32BIT(Delta);
+  ENCODE_U32(pPayload, Delta);
+  //
+  // Try to store packet in RTT buffer and update time stamp when this was successful
+  //
+  Status = (int)SEGGER_RTT_WriteSkipNoLock(CHANNEL_ID_UP, aPacket, (unsigned int)(pPayload - aPacket));
+  SEGGER_SYSVIEW_ON_EVENT_RECORDED(pPayload - aPacket);
+  if (Status) {
+    _SYSVIEW_Globals.LastTxTimeStamp = TimeStamp;
+    _SYSVIEW_Globals.EnableState--; // EnableState has been 2, will be 1. Always.
+  } else {
+    _SYSVIEW_Globals.DropCount++;
+  }
+  //
+  return Status;
+}
+#endif  // (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1)
+
+/*********************************************************************
+*
+*       _SendSyncInfo()
+*
+*  Function description
+*    Send SystemView sync packet and system information in
+*    post mortem mode.
+*
+*  Additional information
+*    Sync is 10 * 0x00 without timestamp
+*/
+#if (SEGGER_SYSVIEW_POST_MORTEM_MODE == 1)
+static void _SendSyncInfo(void) {
+  //
+  // Add sync packet ( 10 * 0x00)
+  // Send system description
+  // Send system time
+  // Send task list
+  // Send module description
+  // Send module information
+  //
+  SEGGER_RTT_WriteWithOverwriteNoLock(CHANNEL_ID_UP, _abSync, 10);
+  SEGGER_SYSVIEW_ON_EVENT_RECORDED(10);
+  SEGGER_SYSVIEW_RecordVoid(SYSVIEW_EVTID_TRACE_START);
+  {
+    U8* pPayload;
+    U8* pPayloadStart;
+    RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 4 * SEGGER_SYSVIEW_QUANTA_U32);
+    //
+    pPayload = pPayloadStart;
+    ENCODE_U32(pPayload, _SYSVIEW_Globals.SysFreq);
+    ENCODE_U32(pPayload, _SYSVIEW_Globals.CPUFreq);
+    ENCODE_U32(pPayload, _SYSVIEW_Globals.RAMBaseAddress);
+    ENCODE_U32(pPayload, SEGGER_SYSVIEW_ID_SHIFT);
+    _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_INIT);
+    RECORD_END();
+  }
+  if (_SYSVIEW_Globals.pfSendSysDesc) {
+    _SYSVIEW_Globals.pfSendSysDesc();
+  }
+  SEGGER_SYSVIEW_RecordSystime();
+  SEGGER_SYSVIEW_SendTaskList();
+  if (_NumModules > 0) {
+    int n;
+    SEGGER_SYSVIEW_SendNumModules();
+    for (n = 0; n < _NumModules; n++) {
+      SEGGER_SYSVIEW_SendModule(n);
+    }
+    SEGGER_SYSVIEW_SendModuleDescription();
+  }
+}
+#endif  // (SEGGER_SYSVIEW_POST_MORTEM_MODE == 1)
+
+/*********************************************************************
+*
+*       _SendPacket()
+*
+*  Function description
+*    Send a SystemView packet over RTT. RTT channel and mode are
+*    configured by macros when the SystemView component is initialized.
+*    This function takes care of maintaining the packet drop count
+*    and sending overflow packets when necessary.
+*    The packet must be passed without Id and Length because this
+*    function prepends it to the packet before transmission.
+*
+*  Parameters
+*    pStartPacket - Pointer to start of packet payload.
+*                   There must be at least 4 bytes free to prepend Id and Length.
+*    pEndPacket   - Pointer to end of packet payload.
+*    EventId      - Id of the event to send.
+*
+*/
+static void _SendPacket(U8* pStartPacket, U8* pEndPacket, unsigned int EventId) {
+  unsigned int  NumBytes;
+  U32           TimeStamp;
+  U32           Delta;
+#if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1)
+  unsigned int  Status;
+#endif
+
+#if (SEGGER_SYSVIEW_USE_STATIC_BUFFER == 0)
+  SEGGER_SYSVIEW_LOCK();
+#endif
+
+#if (SEGGER_SYSVIEW_POST_MORTEM_MODE == 1)
+  if (_SYSVIEW_Globals.EnableState == 0) {
+    goto SendDone;
+  }
+#else
+  if (_SYSVIEW_Globals.EnableState == 1) {  // Enabled, no dropped packets remaining
+    goto Send;
+  }
+  if (_SYSVIEW_Globals.EnableState == 0) {
+    goto SendDone;
+  }
+  //
+  // Handle buffer full situations:
+  // Have packets been dropped before because buffer was full?
+  // In this case try to send and overflow packet.
+  //
+  if (_SYSVIEW_Globals.EnableState == 2) {
+    _TrySendOverflowPacket();
+    if (_SYSVIEW_Globals.EnableState != 1) {
+      goto SendDone;
+    }
+  }
+Send:
+#endif
+  //
+  // Check if event is disabled from being recorded.
+  //
+  if (EventId < 32) {
+    if (_SYSVIEW_Globals.DisabledEvents & ((U32)1u << EventId)) {
+      goto SendDone;
+    }
+  }
+  //
+  // Prepare actual packet.
+  // If it is a known packet, prepend eventId only,
+  // otherwise prepend packet length and eventId.
+  //
+  if (EventId < 24) {
+    *--pStartPacket = (U8)EventId;
+  } else {
+    //
+    // Get data length and prepend it.
+    //
+    NumBytes = (unsigned int)(pEndPacket - pStartPacket);
+#if SEGGER_SYSVIEW_SUPPORT_LONG_DATA
+    if (NumBytes < 127) {
+      *--pStartPacket = EventId;
+    } else {
+      //
+      // Backwards U32 encode EventId.
+      //
+      if (NumBytes < (1u << 14)) { // Encodes in 2 bytes
+        *--pStartPacket = (U8)(NumBytes >>  7);
+        *--pStartPacket = (U8)(NumBytes | 0x80);
+      } else if (NumBytes < (1u << 21)) {    // Encodes in 3 bytes
+        *--pStartPacket = (U8)(NumBytes >> 14);
+        *--pStartPacket = (U8)((NumBytes >>  7) | 0x80);
+        *--pStartPacket = (U8)(NumBytes | 0x80);
+      } else if (NumBytes < (1u << 28)) {    // Encodes in 4 bytes
+        *--pStartPacket = (U8)(NumBytes >> 21);
+        *--pStartPacket = (U8)((NumBytes >> 14) | 0x80);
+        *--pStartPacket = (U8)((NumBytes >>  7) | 0x80);
+        *--pStartPacket = (U8)(NumBytes | 0x80);
+      } else {                              // Encodes in 5 bytes
+        *--pStartPacket = (U8)(NumBytes >> 28);
+        *--pStartPacket = (U8)((NumBytes >> 21) | 0x80);
+        *--pStartPacket = (U8)((NumBytes >> 14) | 0x80);
+        *--pStartPacket = (U8)((NumBytes >>  7) | 0x80);
+        *--pStartPacket = (U8)(NumBytes | 0x80);
+      }
+    }
+#else
+    if (NumBytes > 127) {
+      *--pStartPacket = (U8)(NumBytes >> 7);
+      *--pStartPacket = (U8)(NumBytes | 0x80);
+    } else {
+      *--pStartPacket = (U8)NumBytes;
+    }
+#endif
+    //
+    // Prepend EventId.
+    //
+#if SEGGER_SYSVIEW_SUPPORT_LONG_ID
+    if (EventId < 127) {
+      *--pStartPacket = (U8)EventId;
+    } else {
+      //
+      // Backwards U32 encode EventId.
+      //
+      if (EventId < (1u << 14)) { // Encodes in 2 bytes
+        *--pStartPacket = (U8)(EventId >>  7);
+        *--pStartPacket = (U8)(EventId | 0x80);
+      } else if (EventId < (1u << 21)) {    // Encodes in 3 bytes
+        *--pStartPacket = (U8)(EventId >> 14);
+        *--pStartPacket = (U8)((EventId >>  7) | 0x80);
+        *--pStartPacket = (U8)(EventId | 0x80);
+      } else if (EventId < (1u << 28)) {    // Encodes in 4 bytes
+        *--pStartPacket = (U8)(EventId >> 21);
+        *--pStartPacket = (U8)((EventId >> 14) | 0x80);
+        *--pStartPacket = (U8)((EventId >>  7) | 0x80);
+        *--pStartPacket = (U8)(EventId | 0x80);
+      } else {                              // Encodes in 5 bytes
+        *--pStartPacket = (U8)(EventId >> 28);
+        *--pStartPacket = (U8)((EventId >> 21) | 0x80);
+        *--pStartPacket = (U8)((EventId >> 14) | 0x80);
+        *--pStartPacket = (U8)((EventId >>  7) | 0x80);
+        *--pStartPacket = (U8)(EventId | 0x80);
+      }
+    }
+#else
+    if (EventId > 127) {
+      *--pStartPacket = (U8)(EventId >> 7);
+      *--pStartPacket = (U8)(EventId | 0x80);
+    } else {
+      *--pStartPacket = (U8)EventId;
+    }
+#endif
+  }
+  //
+  // Compute time stamp delta and append it to packet.
+  //
+  TimeStamp  = SEGGER_SYSVIEW_GET_TIMESTAMP();
+  Delta = TimeStamp - _SYSVIEW_Globals.LastTxTimeStamp;
+  MAKE_DELTA_32BIT(Delta);
+  ENCODE_U32(pEndPacket, Delta);
+#if (SEGGER_SYSVIEW_POST_MORTEM_MODE == 1)
+  //
+  // Store packet in RTT buffer by overwriting old data and update time stamp
+  //
+  SEGGER_RTT_WriteWithOverwriteNoLock(CHANNEL_ID_UP, pStartPacket, pEndPacket - pStartPacket);
+  SEGGER_SYSVIEW_ON_EVENT_RECORDED(pEndPacket - pStartPacket);
+  _SYSVIEW_Globals.LastTxTimeStamp = TimeStamp;
+#else
+  //
+  // Try to store packet in RTT buffer and update time stamp when this was successful
+  //
+  Status = SEGGER_RTT_WriteSkipNoLock(CHANNEL_ID_UP, pStartPacket, (unsigned int)(pEndPacket - pStartPacket));
+  SEGGER_SYSVIEW_ON_EVENT_RECORDED(pEndPacket - pStartPacket);
+  if (Status) {
+    _SYSVIEW_Globals.LastTxTimeStamp = TimeStamp;
+  } else {
+    _SYSVIEW_Globals.EnableState++; // EnableState has been 1, will be 2. Always.
+  }
+#endif
+
+#if (SEGGER_SYSVIEW_POST_MORTEM_MODE == 1)
+  //
+  // Add sync and system information periodically if we are in post mortem mode
+  //
+  if (_SYSVIEW_Globals.RecursionCnt == 0) {   // Avoid uncontrolled nesting. This way, this routine can call itself once, but no more often than that.
+    _SYSVIEW_Globals.RecursionCnt = 1;
+    if (_SYSVIEW_Globals.PacketCount++ & (1 << SEGGER_SYSVIEW_SYNC_PERIOD_SHIFT)) {
+      _SendSyncInfo();
+      _SYSVIEW_Globals.PacketCount = 0;
+    }
+    _SYSVIEW_Globals.RecursionCnt = 0;
+  }
+SendDone:
+  ; // Avoid "label at end of compound statement" error when using static buffer
+#else
+SendDone:
+  //
+  // Check if host is sending data which needs to be processed.
+  // Note that since this code is called for every packet, it is very time critical, so we do
+  // only what is really needed here, which is checking if there is any data
+  //
+  if (SEGGER_RTT_HASDATA(CHANNEL_ID_DOWN)) {
+    if (_SYSVIEW_Globals.RecursionCnt == 0) {   // Avoid uncontrolled nesting. This way, this routine can call itself once, but no more often than that.
+      _SYSVIEW_Globals.RecursionCnt = 1;
+      _HandleIncomingPacket();
+      _SYSVIEW_Globals.RecursionCnt = 0;
+    }
+  }
+#endif
+  //
+#if (SEGGER_SYSVIEW_USE_STATIC_BUFFER == 0)
+  SEGGER_SYSVIEW_UNLOCK();  // We are done. Unlock and return
+#endif
+}
+
+#ifndef SEGGER_SYSVIEW_EXCLUDE_PRINTF // Define in project to avoid warnings about variable parameter list
+/*********************************************************************
+*
+*       _VPrintHost()
+*
+*  Function description
+*    Send a format string and its parameters to the host.
+*
+*  Parameters
+*    s            Pointer to format string.
+*    Options      Options to be sent to the host.
+*    pParamList   Pointer to the list of arguments for the format string.
+*/
+static int _VPrintHost(const char* s, U32 Options, va_list* pParamList) {
+  U32         aParas[SEGGER_SYSVIEW_MAX_ARGUMENTS];
+  U32*        pParas;
+  U32         NumArguments;
+  const char* p;
+  char        c;
+  U8*         pPayload;
+  U8*         pPayloadStart;
+#if SEGGER_SYSVIEW_PRINTF_IMPLICIT_FORMAT
+  U8 HasNonScalar;
+
+  HasNonScalar = 0;
+#endif
+  //
+  // Count number of arguments by counting '%' characters in string.
+  // If enabled, check for non-scalar modifier flags to format string on the target.
+  //
+  p = s;
+  NumArguments = 0;
+  for (;;) {
+    c = *p++;
+    if (c == 0) {
+      break;
+    }
+    if (c == '%') {
+      c = *p;
+#if SEGGER_SYSVIEW_PRINTF_IMPLICIT_FORMAT == 0
+      aParas[NumArguments++] = (U32)(va_arg(*pParamList, int));
+      if (NumArguments == SEGGER_SYSVIEW_MAX_ARGUMENTS) {
+        break;
+      }
+#else
+      if (c == 's') {
+        HasNonScalar = 1;
+        break;
+      } else {
+        aParas[NumArguments++] = (U32)(va_arg(*pParamList, int));
+        if (NumArguments == SEGGER_SYSVIEW_MAX_ARGUMENTS) {
+          break;
+        }
+      }
+#endif
+    }
+  }
+
+#if SEGGER_SYSVIEW_PRINTF_IMPLICIT_FORMAT
+  if (HasNonScalar) {
+    return -1;
+  }
+#endif
+  //
+  // Send string and parameters to host
+  //
+  {
+    RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_MAX_STRING_LEN + 2 * SEGGER_SYSVIEW_QUANTA_U32 + SEGGER_SYSVIEW_MAX_ARGUMENTS * SEGGER_SYSVIEW_QUANTA_U32);
+    pPayload = _EncodeStr(pPayloadStart, s, SEGGER_SYSVIEW_MAX_STRING_LEN);
+    ENCODE_U32(pPayload, Options);
+    ENCODE_U32(pPayload, NumArguments);
+    pParas = aParas;
+    while (NumArguments--) {
+      ENCODE_U32(pPayload, (*pParas));
+      pParas++;
+    }
+    _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_PRINT_FORMATTED);
+    RECORD_END();
+  }
+  return 0;
+}
+
+/*********************************************************************
+*
+*       _StoreChar()
+*
+*  Function description
+*    Stores a character in the printf-buffer and sends the buffer when
+*     it is filled.
+*
+*  Parameters
+*    p            Pointer to the buffer description.
+*    c            Character to be printed.
+*/
+static void _StoreChar(SEGGER_SYSVIEW_PRINTF_DESC * p, char c) {
+  unsigned int  Cnt;
+  U8*           pPayload;
+  U32           Options;
+
+  Cnt = p->Cnt;
+  if ((Cnt + 1u) <= SEGGER_SYSVIEW_MAX_STRING_LEN) {
+    *(p->pPayload++) = (U8)c;
+    p->Cnt = Cnt + 1u;
+  }
+  //
+  // Write part of string, when the buffer is full
+  //
+  if (p->Cnt == SEGGER_SYSVIEW_MAX_STRING_LEN) {
+    *(p->pPayloadStart) = (U8)p->Cnt;
+    pPayload = p->pPayload;
+    Options = p->Options;
+    ENCODE_U32(pPayload, Options);
+    ENCODE_U32(pPayload, 0);
+    _SendPacket(p->pPayloadStart, pPayload, SYSVIEW_EVTID_PRINT_FORMATTED);
+    p->pPayloadStart = _PreparePacket(p->pBuffer);
+    p->pPayload = p->pPayloadStart + 1u;
+    p->Cnt = 0u;
+  }
+}
+
+/*********************************************************************
+*
+*       _PrintUnsigned()
+*
+*  Function description
+*    Print an unsigned integer with the given formatting into the
+*     formatted string.
+*
+*  Parameters
+*    pBufferDesc  Pointer to the buffer description.
+*    v            Value to be printed.
+*    Base         Base of the value.
+*    NumDigits    Number of digits to be printed.
+*    FieldWidth   Width of the printed field.
+*    FormatFlags  Flags for formatting the value.
+*/
+static void _PrintUnsigned(SEGGER_SYSVIEW_PRINTF_DESC * pBufferDesc, unsigned int v, unsigned int Base, unsigned int NumDigits, unsigned int FieldWidth, unsigned int FormatFlags) {
+  static const char _aV2C[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
+  unsigned int      Div;
+  unsigned int      Digit;
+  unsigned int      Number;
+  unsigned int      Width;
+  char              c;
+
+  Number = v;
+  Digit = 1u;
+  //
+  // Get actual field width
+  //
+  Width = 1u;
+  while (Number >= Base) {
+    Number = (Number / Base);
+    Width++;
+  }
+  if (NumDigits > Width) {
+    Width = NumDigits;
+  }
+  //
+  // Print leading chars if necessary
+  //
+  if ((FormatFlags & FORMAT_FLAG_LEFT_JUSTIFY) == 0u) {
+    if (FieldWidth != 0u) {
+      if (((FormatFlags & FORMAT_FLAG_PAD_ZERO) == FORMAT_FLAG_PAD_ZERO) && (NumDigits == 0u)) {
+        c = '0';
+      } else {
+        c = ' ';
+      }
+      while ((FieldWidth != 0u) && (Width < FieldWidth)) {
+        FieldWidth--;
+        _StoreChar(pBufferDesc, c);
+      }
+    }
+  }
+  //
+  // Compute Digit.
+  // Loop until Digit has the value of the highest digit required.
+  // Example: If the output is 345 (Base 10), loop 2 times until Digit is 100.
+  //
+  while (1) {
+    if (NumDigits > 1u) {       // User specified a min number of digits to print? => Make sure we loop at least that often, before checking anything else (> 1 check avoids problems with NumDigits being signed / unsigned)
+      NumDigits--;
+    } else {
+      Div = v / Digit;
+      if (Div < Base) {        // Is our divider big enough to extract the highest digit from value? => Done
+        break;
+      }
+    }
+    Digit *= Base;
+  }
+  //
+  // Output digits
+  //
+  do {
+    Div = v / Digit;
+    v -= Div * Digit;
+    _StoreChar(pBufferDesc, _aV2C[Div]);
+    Digit /= Base;
+  } while (Digit);
+  //
+  // Print trailing spaces if necessary
+  //
+  if ((FormatFlags & FORMAT_FLAG_LEFT_JUSTIFY) == FORMAT_FLAG_LEFT_JUSTIFY) {
+    if (FieldWidth != 0u) {
+      while ((FieldWidth != 0u) && (Width < FieldWidth)) {
+        FieldWidth--;
+        _StoreChar(pBufferDesc, ' ');
+      }
+    }
+  }
+}
+
+/*********************************************************************
+*
+*       _PrintInt()
+*
+*  Function description
+*    Print a signed integer with the given formatting into the
+*     formatted string.
+*
+*  Parameters
+*    pBufferDesc  Pointer to the buffer description.
+*    v            Value to be printed.
+*    Base         Base of the value.
+*    NumDigits    Number of digits to be printed.
+*    FieldWidth   Width of the printed field.
+*    FormatFlags  Flags for formatting the value.
+*/
+static void _PrintInt(SEGGER_SYSVIEW_PRINTF_DESC * pBufferDesc, int v, unsigned int Base, unsigned int NumDigits, unsigned int FieldWidth, unsigned int FormatFlags) {
+  unsigned int  Width;
+  int           Number;
+
+  Number = (v < 0) ? -v : v;
+
+  //
+  // Get actual field width
+  //
+  Width = 1u;
+  while (Number >= (int)Base) {
+    Number = (Number / (int)Base);
+    Width++;
+  }
+  if (NumDigits > Width) {
+    Width = NumDigits;
+  }
+  if ((FieldWidth > 0u) && ((v < 0) || ((FormatFlags & FORMAT_FLAG_PRINT_SIGN) == FORMAT_FLAG_PRINT_SIGN))) {
+    FieldWidth--;
+  }
+
+  //
+  // Print leading spaces if necessary
+  //
+  if ((((FormatFlags & FORMAT_FLAG_PAD_ZERO) == 0u) || (NumDigits != 0u)) && ((FormatFlags & FORMAT_FLAG_LEFT_JUSTIFY) == 0u)) {
+    if (FieldWidth != 0u) {
+      while ((FieldWidth != 0u) && (Width < FieldWidth)) {
+        FieldWidth--;
+        _StoreChar(pBufferDesc, ' ');
+      }
+    }
+  }
+  //
+  // Print sign if necessary
+  //
+  if (v < 0) {
+    v = -v;
+    _StoreChar(pBufferDesc, '-');
+  } else if ((FormatFlags & FORMAT_FLAG_PRINT_SIGN) == FORMAT_FLAG_PRINT_SIGN) {
+    _StoreChar(pBufferDesc, '+');
+  } else {
+
+  }
+  //
+  // Print leading zeros if necessary
+  //
+  if (((FormatFlags & FORMAT_FLAG_PAD_ZERO) == FORMAT_FLAG_PAD_ZERO) && ((FormatFlags & FORMAT_FLAG_LEFT_JUSTIFY) == 0u) && (NumDigits == 0u)) {
+    if (FieldWidth != 0u) {
+      while ((FieldWidth != 0u) && (Width < FieldWidth)) {
+        FieldWidth--;
+        _StoreChar(pBufferDesc, '0');
+      }
+    }
+  }
+  //
+  // Print number without sign
+  //
+  _PrintUnsigned(pBufferDesc, (unsigned int)v, Base, NumDigits, FieldWidth, FormatFlags);
+}
+
+/*********************************************************************
+*
+*       _VPrintTarget()
+*
+*  Function description
+*    Stores a formatted string.
+*    This data is read by the host.
+*
+*  Parameters
+*    sFormat      Pointer to format string.
+*    Options      Options to be sent to the host.
+*    pParamList   Pointer to the list of arguments for the format string.
+*/
+static void _VPrintTarget(const char* sFormat, U32 Options, va_list* pParamList) {
+  SEGGER_SYSVIEW_PRINTF_DESC BufferDesc;
+  char          c;
+  int           v;
+  unsigned int  NumDigits;
+  unsigned int  FormatFlags;
+  unsigned int  FieldWidth;
+  U8*           pPayloadStart;
+#if SEGGER_SYSVIEW_USE_STATIC_BUFFER == 0
+  RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_MAX_STRING_LEN + 1 + 2 * SEGGER_SYSVIEW_QUANTA_U32);
+  SEGGER_SYSVIEW_LOCK();
+#else
+  RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_MAX_STRING_LEN + 1 + 2 * SEGGER_SYSVIEW_QUANTA_U32);
+#endif
+
+#if SEGGER_SYSVIEW_USE_STATIC_BUFFER == 0
+  BufferDesc.pBuffer        = aPacket;
+#else
+  BufferDesc.pBuffer        = _aPacket;
+#endif
+  BufferDesc.Cnt            = 0u;
+  BufferDesc.pPayloadStart  = pPayloadStart;
+  BufferDesc.pPayload       = BufferDesc.pPayloadStart + 1u;
+  BufferDesc.Options        =  Options;
+
+  do {
+    c = *sFormat;
+    sFormat++;
+    if (c == 0u) {
+      break;
+    }
+    if (c == '%') {
+      //
+      // Filter out flags
+      //
+      FormatFlags = 0u;
+      v = 1;
+      do {
+        c = *sFormat;
+        switch (c) {
+        case '-': FormatFlags |= FORMAT_FLAG_LEFT_JUSTIFY; sFormat++; break;
+        case '0': FormatFlags |= FORMAT_FLAG_PAD_ZERO;     sFormat++; break;
+        case '+': FormatFlags |= FORMAT_FLAG_PRINT_SIGN;   sFormat++; break;
+        case '#': FormatFlags |= FORMAT_FLAG_ALTERNATE;    sFormat++; break;
+        default:  v = 0; break;
+        }
+      } while (v);
+      //
+      // filter out field with
+      //
+      FieldWidth = 0u;
+      do {
+        c = *sFormat;
+        if ((c < '0') || (c > '9')) {
+          break;
+        }
+        sFormat++;
+        FieldWidth = (FieldWidth * 10u) + ((unsigned int)c - '0');
+      } while (1);
+
+      //
+      // Filter out precision (number of digits to display)
+      //
+      NumDigits = 0u;
+      c = *sFormat;
+      if (c == '.') {
+        sFormat++;
+        do {
+          c = *sFormat;
+          if ((c < '0') || (c > '9')) {
+            break;
+          }
+          sFormat++;
+          NumDigits = NumDigits * 10u + ((unsigned int)c - '0');
+        } while (1);
+      }
+      //
+      // Filter out length modifier
+      //
+      c = *sFormat;
+      do {
+        if ((c == 'l') || (c == 'h')) {
+          c = *sFormat;
+          sFormat++;
+        } else {
+          break;
+        }
+      } while (1);
+      //
+      // Handle specifiers
+      //
+      switch (c) {
+      case 'c': {
+        char c0;
+        v = va_arg(*pParamList, int);
+        c0 = (char)v;
+        _StoreChar(&BufferDesc, c0);
+        break;
+      }
+      case 'd':
+        v = va_arg(*pParamList, int);
+        _PrintInt(&BufferDesc, v, 10u, NumDigits, FieldWidth, FormatFlags);
+        break;
+      case 'u':
+        v = va_arg(*pParamList, int);
+        _PrintUnsigned(&BufferDesc, (unsigned int)v, 10u, NumDigits, FieldWidth, FormatFlags);
+        break;
+      case 'x':
+      case 'X':
+        v = va_arg(*pParamList, int);
+        _PrintUnsigned(&BufferDesc, (unsigned int)v, 16u, NumDigits, FieldWidth, FormatFlags);
+        break;
+      case 'p':
+        v = va_arg(*pParamList, int);
+        _PrintUnsigned(&BufferDesc, (unsigned int)v, 16u, 8u, 8u, 0u);
+        break;
+      case '%':
+        _StoreChar(&BufferDesc, '%');
+        break;
+      default:
+        break;
+      }
+      sFormat++;
+    } else {
+      _StoreChar(&BufferDesc, c);
+    }
+  } while (*sFormat);
+
+  //
+  // Write remaining data, if any
+  //
+  if (BufferDesc.Cnt != 0u) {
+    *(BufferDesc.pPayloadStart) = (U8)BufferDesc.Cnt;
+    ENCODE_U32(BufferDesc.pPayload, BufferDesc.Options);
+    ENCODE_U32(BufferDesc.pPayload, 0);
+    _SendPacket(BufferDesc.pPayloadStart, BufferDesc.pPayload, SYSVIEW_EVTID_PRINT_FORMATTED);
+  }
+#if SEGGER_SYSVIEW_USE_STATIC_BUFFER == 0
+  SEGGER_SYSVIEW_UNLOCK();
+  RECORD_END();
+#else
+  RECORD_END();
+#endif
+}
+#endif // SEGGER_SYSVIEW_EXCLUDE_PRINTF
+
+/*********************************************************************
+*
+*       Public code
+*
+**********************************************************************
+*/
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_Init()
+*
+*  Function description
+*    Initializes the SYSVIEW module.
+*    Must be called before the Systemview Application connects to
+*    the system.
+*
+*  Parameters
+*    SysFreq        - Frequency of timestamp, usually CPU core clock frequency.
+*    CPUFreq        - CPU core clock frequency.
+*    pOSAPI         - Pointer to the API structure for OS-specific functions.
+*    pfSendSysDesc  - Pointer to record system description callback function.
+*
+*  Additional information
+*    This function initializes the RTT channel used to transport
+*    SEGGER SystemView packets.
+*    The channel is assigned the label "SysView" for client software
+*    to identify the SystemView channel.
+*
+*    The channel is configured with the macro SEGGER_SYSVIEW_RTT_CHANNEL.
+*/
+void SEGGER_SYSVIEW_Init(U32 SysFreq, U32 CPUFreq, const SEGGER_SYSVIEW_OS_API *pOSAPI, SEGGER_SYSVIEW_SEND_SYS_DESC_FUNC pfSendSysDesc) {
+#ifdef SEGGER_RTT_SECTION
+  //
+  // Explicitly initialize the RTT Control Block if it is in its dedicated section.
+  //
+  SEGGER_RTT_Init();
+#endif
+#if (SEGGER_SYSVIEW_POST_MORTEM_MODE == 1)
+#if SEGGER_SYSVIEW_RTT_CHANNEL > 0
+  SEGGER_RTT_ConfigUpBuffer(SEGGER_SYSVIEW_RTT_CHANNEL, "SysView", &_UpBuffer[0],   sizeof(_UpBuffer),   SEGGER_RTT_MODE_NO_BLOCK_SKIP);
+#else
+  _SYSVIEW_Globals.UpChannel = (U8)SEGGER_RTT_AllocUpBuffer  ("SysView", &_UpBuffer[0],   sizeof(_UpBuffer),   SEGGER_RTT_MODE_NO_BLOCK_SKIP);
+#endif
+  _SYSVIEW_Globals.RAMBaseAddress   = SEGGER_SYSVIEW_ID_BASE;
+  _SYSVIEW_Globals.LastTxTimeStamp  = SEGGER_SYSVIEW_GET_TIMESTAMP();
+  _SYSVIEW_Globals.pOSAPI           = pOSAPI;
+  _SYSVIEW_Globals.SysFreq          = SysFreq;
+  _SYSVIEW_Globals.CPUFreq          = CPUFreq;
+  _SYSVIEW_Globals.pfSendSysDesc    = pfSendSysDesc;
+  _SYSVIEW_Globals.EnableState      = 0;
+  _SYSVIEW_Globals.PacketCount      = 0;
+#else // (SEGGER_SYSVIEW_POST_MORTEM_MODE == 1)
+#if SEGGER_SYSVIEW_RTT_CHANNEL > 0
+  SEGGER_RTT_ConfigUpBuffer   (SEGGER_SYSVIEW_RTT_CHANNEL, "SysView", &_UpBuffer[0],   sizeof(_UpBuffer),   SEGGER_RTT_MODE_NO_BLOCK_SKIP);
+  SEGGER_RTT_ConfigDownBuffer (SEGGER_SYSVIEW_RTT_CHANNEL, "SysView", &_DownBuffer[0], sizeof(_DownBuffer), SEGGER_RTT_MODE_NO_BLOCK_SKIP);
+#else
+  _SYSVIEW_Globals.UpChannel = (U8)SEGGER_RTT_AllocUpBuffer  ("SysView", &_UpBuffer[0],   sizeof(_UpBuffer),   SEGGER_RTT_MODE_NO_BLOCK_SKIP);
+  _SYSVIEW_Globals.DownChannel = _SYSVIEW_Globals.UpChannel;
+  SEGGER_RTT_ConfigDownBuffer (_SYSVIEW_Globals.DownChannel, "SysView", &_DownBuffer[0], sizeof(_DownBuffer), SEGGER_RTT_MODE_NO_BLOCK_SKIP);
+#endif
+  _SYSVIEW_Globals.RAMBaseAddress   = SEGGER_SYSVIEW_ID_BASE;
+  _SYSVIEW_Globals.LastTxTimeStamp  = SEGGER_SYSVIEW_GET_TIMESTAMP();
+  _SYSVIEW_Globals.pOSAPI           = pOSAPI;
+  _SYSVIEW_Globals.SysFreq          = SysFreq;
+  _SYSVIEW_Globals.CPUFreq          = CPUFreq;
+  _SYSVIEW_Globals.pfSendSysDesc    = pfSendSysDesc;
+  _SYSVIEW_Globals.EnableState      = 0;
+#endif  // (SEGGER_SYSVIEW_POST_MORTEM_MODE == 1)
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_SetRAMBase()
+*
+*  Function description
+*    Sets the RAM base address, which is subtracted from IDs in order
+*     to save bandwidth.
+*
+*  Parameters
+*    RAMBaseAddress - Lowest RAM Address. (i.e. 0x20000000 on most Cortex-M)
+*/
+void SEGGER_SYSVIEW_SetRAMBase(U32 RAMBaseAddress) {
+  _SYSVIEW_Globals.RAMBaseAddress = RAMBaseAddress;
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_RecordVoid()
+*
+*  Function description
+*    Formats and sends a SystemView packet with an empty payload.
+*
+*  Parameters
+*    EventID - SystemView event ID.
+*/
+void SEGGER_SYSVIEW_RecordVoid(unsigned int EventID) {
+  U8* pPayloadStart;
+  RECORD_START(SEGGER_SYSVIEW_INFO_SIZE);
+  //
+  _SendPacket(pPayloadStart, pPayloadStart, EventID);
+  RECORD_END();
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_RecordU32()
+*
+*  Function description
+*    Formats and sends a SystemView packet containing a single U32
+*    parameter payload.
+*
+*  Parameters
+*    EventID - SystemView event ID.
+*    Value   - The 32-bit parameter encoded to SystemView packet payload.
+*/
+void SEGGER_SYSVIEW_RecordU32(unsigned int EventID, U32 Value) {
+  U8* pPayload;
+  U8* pPayloadStart;
+  RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32);
+  //
+  pPayload = pPayloadStart;
+  ENCODE_U32(pPayload, Value);
+  _SendPacket(pPayloadStart, pPayload, EventID);
+  RECORD_END();
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_RecordU32x2()
+*
+*  Function description
+*    Formats and sends a SystemView packet containing 2 U32 parameter payload.
+*
+*  Parameters
+*    EventID - SystemView event ID.
+*    Para0   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para1   - The 32-bit parameter encoded to SystemView packet payload.
+*/
+void SEGGER_SYSVIEW_RecordU32x2(unsigned int EventID, U32 Para0, U32 Para1) {
+  U8* pPayload;
+  U8* pPayloadStart;
+  RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 2 * SEGGER_SYSVIEW_QUANTA_U32);
+  //
+  pPayload = pPayloadStart;
+  ENCODE_U32(pPayload, Para0);
+  ENCODE_U32(pPayload, Para1);
+  _SendPacket(pPayloadStart, pPayload, EventID);
+  RECORD_END();
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_RecordU32x3()
+*
+*  Function description
+*    Formats and sends a SystemView packet containing 3 U32 parameter payload.
+*
+*  Parameters
+*    EventID - SystemView event ID.
+*    Para0   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para1   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para2   - The 32-bit parameter encoded to SystemView packet payload.
+*/
+void SEGGER_SYSVIEW_RecordU32x3(unsigned int EventID, U32 Para0, U32 Para1, U32 Para2) {
+  U8* pPayload;
+  U8* pPayloadStart;
+  RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 3 * SEGGER_SYSVIEW_QUANTA_U32);
+  //
+  pPayload = pPayloadStart;
+  ENCODE_U32(pPayload, Para0);
+  ENCODE_U32(pPayload, Para1);
+  ENCODE_U32(pPayload, Para2);
+  _SendPacket(pPayloadStart, pPayload, EventID);
+  RECORD_END();
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_RecordU32x4()
+*
+*  Function description
+*    Formats and sends a SystemView packet containing 4 U32 parameter payload.
+*
+*  Parameters
+*    EventID - SystemView event ID.
+*    Para0   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para1   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para2   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para3   - The 32-bit parameter encoded to SystemView packet payload.
+*/
+void SEGGER_SYSVIEW_RecordU32x4(unsigned int EventID, U32 Para0, U32 Para1, U32 Para2, U32 Para3) {
+  U8* pPayload;
+  U8* pPayloadStart;
+  RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 4 * SEGGER_SYSVIEW_QUANTA_U32);
+  //
+  pPayload = pPayloadStart;
+  ENCODE_U32(pPayload, Para0);
+  ENCODE_U32(pPayload, Para1);
+  ENCODE_U32(pPayload, Para2);
+  ENCODE_U32(pPayload, Para3);
+  _SendPacket(pPayloadStart, pPayload, EventID);
+  RECORD_END();
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_RecordU32x5()
+*
+*  Function description
+*    Formats and sends a SystemView packet containing 5 U32 parameter payload.
+*
+*  Parameters
+*    EventID - SystemView event ID.
+*    Para0   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para1   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para2   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para3   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para4   - The 32-bit parameter encoded to SystemView packet payload.
+*/
+void SEGGER_SYSVIEW_RecordU32x5(unsigned int EventID, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4) {
+  U8* pPayload;
+  U8* pPayloadStart;
+  RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 5 * SEGGER_SYSVIEW_QUANTA_U32);
+  //
+  pPayload = pPayloadStart;
+  ENCODE_U32(pPayload, Para0);
+  ENCODE_U32(pPayload, Para1);
+  ENCODE_U32(pPayload, Para2);
+  ENCODE_U32(pPayload, Para3);
+  ENCODE_U32(pPayload, Para4);
+  _SendPacket(pPayloadStart, pPayload, EventID);
+  RECORD_END();
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_RecordU32x6()
+*
+*  Function description
+*    Formats and sends a SystemView packet containing 6 U32 parameter payload.
+*
+*  Parameters
+*    EventID - SystemView event ID.
+*    Para0   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para1   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para2   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para3   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para4   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para5   - The 32-bit parameter encoded to SystemView packet payload.
+*/
+void SEGGER_SYSVIEW_RecordU32x6(unsigned int EventID, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4, U32 Para5) {
+  U8* pPayload;
+  U8* pPayloadStart;
+  RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 6 * SEGGER_SYSVIEW_QUANTA_U32);
+  //
+  pPayload = pPayloadStart;
+  ENCODE_U32(pPayload, Para0);
+  ENCODE_U32(pPayload, Para1);
+  ENCODE_U32(pPayload, Para2);
+  ENCODE_U32(pPayload, Para3);
+  ENCODE_U32(pPayload, Para4);
+  ENCODE_U32(pPayload, Para5);
+  _SendPacket(pPayloadStart, pPayload, EventID);
+  RECORD_END();
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_RecordU32x7()
+*
+*  Function description
+*    Formats and sends a SystemView packet containing 7 U32 parameter payload.
+*
+*  Parameters
+*    EventID - SystemView event ID.
+*    Para0   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para1   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para2   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para3   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para4   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para5   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para6   - The 32-bit parameter encoded to SystemView packet payload.
+*/
+void SEGGER_SYSVIEW_RecordU32x7(unsigned int EventID, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4, U32 Para5, U32 Para6) {
+  U8* pPayload;
+  U8* pPayloadStart;
+  RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 7 * SEGGER_SYSVIEW_QUANTA_U32);
+  //
+  pPayload = pPayloadStart;
+  ENCODE_U32(pPayload, Para0);
+  ENCODE_U32(pPayload, Para1);
+  ENCODE_U32(pPayload, Para2);
+  ENCODE_U32(pPayload, Para3);
+  ENCODE_U32(pPayload, Para4);
+  ENCODE_U32(pPayload, Para5);
+  ENCODE_U32(pPayload, Para6);
+  _SendPacket(pPayloadStart, pPayload, EventID);
+  RECORD_END();
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_RecordU32x8()
+*
+*  Function description
+*    Formats and sends a SystemView packet containing 8 U32 parameter payload.
+*
+*  Parameters
+*    EventID - SystemView event ID.
+*    Para0   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para1   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para2   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para3   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para4   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para5   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para6   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para7   - The 32-bit parameter encoded to SystemView packet payload.
+*/
+void SEGGER_SYSVIEW_RecordU32x8(unsigned int EventID, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4, U32 Para5, U32 Para6, U32 Para7) {
+  U8* pPayload;
+  U8* pPayloadStart;
+  RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 8 * SEGGER_SYSVIEW_QUANTA_U32);
+  //
+  pPayload = pPayloadStart;
+  ENCODE_U32(pPayload, Para0);
+  ENCODE_U32(pPayload, Para1);
+  ENCODE_U32(pPayload, Para2);
+  ENCODE_U32(pPayload, Para3);
+  ENCODE_U32(pPayload, Para4);
+  ENCODE_U32(pPayload, Para5);
+  ENCODE_U32(pPayload, Para6);
+  ENCODE_U32(pPayload, Para7);
+  _SendPacket(pPayloadStart, pPayload, EventID);
+  RECORD_END();
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_RecordU32x9()
+*
+*  Function description
+*    Formats and sends a SystemView packet containing 9 U32 parameter payload.
+*
+*  Parameters
+*    EventID - SystemView event ID.
+*    Para0   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para1   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para2   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para3   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para4   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para5   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para6   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para7   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para8   - The 32-bit parameter encoded to SystemView packet payload.
+*/
+void SEGGER_SYSVIEW_RecordU32x9(unsigned int EventID, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4, U32 Para5, U32 Para6, U32 Para7, U32 Para8) {
+  U8* pPayload;
+  U8* pPayloadStart;
+  RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 9 * SEGGER_SYSVIEW_QUANTA_U32);
+  //
+  pPayload = pPayloadStart;
+  ENCODE_U32(pPayload, Para0);
+  ENCODE_U32(pPayload, Para1);
+  ENCODE_U32(pPayload, Para2);
+  ENCODE_U32(pPayload, Para3);
+  ENCODE_U32(pPayload, Para4);
+  ENCODE_U32(pPayload, Para5);
+  ENCODE_U32(pPayload, Para6);
+  ENCODE_U32(pPayload, Para7);
+  ENCODE_U32(pPayload, Para8);
+  _SendPacket(pPayloadStart, pPayload, EventID);
+  RECORD_END();
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_RecordU32x10()
+*
+*  Function description
+*    Formats and sends a SystemView packet containing 10 U32 parameter payload.
+*
+*  Parameters
+*    EventID - SystemView event ID.
+*    Para0   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para1   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para2   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para3   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para4   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para5   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para6   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para7   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para8   - The 32-bit parameter encoded to SystemView packet payload.
+*    Para9   - The 32-bit parameter encoded to SystemView packet payload.
+*/
+void SEGGER_SYSVIEW_RecordU32x10(unsigned int EventID, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4, U32 Para5, U32 Para6, U32 Para7, U32 Para8, U32 Para9) {
+  U8* pPayload;
+  U8* pPayloadStart;
+  RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 10 * SEGGER_SYSVIEW_QUANTA_U32);
+  //
+  pPayload = pPayloadStart;
+  ENCODE_U32(pPayload, Para0);
+  ENCODE_U32(pPayload, Para1);
+  ENCODE_U32(pPayload, Para2);
+  ENCODE_U32(pPayload, Para3);
+  ENCODE_U32(pPayload, Para4);
+  ENCODE_U32(pPayload, Para5);
+  ENCODE_U32(pPayload, Para6);
+  ENCODE_U32(pPayload, Para7);
+  ENCODE_U32(pPayload, Para8);
+  ENCODE_U32(pPayload, Para9);
+  _SendPacket(pPayloadStart, pPayload, EventID);
+  RECORD_END();
+}
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_RecordString()
+*
+*  Function description
+*    Formats and sends a SystemView packet containing a string.
+*
+*  Parameters
+*    EventID - SystemView event ID.
+*    pString - The string to be sent in the SystemView packet payload.
+*
+*  Additional information
+*    The string is encoded as a count byte followed by the contents
+*    of the string.
+*    No more than SEGGER_SYSVIEW_MAX_STRING_LEN bytes will be encoded to the payload.
+*/
+void SEGGER_SYSVIEW_RecordString(unsigned int EventID, const char* pString) {
+  U8* pPayload;
+  U8* pPayloadStart;
+  RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 1 + SEGGER_SYSVIEW_MAX_STRING_LEN);
+  //
+  pPayload = _EncodeStr(pPayloadStart, pString, SEGGER_SYSVIEW_MAX_STRING_LEN);
+  _SendPacket(pPayloadStart, pPayload, EventID);
+  RECORD_END();
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_Start()
+*
+*  Function description
+*    Start recording SystemView events.
+*
+*    This function is triggered by the SystemView Application on connect.
+*    For single-shot or post-mortem mode recording, it needs to be called
+*    by the application.
+*
+*  Additional information
+*    This function enables transmission of SystemView packets recorded
+*    by subsequent trace calls and records a SystemView Start event.
+*
+*    As part of start, a SystemView Init packet is sent, containing the system
+*    frequency. The list of current tasks, the current system time and the
+*    system description string is sent, too.
+*
+*  Notes
+*    SEGGER_SYSVIEW_Start and SEGGER_SYSVIEW_Stop do not nest.
+*    When SEGGER_SYSVIEW_CAN_RESTART is 1, each received start command
+*    records the system information. This is required to enable restart
+*    of recordings when SystemView unexpectedly disconnects without sending
+*    a stop command before.
+*/
+void SEGGER_SYSVIEW_Start(void) {
+#if (SEGGER_SYSVIEW_CAN_RESTART == 0)
+  if (_SYSVIEW_Globals.EnableState == 0) {
+#endif
+    _SYSVIEW_Globals.EnableState = 1;
+#if (SEGGER_SYSVIEW_POST_MORTEM_MODE == 1)
+    _SendSyncInfo();
+#else
+    SEGGER_SYSVIEW_LOCK();
+    SEGGER_RTT_WriteSkipNoLock(CHANNEL_ID_UP, _abSync, 10);
+    SEGGER_SYSVIEW_UNLOCK();
+    SEGGER_SYSVIEW_ON_EVENT_RECORDED(10);
+    SEGGER_SYSVIEW_RecordVoid(SYSVIEW_EVTID_TRACE_START);
+    {
+      U8* pPayload;
+      U8* pPayloadStart;
+      RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 4 * SEGGER_SYSVIEW_QUANTA_U32);
+      //
+      pPayload = pPayloadStart;
+      ENCODE_U32(pPayload, _SYSVIEW_Globals.SysFreq);
+      ENCODE_U32(pPayload, _SYSVIEW_Globals.CPUFreq);
+      ENCODE_U32(pPayload, _SYSVIEW_Globals.RAMBaseAddress);
+      ENCODE_U32(pPayload, SEGGER_SYSVIEW_ID_SHIFT);
+      _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_INIT);
+      RECORD_END();
+    }
+    if (_SYSVIEW_Globals.pfSendSysDesc) {
+      _SYSVIEW_Globals.pfSendSysDesc();
+    }
+    SEGGER_SYSVIEW_RecordSystime();
+    SEGGER_SYSVIEW_SendTaskList();
+    SEGGER_SYSVIEW_SendNumModules();
+#endif
+#if (SEGGER_SYSVIEW_CAN_RESTART == 0)
+  }
+#endif
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_Stop()
+*
+*  Function description
+*    Stop recording SystemView events.
+*
+*    This function is triggered by the SystemView Application on disconnect.
+*    For single-shot or post-mortem mode recording, it can be called
+*    by the application.
+*
+*  Additional information
+*    This function disables transmission of SystemView packets recorded
+*    by subsequent trace calls.  If transmission is enabled when
+*    this function is called, a single SystemView Stop event is recorded
+*    to the trace, send, and then trace transmission is halted.
+*/
+void SEGGER_SYSVIEW_Stop(void) {
+  U8* pPayloadStart;
+  RECORD_START(SEGGER_SYSVIEW_INFO_SIZE);
+  //
+  if (_SYSVIEW_Globals.EnableState) {
+    _SendPacket(pPayloadStart, pPayloadStart, SYSVIEW_EVTID_TRACE_STOP);
+    _SYSVIEW_Globals.EnableState = 0;
+  }
+  RECORD_END();
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_GetChannelID()
+*
+*  Function description
+*    Returns the RTT <Up> / <Down> channel ID used by SystemView.
+*/
+int SEGGER_SYSVIEW_GetChannelID(void) {
+  return CHANNEL_ID_UP;
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_GetSysDesc()
+*
+*  Function description
+*    Triggers a send of the system information and description.
+*
+*/
+void SEGGER_SYSVIEW_GetSysDesc(void) {
+  U8* pPayload;
+  U8* pPayloadStart;
+  RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 4 * SEGGER_SYSVIEW_QUANTA_U32);
+  //
+  pPayload = pPayloadStart;
+  ENCODE_U32(pPayload, _SYSVIEW_Globals.SysFreq);
+  ENCODE_U32(pPayload, _SYSVIEW_Globals.CPUFreq);
+  ENCODE_U32(pPayload, _SYSVIEW_Globals.RAMBaseAddress);
+  ENCODE_U32(pPayload, SEGGER_SYSVIEW_ID_SHIFT);
+  _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_INIT);
+  RECORD_END();
+  if (_SYSVIEW_Globals.pfSendSysDesc) {
+    _SYSVIEW_Globals.pfSendSysDesc();
+  }
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_SendTaskInfo()
+*
+*  Function description
+*    Send a Task Info Packet, containing TaskId for identification,
+*    task priority and task name.
+*
+*  Parameters
+*    pInfo - Pointer to task information to send.
+*/
+void SEGGER_SYSVIEW_SendTaskInfo(const SEGGER_SYSVIEW_TASKINFO *pInfo) {
+  U8* pPayload;
+  U8* pPayloadStart;
+  RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32 + 1 + 32);
+  //
+  pPayload = pPayloadStart;
+  ENCODE_U32(pPayload, SHRINK_ID(pInfo->TaskID));
+  ENCODE_U32(pPayload, pInfo->Prio);
+  pPayload = _EncodeStr(pPayload, pInfo->sName, 32);
+  _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_TASK_INFO);
+  //
+  pPayload = pPayloadStart;
+  ENCODE_U32(pPayload, SHRINK_ID(pInfo->TaskID));
+  ENCODE_U32(pPayload, pInfo->StackBase);
+  ENCODE_U32(pPayload, pInfo->StackSize);
+  ENCODE_U32(pPayload, 0); // Stack End, future use
+  _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_STACK_INFO);
+  RECORD_END();
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_SendTaskList()
+*
+*  Function description
+*    Send all tasks descriptors to the host.
+*/
+void SEGGER_SYSVIEW_SendTaskList(void) {
+  if (_SYSVIEW_Globals.pOSAPI && _SYSVIEW_Globals.pOSAPI->pfSendTaskList) {
+    _SYSVIEW_Globals.pOSAPI->pfSendTaskList();
+  }
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_SendSysDesc()
+*
+*  Function description
+*    Send the system description string to the host.
+*    The system description is used by the Systemview Application
+*    to identify the current application and handle events accordingly.
+*
+*    The system description is usually called by the system description
+*    callback, to ensure it is only sent when the SystemView Application
+*    is connected.
+*
+*  Parameters
+*    sSysDesc - Pointer to the 0-terminated system description string.
+*
+*  Additional information
+*    One system description string may not exceed SEGGER_SYSVIEW_MAX_STRING_LEN characters.
+*    Multiple description strings can be recorded.
+*
+*    The Following items can be described in a system description string.
+*    Each item is identified by its identifier, followed by '=' and the value.
+*    Items are separated by ','.
+*/
+void SEGGER_SYSVIEW_SendSysDesc(const char *sSysDesc) {
+  U8* pPayload;
+  U8* pPayloadStart;
+  RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 1 + SEGGER_SYSVIEW_MAX_STRING_LEN);
+  //
+  pPayload = _EncodeStr(pPayloadStart, sSysDesc, SEGGER_SYSVIEW_MAX_STRING_LEN);
+  _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_SYSDESC);
+  RECORD_END();
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_RecordSystime()
+*
+*  Function description
+*    Formats and sends a SystemView Systime containing a single U64 or U32
+*    parameter payload.
+*/
+void SEGGER_SYSVIEW_RecordSystime(void) {
+  U64 Systime;
+
+  if (_SYSVIEW_Globals.pOSAPI && _SYSVIEW_Globals.pOSAPI->pfGetTime) {
+    Systime = _SYSVIEW_Globals.pOSAPI->pfGetTime();
+    SEGGER_SYSVIEW_RecordU32x2(SYSVIEW_EVTID_SYSTIME_US,
+                               (U32)(Systime),
+                               (U32)(Systime >> 32));
+  } else {
+    SEGGER_SYSVIEW_RecordU32(SYSVIEW_EVTID_SYSTIME_CYCLES, SEGGER_SYSVIEW_GET_TIMESTAMP());
+  }
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_RecordEnterISR()
+*
+*  Function description
+*    Format and send an ISR entry event.
+*
+*  Additional information
+*    Example packets sent
+*      02 0F 50              // ISR(15) Enter. Timestamp is 80 (0x50)
+*/
+void SEGGER_SYSVIEW_RecordEnterISR(void) {
+  unsigned v;
+  U8* pPayload;
+  U8* pPayloadStart;
+  RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32);
+  //
+  pPayload = pPayloadStart;
+  v = SEGGER_SYSVIEW_GET_INTERRUPT_ID();
+  ENCODE_U32(pPayload, v);
+  _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_ISR_ENTER);
+  RECORD_END();
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_RecordExitISR()
+*
+*  Function description
+*    Format and send an ISR exit event.
+*
+*  Additional information
+*    Format as follows:
+*      03 <TimeStamp>        // Max. packet len is 6
+*
+*    Example packets sent
+*      03 20                // ISR Exit. Timestamp is 32 (0x20)
+*/
+void SEGGER_SYSVIEW_RecordExitISR(void) {
+  U8* pPayloadStart;
+  RECORD_START(SEGGER_SYSVIEW_INFO_SIZE);
+  //
+  _SendPacket(pPayloadStart, pPayloadStart, SYSVIEW_EVTID_ISR_EXIT);
+  RECORD_END();
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_RecordExitISRToScheduler()
+*
+*  Function description
+*    Format and send an ISR exit into scheduler event.
+*
+*  Additional information
+*    Format as follows:
+*      18 <TimeStamp>        // Max. packet len is 6
+*
+*    Example packets sent
+*      18 20                // ISR Exit to Scheduler. Timestamp is 32 (0x20)
+*/
+void SEGGER_SYSVIEW_RecordExitISRToScheduler(void) {
+  U8* pPayloadStart;
+  RECORD_START(SEGGER_SYSVIEW_INFO_SIZE);
+  //
+  _SendPacket(pPayloadStart, pPayloadStart, SYSVIEW_EVTID_ISR_TO_SCHEDULER);
+  RECORD_END();
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_RecordEnterTimer()
+*
+*  Function description
+*    Format and send a Timer entry event.
+*
+*  Parameters
+*    TimerId - Id of the timer which starts.
+*/
+void SEGGER_SYSVIEW_RecordEnterTimer(U32 TimerId) {
+  U8* pPayload;
+  U8* pPayloadStart;
+  RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32);
+  //
+  pPayload = pPayloadStart;
+  ENCODE_U32(pPayload, SHRINK_ID(TimerId));
+  _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_TIMER_ENTER);
+  RECORD_END();
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_RecordExitTimer()
+*
+*  Function description
+*    Format and send a Timer exit event.
+*/
+void SEGGER_SYSVIEW_RecordExitTimer(void) {
+  U8* pPayloadStart;
+  RECORD_START(SEGGER_SYSVIEW_INFO_SIZE);
+  //
+  _SendPacket(pPayloadStart, pPayloadStart, SYSVIEW_EVTID_TIMER_EXIT);
+  RECORD_END();
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_RecordEndCall()
+*
+*  Function description
+*    Format and send an End API Call event without return value.
+*
+*  Parameters
+*    EventID - Id of API function which ends.
+*/
+void SEGGER_SYSVIEW_RecordEndCall(unsigned int EventID) {
+  U8* pPayload;
+  U8* pPayloadStart;
+  RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32);
+  //
+  pPayload = pPayloadStart;
+  ENCODE_U32(pPayload, EventID);
+  _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_END_CALL);
+  RECORD_END();
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_RecordEndCallU32()
+*
+*  Function description
+*    Format and send an End API Call event with return value.
+*
+*  Parameters
+*    EventID      - Id of API function which ends.
+*    Para0        - Return value which will be returned by the API function.
+*/
+void SEGGER_SYSVIEW_RecordEndCallU32(unsigned int EventID, U32 Para0) {
+  U8* pPayload;
+  U8* pPayloadStart;
+  RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 2 * SEGGER_SYSVIEW_QUANTA_U32);
+  //
+  pPayload = pPayloadStart;
+  ENCODE_U32(pPayload, EventID);
+  ENCODE_U32(pPayload, Para0);
+  _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_END_CALL);
+  RECORD_END();
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_OnIdle()
+*
+*  Function description
+*    Record an Idle event.
+*/
+void SEGGER_SYSVIEW_OnIdle(void) {
+  U8* pPayloadStart;
+  RECORD_START(SEGGER_SYSVIEW_INFO_SIZE);
+  //
+  _SendPacket(pPayloadStart, pPayloadStart, SYSVIEW_EVTID_IDLE);
+  RECORD_END();
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_OnTaskCreate()
+*
+*  Function description
+*    Record a Task Create event.  The Task Create event corresponds
+*    to creating a task in the OS.
+*
+*  Parameters
+*    TaskId        - Task ID of created task.
+*/
+void SEGGER_SYSVIEW_OnTaskCreate(U32 TaskId) {
+  U8* pPayload;
+  U8* pPayloadStart;
+  RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32);
+  //
+  pPayload = pPayloadStart;
+  TaskId = SHRINK_ID(TaskId);
+  ENCODE_U32(pPayload, TaskId);
+  _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_TASK_CREATE);
+  RECORD_END();
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_OnTaskTerminate()
+*
+*  Function description
+*    Record a Task termination event.
+*    The Task termination event corresponds to terminating a task in
+*    the OS. If the TaskId is the currently active task,
+*    SEGGER_SYSVIEW_OnTaskStopExec may be used, either.
+*
+*  Parameters
+*    TaskId        - Task ID of terminated task.
+*/
+void SEGGER_SYSVIEW_OnTaskTerminate(U32 TaskId) {
+  U8* pPayload;
+  U8* pPayloadStart;
+  RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32);
+  //
+  pPayload = pPayloadStart;
+  TaskId = SHRINK_ID(TaskId);
+  ENCODE_U32(pPayload, TaskId);
+  _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_TASK_TERMINATE);
+  RECORD_END();
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_OnTaskStartExec()
+*
+*  Function description
+*    Record a Task Start Execution event.  The Task Start event
+*    corresponds to when a task has started to execute rather than
+*    when it is ready to execute.
+*
+*  Parameters
+*    TaskId - Task ID of task that started to execute.
+*/
+void SEGGER_SYSVIEW_OnTaskStartExec(U32 TaskId) {
+  U8* pPayload;
+  U8* pPayloadStart;
+  RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32);
+  //
+  pPayload = pPayloadStart;
+  TaskId = SHRINK_ID(TaskId);
+  ENCODE_U32(pPayload, TaskId);
+  _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_TASK_START_EXEC);
+  RECORD_END();
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_OnTaskStopExec()
+*
+*  Function description
+*    Record a Task Stop Execution event.  The Task Stop event
+*    corresponds to when a task stops executing and terminates.
+*/
+void SEGGER_SYSVIEW_OnTaskStopExec(void) {
+  U8* pPayloadStart;
+  RECORD_START(SEGGER_SYSVIEW_INFO_SIZE);
+  //
+  _SendPacket(pPayloadStart, pPayloadStart, SYSVIEW_EVTID_TASK_STOP_EXEC);
+  RECORD_END();
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_OnTaskStartReady()
+*
+*  Function description
+*    Record a Task Start Ready event.
+*
+*  Parameters
+*    TaskId - Task ID of task that started to execute.
+*/
+void SEGGER_SYSVIEW_OnTaskStartReady(U32 TaskId) {
+  U8* pPayload;
+  U8* pPayloadStart;
+  RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32);
+  //
+  pPayload = pPayloadStart;
+  TaskId = SHRINK_ID(TaskId);
+  ENCODE_U32(pPayload, TaskId);
+  _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_TASK_START_READY);
+  RECORD_END();
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_OnTaskStopReady()
+*
+*  Function description
+*    Record a Task Stop Ready event.
+*
+*  Parameters
+*    TaskId - Task ID of task that completed execution.
+*    Cause  - Reason for task to stop (i.e. Idle/Sleep)
+*/
+void SEGGER_SYSVIEW_OnTaskStopReady(U32 TaskId, unsigned int Cause) {
+  U8* pPayload;
+  U8* pPayloadStart;
+  RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 2 * SEGGER_SYSVIEW_QUANTA_U32);
+  //
+  pPayload = pPayloadStart;
+  TaskId = SHRINK_ID(TaskId);
+  ENCODE_U32(pPayload, TaskId);
+  ENCODE_U32(pPayload, Cause);
+  _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_TASK_STOP_READY);
+  RECORD_END();
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_MarkStart()
+*
+*  Function description
+*    Record a Performance Marker Start event to start measuring runtime.
+*
+*  Parameters
+*    MarkerId  - User defined ID for the marker.
+*/
+void SEGGER_SYSVIEW_MarkStart(unsigned MarkerId) {
+  U8* pPayload;
+  U8* pPayloadStart;
+  RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32);
+  //
+  pPayload = pPayloadStart;
+  ENCODE_U32(pPayload, MarkerId);
+  _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_MARK_START);
+  RECORD_END();
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_MarkStop()
+*
+*  Function description
+*    Record a Performance Marker Stop event to stop measuring runtime.
+*
+*  Parameters
+*    MarkerId  - User defined ID for the marker.
+*/
+void SEGGER_SYSVIEW_MarkStop(unsigned MarkerId) {
+  U8 * pPayload;
+  U8 * pPayloadStart;
+  RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32);
+  //
+  pPayload = pPayloadStart;
+  ENCODE_U32(pPayload, MarkerId);
+  _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_MARK_STOP);
+  RECORD_END();
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_Mark()
+*
+*  Function description
+*    Record a Performance Marker intermediate event.
+*
+*  Parameters
+*    MarkerId  - User defined ID for the marker.
+*/
+void SEGGER_SYSVIEW_Mark(unsigned int MarkerId) {
+  U8* pPayload;
+  U8* pPayloadStart;
+  RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 2 * SEGGER_SYSVIEW_QUANTA_U32);
+  //
+  pPayload = pPayloadStart;
+  ENCODE_U32(pPayload, SYSVIEW_EVTID_EX_MARK);
+  ENCODE_U32(pPayload, MarkerId);
+  _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_EX);
+  RECORD_END();
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_NameMarker()
+*
+*  Function description
+*    Send the name of a Performance Marker to be displayed in SystemView.
+*
+*    Marker names are usually set in the system description
+*    callback, to ensure it is only sent when the SystemView Application
+*    is connected.
+*
+*  Parameters
+*    MarkerId   - User defined ID for the marker.
+*    sName      - Pointer to the marker name. (Max. SEGGER_SYSVIEW_MAX_STRING_LEN Bytes)
+*/
+void SEGGER_SYSVIEW_NameMarker(unsigned int MarkerId, const char* sName) {
+  U8* pPayload;
+  U8* pPayloadStart;
+  RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 2 * SEGGER_SYSVIEW_QUANTA_U32 + 1 + SEGGER_SYSVIEW_MAX_STRING_LEN);
+  //
+  pPayload = pPayloadStart;
+  ENCODE_U32(pPayload, SYSVIEW_EVTID_EX_NAME_MARKER);
+  ENCODE_U32(pPayload, MarkerId);
+  pPayload = _EncodeStr(pPayload, sName, SEGGER_SYSVIEW_MAX_STRING_LEN);
+  _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_EX);
+  RECORD_END();
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_NameResource()
+*
+*  Function description
+*    Send the name of a resource to be displayed in SystemView.
+*
+*    Marker names are usually set in the system description
+*    callback, to ensure it is only sent when the SystemView Application
+*    is connected.
+*
+*  Parameters
+*    ResourceId - Id of the resource to be named. i.e. its address.
+*    sName      - Pointer to the resource name. (Max. SEGGER_SYSVIEW_MAX_STRING_LEN Bytes)
+*/
+void SEGGER_SYSVIEW_NameResource(U32 ResourceId, const char* sName) {
+  U8* pPayload;
+  U8* pPayloadStart;
+  RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32 + 1 + SEGGER_SYSVIEW_MAX_STRING_LEN);
+  //
+  pPayload = pPayloadStart;
+  ENCODE_U32(pPayload, SHRINK_ID(ResourceId));
+  pPayload = _EncodeStr(pPayload, sName, SEGGER_SYSVIEW_MAX_STRING_LEN);
+  _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_NAME_RESOURCE);
+  RECORD_END();
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_SendPacket()
+*
+*  Function description
+*    Send an event packet.
+*
+*  Parameters
+*    pPacket      - Pointer to the start of the packet.
+*    pPayloadEnd  - Pointer to the end of the payload.
+*                   Make sure there are at least 5 bytes free after the payload.
+*    EventId      - Id of the event packet.
+*
+*  Return value
+*    !=0:  Success, Message sent.
+*    ==0:  Buffer full, Message *NOT* sent.
+*/
+int SEGGER_SYSVIEW_SendPacket(U8* pPacket, U8* pPayloadEnd, unsigned int EventId) {
+#if (SEGGER_SYSVIEW_USE_STATIC_BUFFER == 1)
+  SEGGER_SYSVIEW_LOCK();
+#endif
+  _SendPacket(pPacket + 4, pPayloadEnd, EventId);
+#if (SEGGER_SYSVIEW_USE_STATIC_BUFFER == 1)
+  SEGGER_SYSVIEW_UNLOCK();
+#endif
+  return 0;
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_EncodeU32()
+*
+*  Function description
+*    Encode a U32 in variable-length format.
+*
+*  Parameters
+*    pPayload - Pointer to where U32 will be encoded.
+*    Value    - The 32-bit value to be encoded.
+*
+*  Return value
+*    Pointer to the byte following the value, i.e. the first free
+*    byte in the payload and the next position to store payload
+*    content.
+*/
+U8* SEGGER_SYSVIEW_EncodeU32(U8* pPayload, U32 Value) {
+  ENCODE_U32(pPayload, Value);
+  return pPayload;
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_EncodeString()
+*
+*  Function description
+*    Encode a string in variable-length format.
+*
+*  Parameters
+*    pPayload - Pointer to where string will be encoded.
+*    s        - String to encode.
+*    MaxLen   - Maximum number of characters to encode from string.
+*
+*  Return value
+*    Pointer to the byte following the value, i.e. the first free
+*    byte in the payload and the next position to store payload
+*    content.
+*
+*  Additional information
+*    The string is encoded as a count byte followed by the contents
+*    of the string.
+*    No more than 1 + MaxLen bytes will be encoded to the payload.
+*/
+U8* SEGGER_SYSVIEW_EncodeString(U8* pPayload, const char* s, unsigned int MaxLen) {
+  return _EncodeStr(pPayload, s, MaxLen);
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_EncodeData()
+*
+*  Function description
+*    Encode a byte buffer in variable-length format.
+*
+*  Parameters
+*    pPayload - Pointer to where string will be encoded.
+*    pSrc     - Pointer to data buffer to be encoded.
+*    NumBytes - Number of bytes in the buffer to be encoded.
+*
+*  Return value
+*    Pointer to the byte following the value, i.e. the first free
+*    byte in the payload and the next position to store payload
+*    content.
+*
+*  Additional information
+*    The data is encoded as a count byte followed by the contents
+*    of the data buffer.
+*    Make sure NumBytes + 1 bytes are free for the payload.
+*/
+U8* SEGGER_SYSVIEW_EncodeData(U8 *pPayload, const char* pSrc, unsigned int NumBytes) {
+  return _EncodeData(pPayload, pSrc, NumBytes);
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_EncodeId()
+*
+*  Function description
+*    Encode a 32-bit Id in shrunken variable-length format.
+*
+*  Parameters
+*    pPayload - Pointer to where the Id will be encoded.
+*    Id       - The 32-bit value to be encoded.
+*
+*  Return value
+*    Pointer to the byte following the value, i.e. the first free
+*    byte in the payload and the next position to store payload
+*    content.
+*
+*  Additional information
+*    The parameters to shrink an Id can be configured in
+*    SEGGER_SYSVIEW_Conf.h and via SEGGER_SYSVIEW_SetRAMBase().
+*     SEGGER_SYSVIEW_ID_BASE: Lowest Id reported by the application.
+*       (i.e. 0x20000000 when all Ids are an address in this RAM)
+*     SEGGER_SYSVIEW_ID_SHIFT: Number of bits to shift the Id to
+*       save bandwidth. (i.e. 2 when Ids are 4 byte aligned)
+*/
+U8* SEGGER_SYSVIEW_EncodeId(U8* pPayload, U32 Id) {
+  Id = SHRINK_ID(Id);
+  ENCODE_U32(pPayload, Id);
+  return pPayload;
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_ShrinkId()
+*
+*  Function description
+*    Get the shrunken value of an Id for further processing like in
+*    SEGGER_SYSVIEW_NameResource().
+*
+*  Parameters
+*    Id       - The 32-bit value to be shrunken.
+*
+*  Return value
+*    Shrunken Id.
+*
+*  Additional information
+*    The parameters to shrink an Id can be configured in
+*    SEGGER_SYSVIEW_Conf.h and via SEGGER_SYSVIEW_SetRAMBase().
+*     SEGGER_SYSVIEW_ID_BASE: Lowest Id reported by the application.
+*       (i.e. 0x20000000 when all Ids are an address in this RAM)
+*     SEGGER_SYSVIEW_ID_SHIFT: Number of bits to shift the Id to
+*       save bandwidth. (i.e. 2 when Ids are 4 byte aligned)
+*/
+U32 SEGGER_SYSVIEW_ShrinkId(U32 Id) {
+  return SHRINK_ID(Id);
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_RegisterModule()
+*
+*  Function description
+*    Register a middleware module for recording its events.
+*
+*  Parameters
+*    pModule  - The middleware module information.
+*
+*  Additional information
+*    SEGGER_SYSVIEW_MODULE elements:
+*      sDescription      - Pointer to a string containing the module name and optionally the module event description.
+*      NumEvents         - Number of events the module wants to register.
+*      EventOffset       - Offset to be added to the event Ids. Out parameter, set by this function. Do not modify after calling this function.
+*      pfSendModuleDesc  - Callback function pointer to send more detailed module description to SystemView Application.
+*      pNext             - Pointer to next registered module. Out parameter, set by this function. Do not modify after calling this function.
+*/
+void SEGGER_SYSVIEW_RegisterModule(SEGGER_SYSVIEW_MODULE* pModule) {
+  SEGGER_SYSVIEW_LOCK();
+  if (_pFirstModule == 0) {
+    //
+    // No module registered, yet.
+    // Start list with new module.
+    // EventOffset is the base offset for modules
+    //
+    pModule->EventOffset = MODULE_EVENT_OFFSET;
+    pModule->pNext = 0;
+    _pFirstModule = pModule;
+    _NumModules = 1;
+  } else {
+    //
+    // Registreded module(s) present.
+    // Prepend new module in list.
+    // EventOffset set from number of events and offset of previous module.
+    //
+    pModule->EventOffset = _pFirstModule->EventOffset + _pFirstModule->NumEvents;
+    pModule->pNext = _pFirstModule;
+    _pFirstModule = pModule;
+    _NumModules++;
+  }
+  SEGGER_SYSVIEW_SendModule(0);
+  if (pModule->pfSendModuleDesc) {
+    pModule->pfSendModuleDesc();
+  }
+  SEGGER_SYSVIEW_UNLOCK();
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_RecordModuleDescription()
+*
+*  Function description
+*    Sends detailed information of a registered module to the host.
+*
+*  Parameters
+*    pModule      - Pointer to the described module.
+*    sDescription - Pointer to a description string.
+*/
+void SEGGER_SYSVIEW_RecordModuleDescription(const SEGGER_SYSVIEW_MODULE* pModule, const char* sDescription) {
+  U8  ModuleId;
+  SEGGER_SYSVIEW_MODULE* p;
+
+  p = _pFirstModule;
+  ModuleId = 0;
+  do {
+    if (p == pModule) {
+      break;
+    }
+    ModuleId++;
+    p = p->pNext;
+  } while (p);
+  {
+    U8* pPayload;
+    U8* pPayloadStart;
+    RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 2 * SEGGER_SYSVIEW_QUANTA_U32 + 1 + SEGGER_SYSVIEW_MAX_STRING_LEN);
+    //
+    pPayload = pPayloadStart;
+    //
+    // Send module description
+    // Send event offset and number of events
+    //
+    ENCODE_U32(pPayload, ModuleId);
+    ENCODE_U32(pPayload, (pModule->EventOffset));
+    pPayload = _EncodeStr(pPayload, sDescription, SEGGER_SYSVIEW_MAX_STRING_LEN);
+    _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_MODULEDESC);
+    RECORD_END();
+  }
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_SendModule()
+*
+*  Function description
+*    Sends the information of a registered module to the host.
+*
+*  Parameters
+*    ModuleId   - Id of the requested module.
+*/
+void SEGGER_SYSVIEW_SendModule(U8 ModuleId) {
+  SEGGER_SYSVIEW_MODULE* pModule;
+  U32 n;
+
+  if (_pFirstModule != 0) {
+    pModule = _pFirstModule;
+    for (n = 0; n < ModuleId; n++) {
+      pModule = pModule->pNext;
+      if (pModule == 0) {
+        break;
+      }
+    }
+    if (pModule != 0) {
+      U8* pPayload;
+      U8* pPayloadStart;
+      RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 2 * SEGGER_SYSVIEW_QUANTA_U32 + 1 + SEGGER_SYSVIEW_MAX_STRING_LEN);
+      //
+      pPayload = pPayloadStart;
+      //
+      // Send module description
+      // Send event offset and number of events
+      //
+      ENCODE_U32(pPayload, ModuleId);
+      ENCODE_U32(pPayload, (pModule->EventOffset));
+      pPayload = _EncodeStr(pPayload, pModule->sModule, SEGGER_SYSVIEW_MAX_STRING_LEN);
+      _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_MODULEDESC);
+      RECORD_END();
+    }
+  }
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_SendModuleDescription()
+*
+*  Function description
+*    Triggers a send of the registered module descriptions.
+*
+*/
+void SEGGER_SYSVIEW_SendModuleDescription(void) {
+  SEGGER_SYSVIEW_MODULE* pModule;
+
+  if (_pFirstModule != 0) {
+    pModule = _pFirstModule;
+    do {
+      if (pModule->pfSendModuleDesc) {
+        pModule->pfSendModuleDesc();
+      }
+      pModule = pModule->pNext;
+    } while (pModule);
+  }
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_SendNumModules()
+*
+*  Function description
+*    Send the number of registered modules to the host.
+*/
+void SEGGER_SYSVIEW_SendNumModules(void) {
+  U8* pPayload;
+  U8* pPayloadStart;
+  RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 2*SEGGER_SYSVIEW_QUANTA_U32);
+  pPayload = pPayloadStart;
+  ENCODE_U32(pPayload, _NumModules);
+  _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_NUMMODULES);
+  RECORD_END();
+}
+
+#ifndef SEGGER_SYSVIEW_EXCLUDE_PRINTF // Define in project to avoid warnings about variable parameter list
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_PrintfHostEx()
+*
+*  Function description
+*    Print a string which is formatted on the host by the SystemView Application
+*    with Additional information.
+*
+*  Parameters
+*    s        - String to be formatted.
+*    Options  - Options for the string. i.e. Log level.
+*
+*  Additional information
+*    All format arguments are treated as 32-bit scalar values.
+*/
+void SEGGER_SYSVIEW_PrintfHostEx(const char* s, U32 Options, ...) {
+  va_list ParamList;
+#if SEGGER_SYSVIEW_PRINTF_IMPLICIT_FORMAT
+  int r;
+
+  va_start(ParamList, Options);
+  r = _VPrintHost(s, Options, &ParamList);
+  va_end(ParamList);
+
+  if (r == -1) {
+    va_start(ParamList, Options);
+    _VPrintTarget(s, Options, &ParamList);
+    va_end(ParamList);
+  }
+#else
+  va_start(ParamList, Options);
+  _VPrintHost(s, Options, &ParamList);
+  va_end(ParamList);
+#endif
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_PrintfHost()
+*
+*  Function description
+*    Print a string which is formatted on the host by the SystemView Application.
+*
+*  Parameters
+*    s        - String to be formatted.
+*
+*  Additional information
+*    All format arguments are treated as 32-bit scalar values.
+*/
+void SEGGER_SYSVIEW_PrintfHost(const char* s, ...) {
+  va_list ParamList;
+#if SEGGER_SYSVIEW_PRINTF_IMPLICIT_FORMAT
+  int r;
+
+  va_start(ParamList, s);
+  r = _VPrintHost(s, SEGGER_SYSVIEW_LOG, &ParamList);
+  va_end(ParamList);
+
+  if (r == -1) {
+    va_start(ParamList, s);
+    _VPrintTarget(s, SEGGER_SYSVIEW_LOG, &ParamList);
+    va_end(ParamList);
+  }
+#else
+  va_start(ParamList, s);
+  _VPrintHost(s, SEGGER_SYSVIEW_LOG, &ParamList);
+  va_end(ParamList);
+#endif
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_WarnfHost()
+*
+*  Function description
+*    Print a warning string which is formatted on the host by
+*    the SystemView Application.
+*
+*  Parameters
+*    s        - String to be formatted.
+*
+*  Additional information
+*    All format arguments are treated as 32-bit scalar values.
+*/
+void SEGGER_SYSVIEW_WarnfHost(const char* s, ...) {
+  va_list ParamList;
+#if SEGGER_SYSVIEW_PRINTF_IMPLICIT_FORMAT
+  int r;
+
+  va_start(ParamList, s);
+  r = _VPrintHost(s, SEGGER_SYSVIEW_WARNING, &ParamList);
+  va_end(ParamList);
+
+  if (r == -1) {
+    va_start(ParamList, s);
+    _VPrintTarget(s, SEGGER_SYSVIEW_WARNING, &ParamList);
+    va_end(ParamList);
+  }
+#else
+  va_start(ParamList, s);
+  _VPrintHost(s, SEGGER_SYSVIEW_WARNING, &ParamList);
+  va_end(ParamList);
+#endif
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_ErrorfHost()
+*
+*  Function description
+*    Print an error string which is formatted on the host by
+*    the SystemView Application.
+*
+*  Parameters
+*    s        - String to be formatted.
+*
+*  Additional information
+*    All format arguments are treated as 32-bit scalar values.
+*/
+void SEGGER_SYSVIEW_ErrorfHost(const char* s, ...) {
+  va_list ParamList;
+#if SEGGER_SYSVIEW_PRINTF_IMPLICIT_FORMAT
+  int r;
+
+  va_start(ParamList, s);
+  r = _VPrintHost(s, SEGGER_SYSVIEW_ERROR, &ParamList);
+  va_end(ParamList);
+
+  if (r == -1) {
+    va_start(ParamList, s);
+    _VPrintTarget(s, SEGGER_SYSVIEW_ERROR, &ParamList);
+    va_end(ParamList);
+  }
+#else
+  va_start(ParamList, s);
+  _VPrintHost(s, SEGGER_SYSVIEW_ERROR, &ParamList);
+  va_end(ParamList);
+#endif
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_PrintfTargetEx()
+*
+*  Function description
+*    Print a string which is formatted on the target before sent to
+*    the host with Additional information.
+*
+*  Parameters
+*    s        - String to be formatted.
+*    Options  - Options for the string. i.e. Log level.
+*/
+void SEGGER_SYSVIEW_PrintfTargetEx(const char* s, U32 Options, ...) {
+  va_list ParamList;
+
+  va_start(ParamList, Options);
+  _VPrintTarget(s, Options, &ParamList);
+  va_end(ParamList);
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_PrintfTarget()
+*
+*  Function description
+*    Print a string which is formatted on the target before sent to
+*    the host.
+*
+*  Parameters
+*    s        - String to be formatted.
+*/
+void SEGGER_SYSVIEW_PrintfTarget(const char* s, ...) {
+  va_list ParamList;
+
+  va_start(ParamList, s);
+  _VPrintTarget(s, SEGGER_SYSVIEW_LOG, &ParamList);
+  va_end(ParamList);
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_WarnfTarget()
+*
+*  Function description
+*    Print a warning string which is formatted on the target before
+*    sent to the host.
+*
+*  Parameters
+*    s        - String to be formatted.
+*/
+void SEGGER_SYSVIEW_WarnfTarget(const char* s, ...) {
+  va_list ParamList;
+
+  va_start(ParamList, s);
+  _VPrintTarget(s, SEGGER_SYSVIEW_WARNING, &ParamList);
+  va_end(ParamList);
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_ErrorfTarget()
+*
+*  Function description
+*    Print an error string which is formatted on the target before
+*    sent to the host.
+*
+*  Parameters
+*    s        - String to be formatted.
+*/
+void SEGGER_SYSVIEW_ErrorfTarget(const char* s, ...) {
+  va_list ParamList;
+
+  va_start(ParamList, s);
+  _VPrintTarget(s, SEGGER_SYSVIEW_ERROR, &ParamList);
+  va_end(ParamList);
+}
+#endif // SEGGER_SYSVIEW_EXCLUDE_PRINTF
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_Print()
+*
+*  Function description
+*    Print a string to the host.
+*
+*  Parameters
+*    s        - String to sent.
+*/
+void SEGGER_SYSVIEW_Print(const char* s) {
+  U8* pPayload;
+  U8* pPayloadStart;
+  RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 2 * SEGGER_SYSVIEW_QUANTA_U32 + SEGGER_SYSVIEW_MAX_STRING_LEN);
+  //
+  pPayload = _EncodeStr(pPayloadStart, s, SEGGER_SYSVIEW_MAX_STRING_LEN);
+  ENCODE_U32(pPayload, SEGGER_SYSVIEW_LOG);
+  ENCODE_U32(pPayload, 0);
+  _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_PRINT_FORMATTED);
+  RECORD_END();
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_Warn()
+*
+*  Function description
+*    Print a warning string to the host.
+*
+*  Parameters
+*    s        - String to sent.
+*/
+void SEGGER_SYSVIEW_Warn(const char* s) {
+  U8* pPayload;
+  U8* pPayloadStart;
+  RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 2 * SEGGER_SYSVIEW_QUANTA_U32 + SEGGER_SYSVIEW_MAX_STRING_LEN);
+  //
+  pPayload = _EncodeStr(pPayloadStart, s, SEGGER_SYSVIEW_MAX_STRING_LEN);
+  ENCODE_U32(pPayload, SEGGER_SYSVIEW_WARNING);
+  ENCODE_U32(pPayload, 0);
+  _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_PRINT_FORMATTED);
+  RECORD_END();
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_Error()
+*
+*  Function description
+*    Print an error string to the host.
+*
+*  Parameters
+*    s        - String to sent.
+*/
+void SEGGER_SYSVIEW_Error(const char* s) {
+  U8* pPayload;
+  U8* pPayloadStart;
+  RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 2 * SEGGER_SYSVIEW_QUANTA_U32 + SEGGER_SYSVIEW_MAX_STRING_LEN);
+  //
+  pPayload = _EncodeStr(pPayloadStart, s, SEGGER_SYSVIEW_MAX_STRING_LEN);
+  ENCODE_U32(pPayload, SEGGER_SYSVIEW_ERROR);
+  ENCODE_U32(pPayload, 0);
+  _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_PRINT_FORMATTED);
+  RECORD_END();
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_EnableEvents()
+*
+*  Function description
+*    Enable standard SystemView events to be generated.
+*
+*  Parameters
+*    EnableMask   - Events to be enabled.
+*/
+void SEGGER_SYSVIEW_EnableEvents(U32 EnableMask) {
+  _SYSVIEW_Globals.DisabledEvents &= ~EnableMask;
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_DisableEvents()
+*
+*  Function description
+*    Disable standard SystemView events to not be generated.
+*
+*  Parameters
+*    DisableMask  - Events to be disabled.
+*/
+void SEGGER_SYSVIEW_DisableEvents(U32 DisableMask) {
+  _SYSVIEW_Globals.DisabledEvents |= DisableMask;
+}
+
+/*********************************************************************
+*
+*       SEGGER_SYSVIEW_IsStarted()
+*
+*  Function description
+*    Handle incoming packets if any and check if recording is started.
+*
+*  Return value
+*      0: Recording not started.
+*    > 0: Recording started.
+*/
+int SEGGER_SYSVIEW_IsStarted(void) {
+#if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1)
+  //
+  // Check if host is sending data which needs to be processed.
+  //
+  if (SEGGER_RTT_HASDATA(CHANNEL_ID_DOWN)) {
+    if (_SYSVIEW_Globals.RecursionCnt == 0) {   // Avoid uncontrolled nesting. This way, this routine can call itself once, but no more often than that.
+      _SYSVIEW_Globals.RecursionCnt = 1;
+      _HandleIncomingPacket();
+      _SYSVIEW_Globals.RecursionCnt = 0;
+    }
+  }
+#endif
+  return _SYSVIEW_Globals.EnableState;
+}
+
+
+/*************************** End of file ****************************/

+ 370 - 0
code/debug/SEGGER/SEGGER_SYSVIEW.h

@@ -0,0 +1,370 @@
+/*********************************************************************
+*                    SEGGER Microcontroller GmbH                     *
+*                        The Embedded Experts                        *
+**********************************************************************
+*                                                                    *
+*            (c) 1995 - 2021 SEGGER Microcontroller GmbH             *
+*                                                                    *
+*       www.segger.com     Support: support@segger.com               *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+*       SEGGER SystemView * Real-time application analysis           *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+* All rights reserved.                                               *
+*                                                                    *
+* SEGGER strongly recommends to not make any changes                 *
+* to or modify the source code of this software in order to stay     *
+* compatible with the SystemView and RTT protocol, and J-Link.       *
+*                                                                    *
+* Redistribution and use in source and binary forms, with or         *
+* without modification, are permitted provided that the following    *
+* condition is met:                                                  *
+*                                                                    *
+* o Redistributions of source code must retain the above copyright   *
+*   notice, this condition and the following disclaimer.             *
+*                                                                    *
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND             *
+* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,        *
+* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF           *
+* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE           *
+* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR           *
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT  *
+* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;    *
+* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF      *
+* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT          *
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE  *
+* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH   *
+* DAMAGE.                                                            *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+*       SystemView version: 3.32                                    *
+*                                                                    *
+**********************************************************************
+-------------------------- END-OF-HEADER -----------------------------
+File    : SEGGER_SYSVIEW.h
+Purpose : System visualization API.
+Revision: $Rev: 26226 $
+*/
+
+#ifndef SEGGER_SYSVIEW_H
+#define SEGGER_SYSVIEW_H
+
+/*********************************************************************
+*
+*       #include Section
+*
+**********************************************************************
+*/
+
+#include "SEGGER.h"
+#include "SEGGER_SYSVIEW_ConfDefaults.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/*********************************************************************
+*
+*       Defines, fixed
+*
+**********************************************************************
+*/
+
+#define SEGGER_SYSVIEW_MAJOR          3
+#define SEGGER_SYSVIEW_MINOR          32
+#define SEGGER_SYSVIEW_REV            0
+#define SEGGER_SYSVIEW_VERSION        ((SEGGER_SYSVIEW_MAJOR * 10000) + (SEGGER_SYSVIEW_MINOR * 100) + SEGGER_SYSVIEW_REV)
+
+#define SEGGER_SYSVIEW_INFO_SIZE      9   // Minimum size, which has to be reserved for a packet. 1-2 byte of message type, 0-2  byte of payload length, 1-5 bytes of timestamp.
+#define SEGGER_SYSVIEW_QUANTA_U32     5   // Maximum number of bytes to encode a U32, should be reserved for each 32-bit value in a packet.
+
+#define SEGGER_SYSVIEW_LOG            (0u)
+#define SEGGER_SYSVIEW_WARNING        (1u)
+#define SEGGER_SYSVIEW_ERROR          (2u)
+#define SEGGER_SYSVIEW_FLAG_APPEND    (1u << 6)
+
+#define SEGGER_SYSVIEW_PREPARE_PACKET(p)  (p) + 4
+//
+// SystemView events. First 32 IDs from 0 .. 31 are reserved for these
+//
+#define   SYSVIEW_EVTID_NOP                0  // Dummy packet.
+#define   SYSVIEW_EVTID_OVERFLOW           1
+#define   SYSVIEW_EVTID_ISR_ENTER          2
+#define   SYSVIEW_EVTID_ISR_EXIT           3
+#define   SYSVIEW_EVTID_TASK_START_EXEC    4
+#define   SYSVIEW_EVTID_TASK_STOP_EXEC     5
+#define   SYSVIEW_EVTID_TASK_START_READY   6
+#define   SYSVIEW_EVTID_TASK_STOP_READY    7
+#define   SYSVIEW_EVTID_TASK_CREATE        8
+#define   SYSVIEW_EVTID_TASK_INFO          9
+#define   SYSVIEW_EVTID_TRACE_START       10
+#define   SYSVIEW_EVTID_TRACE_STOP        11
+#define   SYSVIEW_EVTID_SYSTIME_CYCLES    12
+#define   SYSVIEW_EVTID_SYSTIME_US        13
+#define   SYSVIEW_EVTID_SYSDESC           14
+#define   SYSVIEW_EVTID_MARK_START        15
+#define   SYSVIEW_EVTID_MARK_STOP         16
+#define   SYSVIEW_EVTID_IDLE              17
+#define   SYSVIEW_EVTID_ISR_TO_SCHEDULER  18
+#define   SYSVIEW_EVTID_TIMER_ENTER       19
+#define   SYSVIEW_EVTID_TIMER_EXIT        20
+#define   SYSVIEW_EVTID_STACK_INFO        21
+#define   SYSVIEW_EVTID_MODULEDESC        22
+
+#define   SYSVIEW_EVTID_INIT              24
+#define   SYSVIEW_EVTID_NAME_RESOURCE     25
+#define   SYSVIEW_EVTID_PRINT_FORMATTED   26
+#define   SYSVIEW_EVTID_NUMMODULES        27
+#define   SYSVIEW_EVTID_END_CALL          28
+#define   SYSVIEW_EVTID_TASK_TERMINATE    29
+
+#define   SYSVIEW_EVTID_EX                31
+//
+// SystemView extended events. Sent with ID 31.
+//
+#define   SYSVIEW_EVTID_EX_MARK            0
+#define   SYSVIEW_EVTID_EX_NAME_MARKER     1
+//
+// Event masks to disable/enable events
+//
+#define   SYSVIEW_EVTMASK_NOP               (1 << SYSVIEW_EVTID_NOP)
+#define   SYSVIEW_EVTMASK_OVERFLOW          (1 << SYSVIEW_EVTID_OVERFLOW)
+#define   SYSVIEW_EVTMASK_ISR_ENTER         (1 << SYSVIEW_EVTID_ISR_ENTER)
+#define   SYSVIEW_EVTMASK_ISR_EXIT          (1 << SYSVIEW_EVTID_ISR_EXIT)
+#define   SYSVIEW_EVTMASK_TASK_START_EXEC   (1 << SYSVIEW_EVTID_TASK_START_EXEC)
+#define   SYSVIEW_EVTMASK_TASK_STOP_EXEC    (1 << SYSVIEW_EVTID_TASK_STOP_EXEC)
+#define   SYSVIEW_EVTMASK_TASK_START_READY  (1 << SYSVIEW_EVTID_TASK_START_READY)
+#define   SYSVIEW_EVTMASK_TASK_STOP_READY   (1 << SYSVIEW_EVTID_TASK_STOP_READY)
+#define   SYSVIEW_EVTMASK_TASK_CREATE       (1 << SYSVIEW_EVTID_TASK_CREATE)
+#define   SYSVIEW_EVTMASK_TASK_INFO         (1 << SYSVIEW_EVTID_TASK_INFO)
+#define   SYSVIEW_EVTMASK_TRACE_START       (1 << SYSVIEW_EVTID_TRACE_START)
+#define   SYSVIEW_EVTMASK_TRACE_STOP        (1 << SYSVIEW_EVTID_TRACE_STOP)
+#define   SYSVIEW_EVTMASK_SYSTIME_CYCLES    (1 << SYSVIEW_EVTID_SYSTIME_CYCLES)
+#define   SYSVIEW_EVTMASK_SYSTIME_US        (1 << SYSVIEW_EVTID_SYSTIME_US)
+#define   SYSVIEW_EVTMASK_SYSDESC           (1 << SYSVIEW_EVTID_SYSDESC)
+#define   SYSVIEW_EVTMASK_USER_START        (1 << SYSVIEW_EVTID_USER_START)
+#define   SYSVIEW_EVTMASK_USER_STOP         (1 << SYSVIEW_EVTID_USER_STOP)
+#define   SYSVIEW_EVTMASK_IDLE              (1 << SYSVIEW_EVTID_IDLE)
+#define   SYSVIEW_EVTMASK_ISR_TO_SCHEDULER  (1 << SYSVIEW_EVTID_ISR_TO_SCHEDULER)
+#define   SYSVIEW_EVTMASK_TIMER_ENTER       (1 << SYSVIEW_EVTID_TIMER_ENTER)
+#define   SYSVIEW_EVTMASK_TIMER_EXIT        (1 << SYSVIEW_EVTID_TIMER_EXIT)
+#define   SYSVIEW_EVTMASK_STACK_INFO        (1 << SYSVIEW_EVTID_STACK_INFO)
+#define   SYSVIEW_EVTMASK_MODULEDESC        (1 << SYSVIEW_EVTID_MODULEDESC)
+
+#define   SYSVIEW_EVTMASK_INIT              (1 << SYSVIEW_EVTID_INIT)
+#define   SYSVIEW_EVTMASK_NAME_RESOURCE     (1 << SYSVIEW_EVTID_NAME_RESOURCE)
+#define   SYSVIEW_EVTMASK_PRINT_FORMATTED   (1 << SYSVIEW_EVTID_PRINT_FORMATTED)
+#define   SYSVIEW_EVTMASK_NUMMODULES        (1 << SYSVIEW_EVTID_NUMMODULES)
+#define   SYSVIEW_EVTMASK_END_CALL          (1 << SYSVIEW_EVTID_END_CALL)
+#define   SYSVIEW_EVTMASK_TASK_TERMINATE    (1 << SYSVIEW_EVTID_TASK_TERMINATE)
+
+#define   SYSVIEW_EVTMASK_EX                (1 << SYSVIEW_EVTID_EX)
+
+#define   SYSVIEW_EVTMASK_ALL_INTERRUPTS    ( SYSVIEW_EVTMASK_ISR_ENTER           \
+                                            | SYSVIEW_EVTMASK_ISR_EXIT            \
+                                            | SYSVIEW_EVTMASK_ISR_TO_SCHEDULER)
+#define   SYSVIEW_EVTMASK_ALL_TASKS         ( SYSVIEW_EVTMASK_TASK_START_EXEC     \
+                                            | SYSVIEW_EVTMASK_TASK_STOP_EXEC      \
+                                            | SYSVIEW_EVTMASK_TASK_START_READY    \
+                                            | SYSVIEW_EVTMASK_TASK_STOP_READY     \
+                                            | SYSVIEW_EVTMASK_TASK_CREATE         \
+                                            | SYSVIEW_EVTMASK_TASK_INFO           \
+                                            | SYSVIEW_EVTMASK_STACK_INFO          \
+                                            | SYSVIEW_EVTMASK_TASK_TERMINATE)
+
+/*********************************************************************
+*
+*       Structures
+*
+**********************************************************************
+*/
+
+typedef struct {
+  U32          TaskID;
+  const char*  sName;
+  U32          Prio;
+  U32          StackBase;
+  U32          StackSize;
+} SEGGER_SYSVIEW_TASKINFO;
+
+typedef struct SEGGER_SYSVIEW_MODULE_STRUCT SEGGER_SYSVIEW_MODULE;
+
+struct SEGGER_SYSVIEW_MODULE_STRUCT {
+  const char*                   sModule;
+        U32                     NumEvents;
+        U32                     EventOffset;
+        void                    (*pfSendModuleDesc)(void);
+        SEGGER_SYSVIEW_MODULE*  pNext;
+};
+
+typedef void (SEGGER_SYSVIEW_SEND_SYS_DESC_FUNC)(void);
+
+
+/*********************************************************************
+*
+*       Global data
+*
+**********************************************************************
+*/
+
+#ifdef   EXTERN
+  #undef EXTERN
+#endif
+
+#ifndef SEGGER_SYSVIEW_C       // Defined in SEGGER_SYSVIEW.c which includes this header beside other C-files
+  #define EXTERN extern
+#else
+  #define EXTERN
+#endif
+
+EXTERN unsigned int SEGGER_SYSVIEW_TickCnt;
+EXTERN unsigned int SEGGER_SYSVIEW_InterruptId;
+
+#undef EXTERN
+
+/*********************************************************************
+*
+*       API functions
+*
+**********************************************************************
+*/
+
+typedef struct {
+  U64  (*pfGetTime)      (void);
+  void (*pfSendTaskList) (void);
+} SEGGER_SYSVIEW_OS_API;
+
+/*********************************************************************
+*
+*       Control and initialization functions
+*/
+void SEGGER_SYSVIEW_Init                          (U32 SysFreq, U32 CPUFreq, const SEGGER_SYSVIEW_OS_API *pOSAPI, SEGGER_SYSVIEW_SEND_SYS_DESC_FUNC pfSendSysDesc);
+void SEGGER_SYSVIEW_SetRAMBase                    (U32 RAMBaseAddress);
+void SEGGER_SYSVIEW_Start                         (void);
+void SEGGER_SYSVIEW_Stop                          (void);
+void SEGGER_SYSVIEW_GetSysDesc                    (void);
+void SEGGER_SYSVIEW_SendTaskList                  (void);
+void SEGGER_SYSVIEW_SendTaskInfo                  (const SEGGER_SYSVIEW_TASKINFO* pInfo);
+void SEGGER_SYSVIEW_SendSysDesc                   (const char* sSysDesc);
+int  SEGGER_SYSVIEW_IsStarted                     (void);
+int  SEGGER_SYSVIEW_GetChannelID                  (void);
+
+/*********************************************************************
+*
+*       Event recording functions
+*/
+void SEGGER_SYSVIEW_RecordVoid                    (unsigned int EventId);
+void SEGGER_SYSVIEW_RecordU32                     (unsigned int EventId, U32 Para0);
+void SEGGER_SYSVIEW_RecordU32x2                   (unsigned int EventId, U32 Para0, U32 Para1);
+void SEGGER_SYSVIEW_RecordU32x3                   (unsigned int EventId, U32 Para0, U32 Para1, U32 Para2);
+void SEGGER_SYSVIEW_RecordU32x4                   (unsigned int EventId, U32 Para0, U32 Para1, U32 Para2, U32 Para3);
+void SEGGER_SYSVIEW_RecordU32x5                   (unsigned int EventId, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4);
+void SEGGER_SYSVIEW_RecordU32x6                   (unsigned int EventId, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4, U32 Para5);
+void SEGGER_SYSVIEW_RecordU32x7                   (unsigned int EventId, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4, U32 Para5, U32 Para6);
+void SEGGER_SYSVIEW_RecordU32x8                   (unsigned int EventId, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4, U32 Para5, U32 Para6, U32 Para7);
+void SEGGER_SYSVIEW_RecordU32x9                   (unsigned int EventId, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4, U32 Para5, U32 Para6, U32 Para7, U32 Para8);
+void SEGGER_SYSVIEW_RecordU32x10                  (unsigned int EventId, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4, U32 Para5, U32 Para6, U32 Para7, U32 Para8, U32 Para9);
+void SEGGER_SYSVIEW_RecordString                  (unsigned int EventId, const char* pString);
+void SEGGER_SYSVIEW_RecordSystime                 (void);
+void SEGGER_SYSVIEW_RecordEnterISR                (void);
+void SEGGER_SYSVIEW_RecordExitISR                 (void);
+void SEGGER_SYSVIEW_RecordExitISRToScheduler      (void);
+void SEGGER_SYSVIEW_RecordEnterTimer              (U32 TimerId);
+void SEGGER_SYSVIEW_RecordExitTimer               (void);
+void SEGGER_SYSVIEW_RecordEndCall                 (unsigned int EventID);
+void SEGGER_SYSVIEW_RecordEndCallU32              (unsigned int EventID, U32 Para0);
+
+void SEGGER_SYSVIEW_OnIdle                        (void);
+void SEGGER_SYSVIEW_OnTaskCreate                  (U32 TaskId);
+void SEGGER_SYSVIEW_OnTaskTerminate               (U32 TaskId);
+void SEGGER_SYSVIEW_OnTaskStartExec               (U32 TaskId);
+void SEGGER_SYSVIEW_OnTaskStopExec                (void);
+void SEGGER_SYSVIEW_OnTaskStartReady              (U32 TaskId);
+void SEGGER_SYSVIEW_OnTaskStopReady               (U32 TaskId, unsigned int Cause);
+void SEGGER_SYSVIEW_MarkStart                     (unsigned int MarkerId);
+void SEGGER_SYSVIEW_MarkStop                      (unsigned int MarkerId);
+void SEGGER_SYSVIEW_Mark                          (unsigned int MarkerId);
+void SEGGER_SYSVIEW_NameMarker                    (unsigned int MarkerId, const char* sName);
+
+void SEGGER_SYSVIEW_NameResource                  (U32 ResourceId, const char* sName);
+
+int  SEGGER_SYSVIEW_SendPacket                    (U8* pPacket, U8* pPayloadEnd, unsigned int EventId);
+
+/*********************************************************************
+*
+*       Event parameter encoding functions
+*/
+U8*  SEGGER_SYSVIEW_EncodeU32                     (U8* pPayload, U32 Value);
+U8*  SEGGER_SYSVIEW_EncodeData                    (U8* pPayload, const char* pSrc, unsigned int Len);
+U8*  SEGGER_SYSVIEW_EncodeString                  (U8* pPayload, const char* s, unsigned int MaxLen);
+U8*  SEGGER_SYSVIEW_EncodeId                      (U8* pPayload, U32 Id);
+U32  SEGGER_SYSVIEW_ShrinkId                      (U32 Id);
+
+
+/*********************************************************************
+*
+*       Middleware module registration
+*/
+void SEGGER_SYSVIEW_RegisterModule                (SEGGER_SYSVIEW_MODULE* pModule);
+void SEGGER_SYSVIEW_RecordModuleDescription       (const SEGGER_SYSVIEW_MODULE* pModule, const char* sDescription);
+void SEGGER_SYSVIEW_SendModule                    (U8 ModuleId);
+void SEGGER_SYSVIEW_SendModuleDescription         (void);
+void SEGGER_SYSVIEW_SendNumModules                (void);
+
+/*********************************************************************
+*
+*       printf-Style functions
+*/
+#ifndef SEGGER_SYSVIEW_EXCLUDE_PRINTF // Define in project to avoid warnings about variable parameter list
+void SEGGER_SYSVIEW_PrintfHostEx                  (const char* s, U32 Options, ...);
+void SEGGER_SYSVIEW_PrintfTargetEx                (const char* s, U32 Options, ...);
+void SEGGER_SYSVIEW_PrintfHost                    (const char* s, ...);
+void SEGGER_SYSVIEW_PrintfTarget                  (const char* s, ...);
+void SEGGER_SYSVIEW_WarnfHost                     (const char* s, ...);
+void SEGGER_SYSVIEW_WarnfTarget                   (const char* s, ...);
+void SEGGER_SYSVIEW_ErrorfHost                    (const char* s, ...);
+void SEGGER_SYSVIEW_ErrorfTarget                  (const char* s, ...);
+#endif
+
+void SEGGER_SYSVIEW_Print                         (const char* s);
+void SEGGER_SYSVIEW_Warn                          (const char* s);
+void SEGGER_SYSVIEW_Error                         (const char* s);
+
+/*********************************************************************
+*
+*       Run-time configuration functions
+*/
+void SEGGER_SYSVIEW_EnableEvents                  (U32 EnableMask);
+void SEGGER_SYSVIEW_DisableEvents                 (U32 DisableMask);
+
+/*********************************************************************
+*
+*       Application-provided functions
+*/
+void SEGGER_SYSVIEW_Conf                          (void);
+U32  SEGGER_SYSVIEW_X_GetTimestamp                (void);
+U32  SEGGER_SYSVIEW_X_GetInterruptId              (void);
+
+void SEGGER_SYSVIEW_X_StartComm                   (void);
+void SEGGER_SYSVIEW_X_OnEventRecorded             (unsigned NumBytes);
+
+#ifdef __cplusplus
+}
+#endif
+
+/*********************************************************************
+*
+*       Compatibility API defines
+*/
+#define SEGGER_SYSVIEW_OnUserStart      SEGGER_SYSVIEW_MarkStart
+#define SEGGER_SYSVIEW_OnUserStop       SEGGER_SYSVIEW_MarkStop
+
+#endif
+
+/*************************** End of file ****************************/

+ 85 - 0
code/debug/SEGGER/SEGGER_SYSVIEW_Conf.h

@@ -0,0 +1,85 @@
+/*********************************************************************
+*                    SEGGER Microcontroller GmbH                     *
+*                        The Embedded Experts                        *
+**********************************************************************
+*                                                                    *
+*            (c) 1995 - 2021 SEGGER Microcontroller GmbH             *
+*                                                                    *
+*       www.segger.com     Support: support@segger.com               *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+*       SEGGER SystemView * Real-time application analysis           *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+* All rights reserved.                                               *
+*                                                                    *
+* SEGGER strongly recommends to not make any changes                 *
+* to or modify the source code of this software in order to stay     *
+* compatible with the SystemView and RTT protocol, and J-Link.       *
+*                                                                    *
+* Redistribution and use in source and binary forms, with or         *
+* without modification, are permitted provided that the following    *
+* condition is met:                                                  *
+*                                                                    *
+* o Redistributions of source code must retain the above copyright   *
+*   notice, this condition and the following disclaimer.             *
+*                                                                    *
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND             *
+* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,        *
+* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF           *
+* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE           *
+* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR           *
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT  *
+* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;    *
+* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF      *
+* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT          *
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE  *
+* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH   *
+* DAMAGE.                                                            *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+*       SystemView version: 3.32                                    *
+*                                                                    *
+**********************************************************************
+-------------------------- END-OF-HEADER -----------------------------
+
+File    : SEGGER_SYSVIEW_Conf.h
+Purpose : SEGGER SystemView configuration file.
+          Set defines which deviate from the defaults (see SEGGER_SYSVIEW_ConfDefaults.h) here.          
+Revision: $Rev: 21292 $
+
+Additional information:
+  Required defines which must be set are:
+    SEGGER_SYSVIEW_GET_TIMESTAMP
+    SEGGER_SYSVIEW_GET_INTERRUPT_ID
+  For known compilers and cores, these might be set to good defaults
+  in SEGGER_SYSVIEW_ConfDefaults.h.
+  
+  SystemView needs a (nestable) locking mechanism.
+  If not defined, the RTT locking mechanism is used,
+  which then needs to be properly configured.
+*/
+
+#ifndef SEGGER_SYSVIEW_CONF_H
+#define SEGGER_SYSVIEW_CONF_H
+
+/*********************************************************************
+*
+*       Defines, configurable
+*
+**********************************************************************
+*/
+
+/*********************************************************************
+* TODO: Add your defines here.                                       *
+**********************************************************************
+*/
+
+
+#endif  // SEGGER_SYSVIEW_CONF_H
+
+/*************************** End of file ****************************/

+ 579 - 0
code/debug/SEGGER/SEGGER_SYSVIEW_ConfDefaults.h

@@ -0,0 +1,579 @@
+/*********************************************************************
+*                    SEGGER Microcontroller GmbH                     *
+*                        The Embedded Experts                        *
+**********************************************************************
+*                                                                    *
+*            (c) 1995 - 2021 SEGGER Microcontroller GmbH             *
+*                                                                    *
+*       www.segger.com     Support: support@segger.com               *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+*       SEGGER SystemView * Real-time application analysis           *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+* All rights reserved.                                               *
+*                                                                    *
+* SEGGER strongly recommends to not make any changes                 *
+* to or modify the source code of this software in order to stay     *
+* compatible with the SystemView and RTT protocol, and J-Link.       *
+*                                                                    *
+* Redistribution and use in source and binary forms, with or         *
+* without modification, are permitted provided that the following    *
+* condition is met:                                                  *
+*                                                                    *
+* o Redistributions of source code must retain the above copyright   *
+*   notice, this condition and the following disclaimer.             *
+*                                                                    *
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND             *
+* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,        *
+* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF           *
+* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE           *
+* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR           *
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT  *
+* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;    *
+* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF      *
+* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT          *
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE  *
+* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH   *
+* DAMAGE.                                                            *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+*       SystemView version: 3.32                                    *
+*                                                                    *
+**********************************************************************
+-------------------------- END-OF-HEADER -----------------------------
+File    : SEGGER_SYSVIEW_ConfDefaults.h
+Purpose : Defines defaults for configurable defines used in
+          SEGGER SystemView.
+Revision: $Rev: 26230 $
+*/
+
+#ifndef SEGGER_SYSVIEW_CONFDEFAULTS_H
+#define SEGGER_SYSVIEW_CONFDEFAULTS_H
+
+/*********************************************************************
+*
+*       #include Section
+*
+**********************************************************************
+*/
+
+#include "SEGGER_SYSVIEW_Conf.h"
+#include "SEGGER_RTT_Conf.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*********************************************************************
+*
+*       Defines, fixed
+*
+**********************************************************************
+*/
+//
+// Use auto-detection for SEGGER_SYSVIEW_CORE define
+// based on compiler-/toolchain-specific defines
+// to define SEGGER_SYSVIEW_GET_INTERRUPT_ID and SEGGER_SYSVIEW_GET_TIMESTAMP
+//
+#define SEGGER_SYSVIEW_CORE_OTHER   0
+#define SEGGER_SYSVIEW_CORE_CM0     1 // Cortex-M0/M0+/M1
+#define SEGGER_SYSVIEW_CORE_CM3     2 // Cortex-M3/M4/M7
+#define SEGGER_SYSVIEW_CORE_RX      3 // Renesas RX
+#ifndef SEGGER_SYSVIEW_CORE
+  #if (defined __SES_ARM) || (defined __CROSSWORKS_ARM) || (defined __SEGGER_CC__) || (defined __GNUC__) || (defined __clang__)
+    #if (defined __ARM_ARCH_6M__) || (defined __ARM_ARCH_8M_BASE__)
+      #define SEGGER_SYSVIEW_CORE SEGGER_SYSVIEW_CORE_CM0
+    #elif (defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) || defined(__ARM_ARCH_8M_MAIN__))
+      #define SEGGER_SYSVIEW_CORE SEGGER_SYSVIEW_CORE_CM3
+    #endif
+  #elif defined(__ICCARM__)
+    #if (defined (__ARM6M__)          && (__CORE__ == __ARM6M__))          \
+     || (defined (__ARM8M_BASELINE__) && (__CORE__ == __ARM8M_BASELINE__))
+      #define SEGGER_SYSVIEW_CORE SEGGER_SYSVIEW_CORE_CM0
+    #elif (defined (__ARM7EM__)         && (__CORE__ == __ARM7EM__))         \
+       || (defined (__ARM7M__)          && (__CORE__ == __ARM7M__))          \
+       || (defined (__ARM8M_MAINLINE__) && (__CORE__ == __ARM8M_MAINLINE__)) \
+       || (defined (__ARM8M_MAINLINE__) && (__CORE__ == __ARM8M_MAINLINE__))
+      #define SEGGER_SYSVIEW_CORE SEGGER_SYSVIEW_CORE_CM3
+    #endif
+  #elif defined(__CC_ARM)
+    #if (defined(__TARGET_ARCH_6S_M))
+      #define SEGGER_SYSVIEW_CORE SEGGER_SYSVIEW_CORE_CM0
+    #elif (defined(__TARGET_ARCH_7_M) || defined(__TARGET_ARCH_7E_M))
+      #define SEGGER_SYSVIEW_CORE SEGGER_SYSVIEW_CORE_CM3
+    #endif
+  #elif defined(__TI_ARM__)
+    #ifdef __TI_ARM_V6M0__
+      #define SEGGER_SYSVIEW_CORE SEGGER_SYSVIEW_CORE_CM0
+    #elif (defined(__TI_ARM_V7M3__) || defined(__TI_ARM_V7M4__))
+      #define SEGGER_SYSVIEW_CORE SEGGER_SYSVIEW_CORE_CM3
+    #endif
+  #elif defined(__ICCRX__)
+    #define SEGGER_SYSVIEW_CORE SEGGER_SYSVIEW_CORE_RX
+  #elif defined(__RX)
+    #define SEGGER_SYSVIEW_CORE SEGGER_SYSVIEW_CORE_RX
+  #endif
+
+  #ifndef   SEGGER_SYSVIEW_CORE
+    #define SEGGER_SYSVIEW_CORE SEGGER_SYSVIEW_CORE_OTHER
+  #endif
+#endif
+
+
+/*********************************************************************
+*
+*       Defines, defaults
+*
+**********************************************************************
+*/
+/*********************************************************************
+*
+*       Define: SEGGER_SYSVIEW_APP_NAME
+*
+*  Description
+*    The application name to be displayed in SystemView.
+*  Default
+*    "SystemView-enabled Application"
+*  Notes
+*    Convenience define to be used for SEGGER_SYSVIEW_SendSysDesc().
+*/
+#ifndef   SEGGER_SYSVIEW_APP_NAME
+  #define SEGGER_SYSVIEW_APP_NAME                 "SystemView-enabled Application"
+#endif
+
+/*********************************************************************
+*
+*       Define: SEGGER_SYSVIEW_DEVICE_NAME
+*
+*  Description
+*    The target device name to be displayed in SystemView.
+*  Default
+*    "undefined device"
+*  Notes
+*    Convenience define to be used for SEGGER_SYSVIEW_SendSysDesc().
+*/
+#ifndef   SEGGER_SYSVIEW_DEVICE_NAME
+  #define SEGGER_SYSVIEW_DEVICE_NAME              "undefined device"
+#endif
+
+/*********************************************************************
+*
+*       Define: SEGGER_SYSVIEW_GET_INTERRUPT_ID()
+*
+*  Description
+*    Function macro to retrieve the Id of the currently active
+*    interrupt.
+*  Default
+*    Call user-supplied function SEGGER_SYSVIEW_X_GetInterruptId().
+*  Notes
+*    For some known compilers and cores, a ready-to-use, core-specific
+*    default is set.
+*    ARMv7M: Read ICSR[8:0] (active vector)
+*    ARMv6M: Read ICSR[5:0] (active vector)
+*/
+#ifndef SEGGER_SYSVIEW_GET_INTERRUPT_ID
+  #if SEGGER_SYSVIEW_CORE == SEGGER_SYSVIEW_CORE_CM3
+    #define SEGGER_SYSVIEW_GET_INTERRUPT_ID()     ((*(U32*)(0xE000ED04)) & 0x1FF)         // Get the currently active interrupt Id. (i.e. read Cortex-M ICSR[8:0] = active vector)
+  #elif SEGGER_SYSVIEW_CORE == SEGGER_SYSVIEW_CORE_CM0
+    #if defined(__ICCARM__)
+      #if (__VER__ > 6010000)
+        #define SEGGER_SYSVIEW_GET_INTERRUPT_ID() (__get_IPSR())                          // Workaround for IAR, which might do a byte-access to 0xE000ED04. Read IPSR instead.
+      #else
+        #define SEGGER_SYSVIEW_GET_INTERRUPT_ID() ((*(U32*)(0xE000ED04)) & 0x3F)          // Older versions of IAR do not include __get_IPSR, but might also not optimize to byte-access.
+      #endif
+    #else
+      #define SEGGER_SYSVIEW_GET_INTERRUPT_ID()   ((*(U32*)(0xE000ED04)) & 0x3F)          // Get the currently active interrupt Id. (i.e. read Cortex-M ICSR[5:0] = active vector)
+    #endif
+  #else
+    #define SEGGER_SYSVIEW_GET_INTERRUPT_ID()     SEGGER_SYSVIEW_X_GetInterruptId()       // Get the currently active interrupt Id from the user-provided function.
+  #endif
+#endif
+
+/*********************************************************************
+*
+*       Define: SEGGER_SYSVIEW_GET_TIMESTAMP()
+*
+*  Description
+*    Function macro to retrieve a system timestamp for SYSVIEW events.
+*  Default
+*    Call user-supplied function SEGGER_SYSVIEW_X_GetTimestamp().
+*  Notes
+*    For some known compilers and cores, a ready-to-use, core-specific
+*    default is set.
+*    ARMv7M: Read Cortex-M Cycle Count register.
+*
+*    The system timestamp clock frequency has to be passed in
+*    SEGGER_SYSVIEW_Init().
+*/
+#ifndef SEGGER_SYSVIEW_GET_TIMESTAMP
+  #if defined (SEGGER_SYSVIEW_CORE) && (SEGGER_SYSVIEW_CORE == SEGGER_SYSVIEW_CORE_CM3)
+    #define SEGGER_SYSVIEW_GET_TIMESTAMP()        (*(U32 *)(0xE0001004))                  // Retrieve a system timestamp. Cortex-M cycle counter.
+  #else
+    #define SEGGER_SYSVIEW_GET_TIMESTAMP()        SEGGER_SYSVIEW_X_GetTimestamp()         // Retrieve a system timestamp via user-defined function
+  #endif
+#endif
+
+/*********************************************************************
+*
+*       Define: SEGGER_SYSVIEW_TIMESTAMP_BITS
+*
+*  Description
+*    Number of valid (low-order) bits delivered in system timestamp.
+*  Default
+*    32
+*  Notes
+*    Value has to match system timestamp clock source.
+*/
+// Define number of valid bits low-order delivered by clock source.
+#ifndef   SEGGER_SYSVIEW_TIMESTAMP_BITS
+  #define SEGGER_SYSVIEW_TIMESTAMP_BITS           32
+#endif
+
+/*********************************************************************
+*
+*       Define: SEGGER_SYSVIEW_RTT_CHANNEL
+*
+*  Description
+*    The RTT channel that SystemView will use.
+*  Default
+*    0: Auto selection.
+*  Notes
+*    Value has to be lower than SEGGER_RTT_MAX_NUM_UP_BUFFERS.
+*/
+#ifndef   SEGGER_SYSVIEW_RTT_CHANNEL
+  #define SEGGER_SYSVIEW_RTT_CHANNEL              0
+#endif
+// Sanity check of RTT channel
+#if (SEGGER_SYSVIEW_RTT_CHANNEL == 0) && (SEGGER_RTT_MAX_NUM_UP_BUFFERS < 2)
+  #error "SEGGER_RTT_MAX_NUM_UP_BUFFERS in SEGGER_RTT_Conf.h has to be > 1!"
+#elif (SEGGER_SYSVIEW_RTT_CHANNEL >= SEGGER_RTT_MAX_NUM_UP_BUFFERS)
+  #error "SEGGER_RTT_MAX_NUM_UP_BUFFERS  in SEGGER_RTT_Conf.h has to be > SEGGER_SYSVIEW_RTT_CHANNEL!"
+#endif
+
+/*********************************************************************
+*
+*       Define: SEGGER_SYSVIEW_RTT_BUFFER_SIZE
+*
+*  Description
+*    Number of bytes that SystemView uses for the RTT buffer.
+*  Default
+*    1024
+*/
+#ifndef   SEGGER_SYSVIEW_RTT_BUFFER_SIZE
+  #define SEGGER_SYSVIEW_RTT_BUFFER_SIZE          1024
+#endif
+
+/*********************************************************************
+*
+*       Define: SEGGER_SYSVIEW_SECTION
+*
+*  Description
+*    Section to place the SystemView RTT Buffer into.
+*  Default
+*    undefined: Do not place into a specific section.
+*  Notes
+*    If SEGGER_RTT_SECTION is defined, the default changes to use
+*    this section for the SystemView RTT Buffer, too.
+*/
+#if !(defined SEGGER_SYSVIEW_SECTION) && (defined SEGGER_RTT_SECTION)
+  #define SEGGER_SYSVIEW_SECTION                  SEGGER_RTT_SECTION
+#endif
+
+/*********************************************************************
+*
+*       Define: SEGGER_SYSVIEW_CPU_CACHE_LINE_SIZE
+*
+*  Description
+*    Largest cache line size (in bytes) in the target system.
+*  Default
+*    0
+*  Notes
+*    Required in systems with caches to make sure that the SystemView
+*    RTT buffer can be aligned accordingly.
+*/
+#ifndef SEGGER_SYSVIEW_CPU_CACHE_LINE_SIZE
+  #define SEGGER_SYSVIEW_CPU_CACHE_LINE_SIZE      0
+#endif
+
+/*********************************************************************
+*
+*       Define: SEGGER_SYSVIEW_ID_BASE
+*
+*  Description
+*    Lowest Id reported by the application.
+*  Default
+*    0
+*  Notes
+*    Value is usually subtracted from mailboxes, semaphores, tasks,
+*    .... addresses, to compress event parameters.
+*    Should be the lowest RAM address of the system.
+*/
+#ifndef   SEGGER_SYSVIEW_ID_BASE
+  #define SEGGER_SYSVIEW_ID_BASE                  0
+#endif
+
+/*********************************************************************
+*
+*       Define: SEGGER_SYSVIEW_ID_SHIFT
+*
+*  Description
+*    Number of bits to shift Ids.
+*  Default
+*    0
+*  Notes
+*    Ids are shifted to compress event parameters.
+*    Should match the alignment of Ids (addresses),
+*    e.g. 2 when Ids are 4 byte aligned.
+*/
+#ifndef   SEGGER_SYSVIEW_ID_SHIFT
+  #define SEGGER_SYSVIEW_ID_SHIFT                 0
+#endif
+
+/*********************************************************************
+*
+*       Define: SEGGER_SYSVIEW_MAX_ARGUMENTS
+*
+*  Description
+*    Maximum number of arguments which are handled with SystemView
+*    print routines or may be encoded in one recording function.
+*    routines.
+*  Default
+*    16
+*/
+#ifndef   SEGGER_SYSVIEW_MAX_ARGUMENTS
+  #define SEGGER_SYSVIEW_MAX_ARGUMENTS            16
+#endif
+
+/*********************************************************************
+*
+*       Define: SEGGER_SYSVIEW_MAX_STRING_LEN
+*
+*  Description
+*    Maximum string length which can be used in SystemView print and
+*    system description routines.
+*  Default
+*    128
+*/
+#ifndef   SEGGER_SYSVIEW_MAX_STRING_LEN
+  #define SEGGER_SYSVIEW_MAX_STRING_LEN           128
+#endif
+
+/*********************************************************************
+*
+*       Define: SEGGER_SYSVIEW_SUPPORT_LONG_ID
+*
+*  Description
+*    It set, support enconding Evend Ids longer than 14 bit.
+*  Default
+*    1
+*/
+#ifndef   SEGGER_SYSVIEW_SUPPORT_LONG_ID
+  #define SEGGER_SYSVIEW_SUPPORT_LONG_ID          1
+#endif
+
+/*********************************************************************
+*
+*       Define: SEGGER_SYSVIEW_SUPPORT_LONG_DATA
+*
+*  Description
+*    It set, support enconding event data longer than 14 bit.
+*  Default
+*    0
+*/
+#ifndef   SEGGER_SYSVIEW_SUPPORT_LONG_DATA
+  #define SEGGER_SYSVIEW_SUPPORT_LONG_DATA        0
+#endif
+
+/*********************************************************************
+*
+*       Define: SEGGER_SYSVIEW_PRINTF_IMPLICIT_FORMAT
+*
+*  Description
+*    If enabled, on SEGGER_SYSVIEW_PrintHost, check the format string
+*    and if it includes unsupported formatters, use formatting on the
+*    target instead.
+*  Default
+*    0: Disabled.
+*/
+#ifndef   SEGGER_SYSVIEW_PRINTF_IMPLICIT_FORMAT
+  #define SEGGER_SYSVIEW_PRINTF_IMPLICIT_FORMAT   0
+#endif
+
+/*********************************************************************
+*
+*       Define: SEGGER_SYSVIEW_USE_INTERNAL_RECORDER
+*
+*  Description
+*    If set, an internal recorder, such as UART or IP is used.
+*  Default
+*    0: Disabled.
+*  Notes
+*    Convenience define to be used by SEGGER_SYSVIEW_Conf(),
+*    such as in embOS configuration to enable Cortex-M cycle counter.
+*/
+#ifndef   SEGGER_SYSVIEW_USE_INTERNAL_RECORDER
+  #define SEGGER_SYSVIEW_USE_INTERNAL_RECORDER    0
+#endif
+
+/*********************************************************************
+*
+*       Define: SEGGER_SYSVIEW_CAN_RESTART
+*
+*  Description
+*    If enabled, send the SystemView start sequence on every start
+*    command, not just on the first one.
+*    Enables restart when SystemView disconnected unexpectedly.
+*  Default
+*    1: Enabled
+*/
+#ifndef   SEGGER_SYSVIEW_CAN_RESTART
+  #define SEGGER_SYSVIEW_CAN_RESTART              1
+#endif
+
+/*********************************************************************
+*
+*       Define: SEGGER_SYSVIEW_START_ON_INIT
+*
+*  Description
+*    Enable calling SEGGER_SYSVIEW_Start() after initialization.
+*  Default
+*    0: Disabled.
+*  Notes
+*    Convenience define to be used by SEGGER_SYSVIEW_Conf(),
+*    such as in embOS configuration.
+*/
+#ifndef   SEGGER_SYSVIEW_START_ON_INIT
+  #define SEGGER_SYSVIEW_START_ON_INIT            0
+#endif
+
+/*********************************************************************
+*
+*       Define: SEGGER_SYSVIEW_USE_STATIC_BUFFER
+*
+*  Description
+*    If enabled, use a static buffer instead of a buffer on the stack
+*    for SystemView event packets.
+*  Default
+*    1: Enabled.
+*  Notes
+*    If enabled, the static memory use by SystemView is increased by
+*    the maximum packet size. SystemView is locked on entry of a
+*    recording function.
+*    If disabled, the stack usage by SystemView recording functions
+*    might be increased by up to the maximum packet size. SystemView
+*    is locked when writing the packet to the RTT buffer.
+*/
+#ifndef   SEGGER_SYSVIEW_USE_STATIC_BUFFER
+  #define SEGGER_SYSVIEW_USE_STATIC_BUFFER        1
+#endif
+
+/*********************************************************************
+*
+*       Define: SEGGER_SYSVIEW_MAX_PACKET_SIZE
+*
+*  Description
+*    Maximum packet size for a SystemView event.
+*  Default
+*    Automatically calculated.
+*  Notes
+*    The maximum packet size is mainly defined by the maximum string
+*    length and the maximum number of arguments.
+*/
+#ifndef   SEGGER_SYSVIEW_MAX_PACKET_SIZE
+  #define SEGGER_SYSVIEW_MAX_PACKET_SIZE          (SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_MAX_STRING_LEN + 2 * SEGGER_SYSVIEW_QUANTA_U32 + SEGGER_SYSVIEW_MAX_ARGUMENTS * SEGGER_SYSVIEW_QUANTA_U32)
+#endif
+
+/*********************************************************************
+*
+*       Define: SEGGER_SYSVIEW_POST_MORTEM_MODE
+*
+*  Description
+*    If enabled, SystemView records for post-mortem analysis instead
+*    of real-time analysis.
+*  Default
+*    0: Disabled.
+*  Notes
+*    For more information refer to
+*    https://www.segger.com/products/development-tools/systemview/technology/post-mortem-mode
+*/
+#ifndef   SEGGER_SYSVIEW_POST_MORTEM_MODE
+  #define SEGGER_SYSVIEW_POST_MORTEM_MODE         0
+#endif
+
+/*********************************************************************
+*
+*       Define: SEGGER_SYSVIEW_SYNC_PERIOD_SHIFT
+*
+*  Description
+*    Configure how frequently syncronization is sent in post-mortem
+*    mode.
+*  Default
+*    8: (1 << 8) = Every 256 Events.
+*  Notes
+*    In post-mortem mode, at least one sync has to be in the RTT buffer.
+*    Recommended sync frequency: Buffer Size / 16
+*    For more information refer to
+*    https://www.segger.com/products/development-tools/systemview/technology/post-mortem-mode
+*/
+#ifndef   SEGGER_SYSVIEW_SYNC_PERIOD_SHIFT
+  #define SEGGER_SYSVIEW_SYNC_PERIOD_SHIFT        8
+#endif
+
+/*********************************************************************
+*
+*       Define: SEGGER_SYSVIEW_ON_EVENT_RECORDED()
+*
+*  Description
+*    Function macro to notify recorder about a new event in buffer.
+*  Default
+*    undefined: Do not notify recorder.
+*  Notes
+*    Used for non-J-Link recorder,
+*    such as to enable transmission via UART or notify IP task.
+*/
+#ifndef   SEGGER_SYSVIEW_ON_EVENT_RECORDED
+  #define SEGGER_SYSVIEW_ON_EVENT_RECORDED(NumBytes)
+#endif
+
+/*********************************************************************
+*
+*       Define: SEGGER_SYSVIEW_LOCK()
+*
+*  Description
+*    Function macro to (nestable) lock SystemView recording.
+*  Default
+*    Use RTT Locking mechanism (defined by SEGGER_RTT_LOCK()).
+*  Notes
+*    If SystemView recording is not locked, recording events from
+*    interrupts and tasks may lead to unpredictable, undefined, event
+*    data.
+*/
+#ifndef   SEGGER_SYSVIEW_LOCK
+  #define SEGGER_SYSVIEW_LOCK()                   SEGGER_RTT_LOCK()
+#endif
+
+/*********************************************************************
+*
+*       Define: SEGGER_SYSVIEW_UNLOCK
+*
+*  Description
+*    Function macro to unlock SystemView recording.
+*  Default
+*    Use RTT Unlocking mechanism (defined by SEGGER_RTT_UNLOCK()).
+*/
+#ifndef   SEGGER_SYSVIEW_UNLOCK
+  #define SEGGER_SYSVIEW_UNLOCK()                 SEGGER_RTT_UNLOCK()
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+/*************************** End of file ****************************/

+ 104 - 0
code/debug/SEGGER/SEGGER_SYSVIEW_Config_FreeRTOS.c

@@ -0,0 +1,104 @@
+/*********************************************************************
+*                    SEGGER Microcontroller GmbH                     *
+*                        The Embedded Experts                        *
+**********************************************************************
+*                                                                    *
+*            (c) 1995 - 2021 SEGGER Microcontroller GmbH             *
+*                                                                    *
+*       www.segger.com     Support: support@segger.com               *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+*       SEGGER SystemView * Real-time application analysis           *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+* All rights reserved.                                               *
+*                                                                    *
+* SEGGER strongly recommends to not make any changes                 *
+* to or modify the source code of this software in order to stay     *
+* compatible with the SystemView and RTT protocol, and J-Link.       *
+*                                                                    *
+* Redistribution and use in source and binary forms, with or         *
+* without modification, are permitted provided that the following    *
+* condition is met:                                                  *
+*                                                                    *
+* o Redistributions of source code must retain the above copyright   *
+*   notice, this condition and the following disclaimer.             *
+*                                                                    *
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND             *
+* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,        *
+* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF           *
+* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE           *
+* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR           *
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT  *
+* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;    *
+* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF      *
+* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT          *
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE  *
+* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH   *
+* DAMAGE.                                                            *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+*       SystemView version: 3.32                                    *
+*                                                                    *
+**********************************************************************
+-------------------------- END-OF-HEADER -----------------------------
+
+File    : SEGGER_SYSVIEW_Config_FreeRTOS.c
+Purpose : Sample setup configuration of SystemView with FreeRTOS.
+Revision: $Rev: 7745 $
+*/
+#include "FreeRTOS.h"
+#include "SEGGER_SYSVIEW.h"
+
+extern const SEGGER_SYSVIEW_OS_API SYSVIEW_X_OS_TraceAPI;
+
+/*********************************************************************
+*
+*       Defines, configurable
+*
+**********************************************************************
+*/
+// The application name to be displayed in SystemViewer
+#define SYSVIEW_APP_NAME        "FreeRTOS Demo Application"
+
+// The target device name
+#define SYSVIEW_DEVICE_NAME     "Cortex-M4"
+
+// Frequency of the timestamp. Must match SEGGER_SYSVIEW_GET_TIMESTAMP in SEGGER_SYSVIEW_Conf.h
+#define SYSVIEW_TIMESTAMP_FREQ  (configCPU_CLOCK_HZ)
+
+// System Frequency. SystemcoreClock is used in most CMSIS compatible projects.
+#define SYSVIEW_CPU_FREQ        configCPU_CLOCK_HZ
+
+// The lowest RAM address used for IDs (pointers)
+#define SYSVIEW_RAM_BASE        (0x10000000)
+
+/********************************************************************* 
+*
+*       _cbSendSystemDesc()
+*
+*  Function description
+*    Sends SystemView description strings.
+*/
+static void _cbSendSystemDesc(void) {
+  SEGGER_SYSVIEW_SendSysDesc("N="SYSVIEW_APP_NAME",D="SYSVIEW_DEVICE_NAME",O=FreeRTOS");
+  SEGGER_SYSVIEW_SendSysDesc("I#15=SysTick");
+}
+
+/*********************************************************************
+*
+*       Global functions
+*
+**********************************************************************
+*/
+void SEGGER_SYSVIEW_Conf(void) {
+  SEGGER_SYSVIEW_Init(SYSVIEW_TIMESTAMP_FREQ, SYSVIEW_CPU_FREQ, 
+                      &SYSVIEW_X_OS_TraceAPI, _cbSendSystemDesc);
+  SEGGER_SYSVIEW_SetRAMBase(SYSVIEW_RAM_BASE);
+}
+
+/*************************** End of file ****************************/

+ 252 - 0
code/debug/SEGGER/SEGGER_SYSVIEW_FreeRTOS.c

@@ -0,0 +1,252 @@
+/*********************************************************************
+*                    SEGGER Microcontroller GmbH                     *
+*                        The Embedded Experts                        *
+**********************************************************************
+*                                                                    *
+*            (c) 1995 - 2021 SEGGER Microcontroller GmbH             *
+*                                                                    *
+*       www.segger.com     Support: support@segger.com               *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+*       SEGGER SystemView * Real-time application analysis           *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+* All rights reserved.                                               *
+*                                                                    *
+* SEGGER strongly recommends to not make any changes                 *
+* to or modify the source code of this software in order to stay     *
+* compatible with the SystemView and RTT protocol, and J-Link.       *
+*                                                                    *
+* Redistribution and use in source and binary forms, with or         *
+* without modification, are permitted provided that the following    *
+* condition is met:                                                  *
+*                                                                    *
+* o Redistributions of source code must retain the above copyright   *
+*   notice, this condition and the following disclaimer.             *
+*                                                                    *
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND             *
+* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,        *
+* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF           *
+* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE           *
+* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR           *
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT  *
+* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;    *
+* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF      *
+* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT          *
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE  *
+* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH   *
+* DAMAGE.                                                            *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+*       SystemView version: 3.32                                    *
+*                                                                    *
+**********************************************************************
+-------------------------- END-OF-HEADER -----------------------------
+
+File    : SEGGER_SYSVIEW_FreeRTOS.c
+Purpose : Interface between FreeRTOS and SystemView.
+Revision: $Rev: 7947 $
+*/
+#include "FreeRTOS.h"
+#include "task.h"
+#include "SEGGER_SYSVIEW.h"
+#include "SEGGER_SYSVIEW_FreeRTOS.h"
+#include "string.h" // Required for memset
+
+
+
+typedef struct SYSVIEW_FREERTOS_TASK_STATUS SYSVIEW_FREERTOS_TASK_STATUS;
+
+struct SYSVIEW_FREERTOS_TASK_STATUS {
+  U32         xHandle;
+  const char* pcTaskName;
+  unsigned    uxCurrentPriority;
+  U32         pxStack;
+  unsigned    uStackHighWaterMark;
+};
+
+static SYSVIEW_FREERTOS_TASK_STATUS _aTasks[SYSVIEW_FREERTOS_MAX_NOF_TASKS];
+static unsigned _NumTasks;
+
+/*********************************************************************
+*
+*       _cbSendTaskList()
+*
+*  Function description
+*    This function is part of the link between FreeRTOS and SYSVIEW.
+*    Called from SystemView when asked by the host, it uses SYSVIEW
+*    functions to send the entire task list to the host.
+*/
+static void _cbSendTaskList(void) {
+  unsigned n;
+
+  for (n = 0; n < _NumTasks; n++) {
+#if INCLUDE_uxTaskGetStackHighWaterMark // Report Task Stack High Watermark
+    _aTasks[n].uStackHighWaterMark = uxTaskGetStackHighWaterMark((TaskHandle_t)_aTasks[n].xHandle);
+#endif
+    SYSVIEW_SendTaskInfo((U32)_aTasks[n].xHandle, _aTasks[n].pcTaskName, (unsigned)_aTasks[n].uxCurrentPriority, (U32)_aTasks[n].pxStack, (unsigned)_aTasks[n].uStackHighWaterMark);
+  }
+}
+
+/*********************************************************************
+*
+*       _cbGetTime()
+*
+*  Function description
+*    This function is part of the link between FreeRTOS and SYSVIEW.
+*    Called from SystemView when asked by the host, returns the
+*    current system time in micro seconds.
+*/
+static U64 _cbGetTime(void) {
+  U64 Time;
+
+  Time = xTaskGetTickCountFromISR();
+  Time *= portTICK_PERIOD_MS;
+  Time *= 1000;
+  return Time;
+}
+
+/*********************************************************************
+*
+*       Global functions
+*
+**********************************************************************
+*/
+/*********************************************************************
+*
+*       SYSVIEW_AddTask()
+*
+*  Function description
+*    Add a task to the internal list and record its information.
+*/
+void SYSVIEW_AddTask(U32 xHandle, const char* pcTaskName, unsigned uxCurrentPriority, U32  pxStack, unsigned uStackHighWaterMark) {
+  
+  if (memcmp(pcTaskName, "IDLE", 5) == 0) {
+    return;
+  }
+  
+  if (_NumTasks >= SYSVIEW_FREERTOS_MAX_NOF_TASKS) {
+    SEGGER_SYSVIEW_Warn("SYSTEMVIEW: Could not record task information. Maximum number of tasks reached.");
+    return;
+  }
+
+  _aTasks[_NumTasks].xHandle = xHandle;
+  _aTasks[_NumTasks].pcTaskName = pcTaskName;
+  _aTasks[_NumTasks].uxCurrentPriority = uxCurrentPriority;
+  _aTasks[_NumTasks].pxStack = pxStack;
+  _aTasks[_NumTasks].uStackHighWaterMark = uStackHighWaterMark;
+
+  _NumTasks++;
+
+  SYSVIEW_SendTaskInfo(xHandle, pcTaskName,uxCurrentPriority, pxStack, uStackHighWaterMark);
+
+}
+
+/*********************************************************************
+*
+*       SYSVIEW_UpdateTask()
+*
+*  Function description
+*    Update a task in the internal list and record its information.
+*/
+void SYSVIEW_UpdateTask(U32 xHandle, const char* pcTaskName, unsigned uxCurrentPriority, U32 pxStack, unsigned uStackHighWaterMark) {
+  unsigned n;
+  
+  if (memcmp(pcTaskName, "IDLE", 5) == 0) {
+    return;
+  }
+
+  for (n = 0; n < _NumTasks; n++) {
+    if (_aTasks[n].xHandle == xHandle) {
+      break;
+    }
+  }
+  if (n < _NumTasks) {
+    _aTasks[n].pcTaskName = pcTaskName;
+    _aTasks[n].uxCurrentPriority = uxCurrentPriority;
+    _aTasks[n].pxStack = pxStack;
+    _aTasks[n].uStackHighWaterMark = uStackHighWaterMark;
+
+    SYSVIEW_SendTaskInfo(xHandle, pcTaskName, uxCurrentPriority, pxStack, uStackHighWaterMark);
+  } else {
+    SYSVIEW_AddTask(xHandle, pcTaskName, uxCurrentPriority, pxStack, uStackHighWaterMark);
+  }
+}
+
+/*********************************************************************
+*
+*       SYSVIEW_DeleteTask()
+*
+*  Function description
+*    Delete a task from the internal list.
+*/
+void SYSVIEW_DeleteTask(U32 xHandle) {
+  unsigned n;
+  
+  if (_NumTasks == 0) {
+    return; // Early out
+  }  
+  for (n = 0; n < _NumTasks; n++) {
+    if (_aTasks[n].xHandle == xHandle) {
+      break;
+    }
+  }
+  if (n == (_NumTasks - 1)) {  
+    //
+    // Task is last item in list.
+    // Simply zero the item and decrement number of tasks.
+    //
+    memset(&_aTasks[n], 0, sizeof(_aTasks[n]));
+    _NumTasks--;
+  } else if (n < _NumTasks) {
+    //
+    // Task is in the middle of the list.
+    // Move last item to current position and decrement number of tasks.
+    // Order of tasks does not really matter, so no need to move all following items.
+    //
+    _aTasks[n].xHandle             = _aTasks[_NumTasks - 1].xHandle;
+    _aTasks[n].pcTaskName          = _aTasks[_NumTasks - 1].pcTaskName;
+    _aTasks[n].uxCurrentPriority   = _aTasks[_NumTasks - 1].uxCurrentPriority;
+    _aTasks[n].pxStack             = _aTasks[_NumTasks - 1].pxStack;
+    _aTasks[n].uStackHighWaterMark = _aTasks[_NumTasks - 1].uStackHighWaterMark;
+    memset(&_aTasks[_NumTasks - 1], 0, sizeof(_aTasks[_NumTasks - 1]));
+    _NumTasks--;
+  }
+}
+
+/*********************************************************************
+*
+*       SYSVIEW_SendTaskInfo()
+*
+*  Function description
+*    Record task information.
+*/
+void SYSVIEW_SendTaskInfo(U32 TaskID, const char* sName, unsigned Prio, U32 StackBase, unsigned StackSize) {
+  SEGGER_SYSVIEW_TASKINFO TaskInfo;
+
+  memset(&TaskInfo, 0, sizeof(TaskInfo)); // Fill all elements with 0 to allow extending the structure in future version without breaking the code
+  TaskInfo.TaskID     = TaskID;
+  TaskInfo.sName      = sName;
+  TaskInfo.Prio       = Prio;
+  TaskInfo.StackBase  = StackBase;
+  TaskInfo.StackSize  = StackSize;
+  SEGGER_SYSVIEW_SendTaskInfo(&TaskInfo);
+}
+
+/*********************************************************************
+*
+*       Public API structures
+*
+**********************************************************************
+*/
+// Callbacks provided to SYSTEMVIEW by FreeRTOS
+const SEGGER_SYSVIEW_OS_API SYSVIEW_X_OS_TraceAPI = {
+  _cbGetTime,
+  _cbSendTaskList,
+};
+
+/*************************** End of file ****************************/

+ 334 - 0
code/debug/SEGGER/SEGGER_SYSVIEW_FreeRTOS.h

@@ -0,0 +1,334 @@
+/*********************************************************************
+*                    SEGGER Microcontroller GmbH                     *
+*                        The Embedded Experts                        *
+**********************************************************************
+*                                                                    *
+*            (c) 1995 - 2021 SEGGER Microcontroller GmbH             *
+*                                                                    *
+*       www.segger.com     Support: support@segger.com               *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+*       SEGGER SystemView * Real-time application analysis           *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+* All rights reserved.                                               *
+*                                                                    *
+* SEGGER strongly recommends to not make any changes                 *
+* to or modify the source code of this software in order to stay     *
+* compatible with the SystemView and RTT protocol, and J-Link.       *
+*                                                                    *
+* Redistribution and use in source and binary forms, with or         *
+* without modification, are permitted provided that the following    *
+* condition is met:                                                  *
+*                                                                    *
+* o Redistributions of source code must retain the above copyright   *
+*   notice, this condition and the following disclaimer.             *
+*                                                                    *
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND             *
+* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,        *
+* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF           *
+* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE           *
+* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR           *
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT  *
+* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;    *
+* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF      *
+* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT          *
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE  *
+* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH   *
+* DAMAGE.                                                            *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+*       SystemView version: 3.32                                    *
+*                                                                    *
+**********************************************************************
+-------------------------- END-OF-HEADER -----------------------------
+
+File    : SEGGER_SYSVIEW_FreeRTOS.h
+Purpose : Interface between FreeRTOS and SystemView.
+          Tested with FreeRTOS V10.4.3
+Revision: $Rev: 7745 $
+
+Notes:
+  (1) Include this file at the end of FreeRTOSConfig.h
+*/
+
+#ifndef SYSVIEW_FREERTOS_H
+#define SYSVIEW_FREERTOS_H
+
+#include "SEGGER_SYSVIEW.h"
+
+/*********************************************************************
+*
+*       Defines, configurable
+*
+**********************************************************************
+*/
+#ifndef portSTACK_GROWTH
+  #define portSTACK_GROWTH              ( -1 )
+#endif
+
+#define SYSVIEW_FREERTOS_MAX_NOF_TASKS  8
+
+/*********************************************************************
+*
+*       Defines, fixed
+*
+**********************************************************************
+*/
+#define apiID_OFFSET                              (32u)
+
+#define apiID_VTASKALLOCATEMPUREGIONS             (1u)
+#define apiID_VTASKDELETE                         (2u)
+#define apiID_VTASKDELAY                          (3u)
+#define apiID_VTASKDELAYUNTIL                     (4u)
+#define apiID_UXTASKPRIORITYGET                   (5u)
+#define apiID_UXTASKPRIORITYGETFROMISR            (6u)
+#define apiID_ETASKGETSTATE                       (7u)
+#define apiID_VTASKPRIORITYSET                    (8u)
+#define apiID_VTASKSUSPEND                        (9u)
+#define apiID_VTASKRESUME                         (10u)
+#define apiID_XTASKRESUMEFROMISR                  (11u)
+#define apiID_VTASKSTARTSCHEDULER                 (12u)
+#define apiID_VTASKENDSCHEDULER                   (13u)
+#define apiID_VTASKSUSPENDALL                     (14u)
+#define apiID_XTASKRESUMEALL                      (15u)
+#define apiID_XTASKGETTICKCOUNT                   (16u)
+#define apiID_XTASKGETTICKCOUNTFROMISR            (17u)
+#define apiID_UXTASKGETNUMBEROFTASKS              (18u)
+#define apiID_PCTASKGETTASKNAME                   (19u)
+#define apiID_UXTASKGETSTACKHIGHWATERMARK         (20u)
+#define apiID_VTASKSETAPPLICATIONTASKTAG          (21u)
+#define apiID_XTASKGETAPPLICATIONTASKTAG          (22u)
+#define apiID_VTASKSETTHREADLOCALSTORAGEPOINTER   (23u)
+#define apiID_PVTASKGETTHREADLOCALSTORAGEPOINTER  (24u)
+#define apiID_XTASKCALLAPPLICATIONTASKHOOK        (25u)
+#define apiID_XTASKGETIDLETASKHANDLE              (26u)
+#define apiID_UXTASKGETSYSTEMSTATE                (27u)
+#define apiID_VTASKLIST                           (28u)
+#define apiID_VTASKGETRUNTIMESTATS                (29u)
+#define apiID_XTASKGENERICNOTIFY                  (30u)
+#define apiID_XTASKGENERICNOTIFYFROMISR           (31u)
+#define apiID_XTASKNOTIFYWAIT                     (32u)
+#define apiID_VTASKNOTIFYGIVEFROMISR              (33u)
+#define apiID_ULTASKNOTIFYTAKE                    (34u)
+#define apiID_XTASKNOTIFYSTATECLEAR               (35u)
+#define apiID_XTASKGETCURRENTTASKHANDLE           (36u)
+#define apiID_VTASKSETTIMEOUTSTATE                (37u)
+#define apiID_XTASKCHECKFORTIMEOUT                (38u)
+#define apiID_VTASKMISSEDYIELD                    (39u)
+#define apiID_XTASKGETSCHEDULERSTATE              (40u)
+#define apiID_VTASKPRIORITYINHERIT                (41u)
+#define apiID_XTASKPRIORITYDISINHERIT             (42u)
+#define apiID_XTASKGENERICCREATE                  (43u)
+#define apiID_UXTASKGETTASKNUMBER                 (44u)
+#define apiID_VTASKSETTASKNUMBER                  (45u)
+#define apiID_VTASKSTEPTICK                       (46u)
+#define apiID_ETASKCONFIRMSLEEPMODESTATUS         (47u)
+#define apiID_XTIMERCREATE                        (48u)
+#define apiID_PVTIMERGETTIMERID                   (49u)
+#define apiID_VTIMERSETTIMERID                    (50u)
+#define apiID_XTIMERISTIMERACTIVE                 (51u)
+#define apiID_XTIMERGETTIMERDAEMONTASKHANDLE      (52u)
+#define apiID_XTIMERPENDFUNCTIONCALLFROMISR       (53u)
+#define apiID_XTIMERPENDFUNCTIONCALL              (54u)
+#define apiID_PCTIMERGETTIMERNAME                 (55u)
+#define apiID_XTIMERCREATETIMERTASK               (56u)
+#define apiID_XTIMERGENERICCOMMAND                (57u)
+#define apiID_XQUEUEGENERICSEND                   (58u)
+#define apiID_XQUEUEPEEKFROMISR                   (59u)
+#define apiID_XQUEUEGENERICRECEIVE                (60u)
+#define apiID_UXQUEUEMESSAGESWAITING              (61u)
+#define apiID_UXQUEUESPACESAVAILABLE              (62u)
+#define apiID_VQUEUEDELETE                        (63u)
+#define apiID_XQUEUEGENERICSENDFROMISR            (64u)
+#define apiID_XQUEUEGIVEFROMISR                   (65u)
+#define apiID_XQUEUERECEIVEFROMISR                (66u)
+#define apiID_XQUEUEISQUEUEEMPTYFROMISR           (67u)
+#define apiID_XQUEUEISQUEUEFULLFROMISR            (68u)
+#define apiID_UXQUEUEMESSAGESWAITINGFROMISR       (69u)
+#define apiID_XQUEUEALTGENERICSEND                (70u)
+#define apiID_XQUEUEALTGENERICRECEIVE             (71u)
+#define apiID_XQUEUECRSENDFROMISR                 (72u)
+#define apiID_XQUEUECRRECEIVEFROMISR              (73u)
+#define apiID_XQUEUECRSEND                        (74u)
+#define apiID_XQUEUECRRECEIVE                     (75u)
+#define apiID_XQUEUECREATEMUTEX                   (76u)
+#define apiID_XQUEUECREATECOUNTINGSEMAPHORE       (77u)
+#define apiID_XQUEUEGETMUTEXHOLDER                (78u)
+#define apiID_XQUEUETAKEMUTEXRECURSIVE            (79u)
+#define apiID_XQUEUEGIVEMUTEXRECURSIVE            (80u)
+#define apiID_VQUEUEADDTOREGISTRY                 (81u)
+#define apiID_VQUEUEUNREGISTERQUEUE               (82u)
+#define apiID_XQUEUEGENERICCREATE                 (83u)
+#define apiID_XQUEUECREATESET                     (84u)
+#define apiID_XQUEUEADDTOSET                      (85u)
+#define apiID_XQUEUEREMOVEFROMSET                 (86u)
+#define apiID_XQUEUESELECTFROMSET                 (87u)
+#define apiID_XQUEUESELECTFROMSETFROMISR          (88u)
+#define apiID_XQUEUEGENERICRESET                  (89u)
+#define apiID_VLISTINITIALISE                     (90u)
+#define apiID_VLISTINITIALISEITEM                 (91u)
+#define apiID_VLISTINSERT                         (92u)
+#define apiID_VLISTINSERTEND                      (93u)
+#define apiID_UXLISTREMOVE                        (94u)
+#define apiID_XEVENTGROUPCREATE                   (95u)
+#define apiID_XEVENTGROUPWAITBITS                 (96u)
+#define apiID_XEVENTGROUPCLEARBITS                (97u)
+#define apiID_XEVENTGROUPCLEARBITSFROMISR         (98u)
+#define apiID_XEVENTGROUPSETBITS                  (99u)
+#define apiID_XEVENTGROUPSETBITSFROMISR           (100u)
+#define apiID_XEVENTGROUPSYNC                     (101u)
+#define apiID_XEVENTGROUPGETBITSFROMISR           (102u)
+#define apiID_VEVENTGROUPDELETE                   (103u)
+#define apiID_UXEVENTGROUPGETNUMBER               (104u)
+#define apiID_XSTREAMBUFFERCREATE                 (105u)
+#define apiID_VSTREAMBUFFERDELETE                 (106u)
+#define apiID_XSTREAMBUFFERRESET                  (107u)
+#define apiID_XSTREAMBUFFERSEND                   (108u)
+#define apiID_XSTREAMBUFFERSENDFROMISR            (109u)
+#define apiID_XSTREAMBUFFERRECEIVE                (110u)
+#define apiID_XSTREAMBUFFERRECEIVEFROMISR         (111u)
+
+#define traceSTART()                                                            SEGGER_SYSVIEW_Conf()
+
+#define traceTASK_NOTIFY_TAKE(uxIndexToWait)                                    SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET + apiID_ULTASKNOTIFYTAKE, xClearCountOnExit, xTicksToWait)
+#define traceTASK_DELAY()                                                       SEGGER_SYSVIEW_RecordU32  (apiID_OFFSET + apiID_VTASKDELAY, xTicksToDelay)
+#define traceTASK_DELAY_UNTIL(xTimeToWake)                                      SEGGER_SYSVIEW_RecordVoid (apiID_OFFSET + apiID_VTASKDELAYUNTIL)
+#define traceTASK_NOTIFY_GIVE_FROM_ISR(uxIndexToNotify)                         SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET + apiID_VTASKNOTIFYGIVEFROMISR, SEGGER_SYSVIEW_ShrinkId((U32)pxTCB), (U32)pxHigherPriorityTaskWoken)
+
+#define traceTASK_PRIORITY_INHERIT( pxTCB, uxPriority )                         SEGGER_SYSVIEW_RecordU32  (apiID_OFFSET + apiID_VTASKPRIORITYINHERIT, (U32)pxMutexHolder)
+#define traceTASK_RESUME( pxTCB )                                               SEGGER_SYSVIEW_RecordU32  (apiID_OFFSET + apiID_VTASKRESUME, SEGGER_SYSVIEW_ShrinkId((U32)pxTCB))
+#define traceINCREASE_TICK_COUNT( xTicksToJump )                                SEGGER_SYSVIEW_RecordU32  (apiID_OFFSET + apiID_VTASKSTEPTICK, xTicksToJump)
+#define traceTASK_SUSPEND( pxTCB )                                              SEGGER_SYSVIEW_RecordU32  (apiID_OFFSET + apiID_VTASKSUSPEND, SEGGER_SYSVIEW_ShrinkId((U32)pxTCB))
+#define traceTASK_PRIORITY_DISINHERIT( pxTCB, uxBasePriority )                  SEGGER_SYSVIEW_RecordU32  (apiID_OFFSET + apiID_XTASKPRIORITYDISINHERIT, (U32)pxMutexHolder)
+#define traceTASK_RESUME_FROM_ISR( pxTCB )                                      SEGGER_SYSVIEW_RecordU32  (apiID_OFFSET + apiID_XTASKRESUMEFROMISR, SEGGER_SYSVIEW_ShrinkId((U32)pxTCB))
+#define traceTASK_NOTIFY(uxIndexToNotify)                                       SEGGER_SYSVIEW_RecordU32x4(apiID_OFFSET + apiID_XTASKGENERICNOTIFY, SEGGER_SYSVIEW_ShrinkId((U32)pxTCB), ulValue, eAction, (U32)pulPreviousNotificationValue)
+#define traceTASK_NOTIFY_FROM_ISR(uxIndexToWait)                                SEGGER_SYSVIEW_RecordU32x5(apiID_OFFSET + apiID_XTASKGENERICNOTIFYFROMISR, SEGGER_SYSVIEW_ShrinkId((U32)pxTCB), ulValue, eAction, (U32)pulPreviousNotificationValue, (U32)pxHigherPriorityTaskWoken)
+#define traceTASK_NOTIFY_WAIT(uxIndexToWait)                                    SEGGER_SYSVIEW_RecordU32x4(apiID_OFFSET + apiID_XTASKNOTIFYWAIT, ulBitsToClearOnEntry, ulBitsToClearOnExit, (U32)pulNotificationValue, xTicksToWait)
+
+#define traceQUEUE_CREATE( pxNewQueue )                                         SEGGER_SYSVIEW_RecordU32x3(apiID_OFFSET + apiID_XQUEUEGENERICCREATE, uxQueueLength, uxItemSize, ucQueueType)
+#define traceQUEUE_DELETE( pxQueue )                                            SEGGER_SYSVIEW_RecordU32  (apiID_OFFSET + apiID_VQUEUEDELETE, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue))
+#define traceQUEUE_PEEK( pxQueue )                                              SEGGER_SYSVIEW_RecordU32x4(apiID_OFFSET + apiID_XQUEUEGENERICRECEIVE, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), SEGGER_SYSVIEW_ShrinkId((U32)pvBuffer), xTicksToWait, 1)
+#define traceQUEUE_PEEK_FROM_ISR( pxQueue )                                     SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET + apiID_XQUEUEPEEKFROMISR, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), SEGGER_SYSVIEW_ShrinkId((U32)pvBuffer))
+#define traceQUEUE_PEEK_FROM_ISR_FAILED( pxQueue )                              SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET + apiID_XQUEUEPEEKFROMISR, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), SEGGER_SYSVIEW_ShrinkId((U32)pvBuffer))
+#define traceQUEUE_RECEIVE( pxQueue )                                           SEGGER_SYSVIEW_RecordU32x4(apiID_OFFSET + apiID_XQUEUEGENERICRECEIVE, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), SEGGER_SYSVIEW_ShrinkId((U32)0), xTicksToWait, 1)
+#define traceQUEUE_RECEIVE_FAILED( pxQueue )                                    SEGGER_SYSVIEW_RecordU32x4(apiID_OFFSET + apiID_XQUEUEGENERICRECEIVE, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), SEGGER_SYSVIEW_ShrinkId((U32)0), xTicksToWait, 1)
+#define traceQUEUE_SEMAPHORE_RECEIVE( pxQueue )                                 SEGGER_SYSVIEW_RecordU32x4(apiID_OFFSET + apiID_XQUEUEGENERICRECEIVE, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), SEGGER_SYSVIEW_ShrinkId((U32)0), xTicksToWait, 0)
+#define traceQUEUE_RECEIVE_FROM_ISR( pxQueue )                                  SEGGER_SYSVIEW_RecordU32x3(apiID_OFFSET + apiID_XQUEUERECEIVEFROMISR, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), SEGGER_SYSVIEW_ShrinkId((U32)pvBuffer), (U32)pxHigherPriorityTaskWoken)
+#define traceQUEUE_RECEIVE_FROM_ISR_FAILED( pxQueue )                           SEGGER_SYSVIEW_RecordU32x3(apiID_OFFSET + apiID_XQUEUERECEIVEFROMISR, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), SEGGER_SYSVIEW_ShrinkId((U32)pvBuffer), (U32)pxHigherPriorityTaskWoken)
+#define traceQUEUE_REGISTRY_ADD( xQueue, pcQueueName )                          SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET + apiID_VQUEUEADDTOREGISTRY, SEGGER_SYSVIEW_ShrinkId((U32)xQueue), (U32)pcQueueName)
+#if ( configUSE_QUEUE_SETS != 1 )
+  #define traceQUEUE_SEND( pxQueue )                                            SEGGER_SYSVIEW_RecordU32x4(apiID_OFFSET + apiID_XQUEUEGENERICSEND, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), (U32)pvItemToQueue, xTicksToWait, xCopyPosition)
+#else
+  #define traceQUEUE_SEND( pxQueue )                                            SEGGER_SYSVIEW_RecordU32x4(apiID_OFFSET + apiID_XQUEUEGENERICSEND, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), 0u, 0u, xCopyPosition)
+#endif
+#define traceQUEUE_SEND_FAILED( pxQueue )                                       SEGGER_SYSVIEW_RecordU32x4(apiID_OFFSET + apiID_XQUEUEGENERICSEND, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), (U32)pvItemToQueue, xTicksToWait, xCopyPosition)
+#define traceQUEUE_SEND_FROM_ISR( pxQueue )                                     SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET + apiID_XQUEUEGENERICSENDFROMISR, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), (U32)pxHigherPriorityTaskWoken)
+#define traceQUEUE_SEND_FROM_ISR_FAILED( pxQueue )                              SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET + apiID_XQUEUEGENERICSENDFROMISR, SEGGER_SYSVIEW_ShrinkId((U32)pxQueue), (U32)pxHigherPriorityTaskWoken)
+#define traceSTREAM_BUFFER_CREATE( pxStreamBuffer, xIsMessageBuffer )           SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET + apiID_XSTREAMBUFFERCREATE, (U32)xIsMessageBuffer, (U32)pxStreamBuffer)
+#define traceSTREAM_BUFFER_CREATE_FAILED( xIsMessageBuffer )                    SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET + apiID_XSTREAMBUFFERCREATE, (U32)xIsMessageBuffer, 0u)
+#define traceSTREAM_BUFFER_DELETE( xStreamBuffer )                              SEGGER_SYSVIEW_RecordU32  (apiID_OFFSET + apiID_VSTREAMBUFFERDELETE, (U32)xStreamBuffer)
+#define traceSTREAM_BUFFER_RESET( xStreamBuffer )                               SEGGER_SYSVIEW_RecordU32  (apiID_OFFSET + apiID_XSTREAMBUFFERRESET, (U32)xStreamBuffer)
+#define traceSTREAM_BUFFER_SEND( xStreamBuffer, xBytesSent )                    SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET + apiID_XSTREAMBUFFERSEND, (U32)xStreamBuffer, (U32)xBytesSent)
+#define traceSTREAM_BUFFER_SEND_FAILED( xStreamBuffer )                         SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET + apiID_XSTREAMBUFFERSEND, (U32)xStreamBuffer, 0u)
+#define traceSTREAM_BUFFER_SEND_FROM_ISR( xStreamBuffer, xBytesSent )           SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET + apiID_XSTREAMBUFFERSENDFROMISR, (U32)xStreamBuffer, (U32)xBytesSent)
+#define traceSTREAM_BUFFER_RECEIVE( xStreamBuffer, xReceivedLength )            SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET + apiID_XSTREAMBUFFERRECEIVE, (U32)xStreamBuffer, (U32)xReceivedLength)
+#define traceSTREAM_BUFFER_RECEIVE_FAILED( xStreamBuffer )                      SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET + apiID_XSTREAMBUFFERRECEIVE, (U32)xStreamBuffer, 0u)
+#define traceSTREAM_BUFFER_RECEIVE_FROM_ISR( xStreamBuffer, xReceivedLength )   SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET + apiID_XSTREAMBUFFERRECEIVEFROMISR, (U32)xStreamBuffer, (U32)xReceivedLength)
+
+
+#define traceTASK_DELETE( pxTCB )                   {                                                                                                   \
+                                                      SEGGER_SYSVIEW_RecordU32(apiID_OFFSET + apiID_VTASKDELETE, SEGGER_SYSVIEW_ShrinkId((U32)pxTCB));  \
+                                                      SYSVIEW_DeleteTask((U32)pxTCB);                                                                   \
+                                                    }
+
+
+#if( portSTACK_GROWTH < 0 )
+#define traceTASK_CREATE(pxNewTCB)                  if (pxNewTCB != NULL) {                                             \
+                                                      SEGGER_SYSVIEW_OnTaskCreate((U32)pxNewTCB);                       \
+                                                      SYSVIEW_AddTask((U32)pxNewTCB,                                    \
+                                                                      &(pxNewTCB->pcTaskName[0]),                       \
+                                                                      pxNewTCB->uxPriority,                             \
+                                                                      (U32)pxNewTCB->pxStack,                           \
+                                                                      ((U32)pxNewTCB->pxTopOfStack - (U32)pxNewTCB->pxStack) \
+                                                                      );                                                \
+                                                    }
+#else
+#define traceTASK_CREATE(pxNewTCB)                  if (pxNewTCB != NULL) {                                             \
+                                                      SEGGER_SYSVIEW_OnTaskCreate((U32)pxNewTCB);                       \
+                                                      SYSVIEW_AddTask((U32)pxNewTCB,                                    \
+                                                                      &(pxNewTCB->pcTaskName[0]),                       \
+                                                                      pxNewTCB->uxPriority,                             \
+                                                                      (U32)pxNewTCB->pxStack,                           \
+                                                                      (U32)(pxNewTCB->pxStack-pxNewTCB->pxTopOfStack)   \
+                                                                      );                                                \
+                                                    }
+#endif
+#define traceTASK_PRIORITY_SET(pxTask, uxNewPriority) {                                                                 \
+                                                        SEGGER_SYSVIEW_RecordU32x2(apiID_OFFSET+apiID_VTASKPRIORITYSET, \
+                                                                                   SEGGER_SYSVIEW_ShrinkId((U32)pxTCB), \
+                                                                                   uxNewPriority                        \
+                                                                                  );                                    \
+                                                        SYSVIEW_UpdateTask((U32)pxTask,                                 \
+                                                                           &(pxTask->pcTaskName[0]),                    \
+                                                                           uxNewPriority,                               \
+                                                                           (U32)pxTask->pxStack,                        \
+                                                                           0                                            \
+                                                                          );                                            \
+                                                      }
+//
+// Define INCLUDE_xTaskGetIdleTaskHandle as 1 in FreeRTOSConfig.h to allow identification of Idle state.
+//
+#if ( INCLUDE_xTaskGetIdleTaskHandle == 1 )
+  #define traceTASK_SWITCHED_IN()                   if(prvGetTCBFromHandle(NULL) == xIdleTaskHandle) {                  \
+                                                      SEGGER_SYSVIEW_OnIdle();                                          \
+                                                    } else {                                                            \
+                                                      SEGGER_SYSVIEW_OnTaskStartExec((U32)pxCurrentTCB);                \
+                                                    }
+#else
+  #define traceTASK_SWITCHED_IN()                   {                                                                   \
+                                                      if (memcmp(pxCurrentTCB->pcTaskName, "IDLE", 5) != 0) {           \
+                                                        SEGGER_SYSVIEW_OnTaskStartExec((U32)pxCurrentTCB);              \
+                                                      } else {                                                          \
+                                                        SEGGER_SYSVIEW_OnIdle();                                        \
+                                                      }                                                                 \
+                                                    }
+#endif
+
+#define traceMOVED_TASK_TO_READY_STATE(pxTCB)       SEGGER_SYSVIEW_OnTaskStartReady((U32)pxTCB)
+#define traceREADDED_TASK_TO_READY_STATE(pxTCB)
+
+#define traceMOVED_TASK_TO_DELAYED_LIST()           SEGGER_SYSVIEW_OnTaskStopReady((U32)pxCurrentTCB,  (1u << 2))
+#define traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST()  SEGGER_SYSVIEW_OnTaskStopReady((U32)pxCurrentTCB,  (1u << 2))
+#define traceMOVED_TASK_TO_SUSPENDED_LIST(pxTCB)    SEGGER_SYSVIEW_OnTaskStopReady((U32)pxTCB,         ((3u << 3) | 3))
+
+
+#define traceISR_EXIT_TO_SCHEDULER()                SEGGER_SYSVIEW_RecordExitISRToScheduler()
+#define traceISR_EXIT()                             SEGGER_SYSVIEW_RecordExitISR()
+#define traceISR_ENTER()                            SEGGER_SYSVIEW_RecordEnterISR()
+
+/*********************************************************************
+*
+*       API functions
+*
+**********************************************************************
+*/
+#ifdef __cplusplus
+extern "C" {
+#endif
+void SYSVIEW_AddTask      (U32 xHandle, const char* pcTaskName, unsigned uxCurrentPriority, U32  pxStack, unsigned uStackHighWaterMark);
+void SYSVIEW_UpdateTask   (U32 xHandle, const char* pcTaskName, unsigned uxCurrentPriority, U32 pxStack, unsigned uStackHighWaterMark);
+void SYSVIEW_DeleteTask   (U32 xHandle);
+void SYSVIEW_SendTaskInfo (U32 TaskID, const char* sName, unsigned Prio, U32 StackBase, unsigned StackSize);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+/*************************** End of file ****************************/

+ 99 - 0
code/debug/SEGGER/SEGGER_SYSVIEW_Int.h

@@ -0,0 +1,99 @@
+/*********************************************************************
+*                    SEGGER Microcontroller GmbH                     *
+*                        The Embedded Experts                        *
+**********************************************************************
+*                                                                    *
+*            (c) 1995 - 2021 SEGGER Microcontroller GmbH             *
+*                                                                    *
+*       www.segger.com     Support: support@segger.com               *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+*       SEGGER SystemView * Real-time application analysis           *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+* All rights reserved.                                               *
+*                                                                    *
+* SEGGER strongly recommends to not make any changes                 *
+* to or modify the source code of this software in order to stay     *
+* compatible with the SystemView and RTT protocol, and J-Link.       *
+*                                                                    *
+* Redistribution and use in source and binary forms, with or         *
+* without modification, are permitted provided that the following    *
+* condition is met:                                                  *
+*                                                                    *
+* o Redistributions of source code must retain the above copyright   *
+*   notice, this condition and the following disclaimer.             *
+*                                                                    *
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND             *
+* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,        *
+* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF           *
+* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE           *
+* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR           *
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT  *
+* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;    *
+* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF      *
+* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT          *
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE  *
+* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH   *
+* DAMAGE.                                                            *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+*       SystemView version: 3.32                                    *
+*                                                                    *
+**********************************************************************
+-------------------------- END-OF-HEADER -----------------------------
+File    : SEGGER_SYSVIEW_Int.h
+Purpose : SEGGER SystemView internal header.
+Revision: $Rev: 21281 $
+*/
+
+#ifndef SEGGER_SYSVIEW_INT_H
+#define SEGGER_SYSVIEW_INT_H
+
+/*********************************************************************
+*
+*       #include Section
+*
+**********************************************************************
+*/
+
+#include "SEGGER_SYSVIEW.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/*********************************************************************
+*
+*       Private data types
+*
+**********************************************************************
+*/
+//
+// Commands that Host can send to target
+//
+typedef enum {
+  SEGGER_SYSVIEW_COMMAND_ID_START = 1,
+  SEGGER_SYSVIEW_COMMAND_ID_STOP,
+  SEGGER_SYSVIEW_COMMAND_ID_GET_SYSTIME,
+  SEGGER_SYSVIEW_COMMAND_ID_GET_TASKLIST,
+  SEGGER_SYSVIEW_COMMAND_ID_GET_SYSDESC,
+  SEGGER_SYSVIEW_COMMAND_ID_GET_NUMMODULES,
+  SEGGER_SYSVIEW_COMMAND_ID_GET_MODULEDESC,
+  SEGGER_SYSVIEW_COMMAND_ID_HEARTBEAT = 127,
+  // Extended commands: Commands >= 128 have a second parameter
+  SEGGER_SYSVIEW_COMMAND_ID_GET_MODULE = 128
+} SEGGER_SYSVIEW_COMMAND_ID;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+/*************************** End of file ****************************/

+ 0 - 0
cm_backtrace/Languages/README.md → code/debug/cm_backtrace/Languages/README.md


+ 0 - 0
cm_backtrace/Languages/en-US/cmb_en_US.h → code/debug/cm_backtrace/Languages/en-US/cmb_en_US.h


+ 0 - 0
cm_backtrace/Languages/zh-CN/cmb_zh_CN.h → code/debug/cm_backtrace/Languages/zh-CN/cmb_zh_CN.h


+ 0 - 0
cm_backtrace/Languages/zh-CN/cmb_zh_CN_UTF8.h → code/debug/cm_backtrace/Languages/zh-CN/cmb_zh_CN_UTF8.h


+ 0 - 0
cm_backtrace/cm_backtrace.c → code/debug/cm_backtrace/cm_backtrace.c


+ 0 - 0
cm_backtrace/cm_backtrace.h → code/debug/cm_backtrace/cm_backtrace.h


+ 0 - 0
cm_backtrace/cmb_cfg.h → code/debug/cm_backtrace/cmb_cfg.h


+ 0 - 0
cm_backtrace/cmb_def.h → code/debug/cm_backtrace/cmb_def.h


+ 0 - 0
cm_backtrace/fault_handler/gcc/cmb_fault.S → code/debug/cm_backtrace/fault_handler/gcc/cmb_fault.S


+ 0 - 0
cm_backtrace/fault_handler/iar/cmb_fault.S → code/debug/cm_backtrace/fault_handler/iar/cmb_fault.S


+ 0 - 0
cm_backtrace/fault_handler/keil/cmb_fault.S → code/debug/cm_backtrace/fault_handler/keil/cmb_fault.S


+ 0 - 0
src/SL_Sc7a20_Driver.c → code/driver/SL_Sc7a20_Driver.c


+ 33 - 33
src/SL_Sc7a20_Driver.h → code/driver/SL_Sc7a20_Driver.h

@@ -5,26 +5,26 @@
 #include "StandardTypes.h"
 #include "Spi.h"
 
-/***使用驱动前请根据实际接线情况配置******/
-/**SC7A20的SDO 脚接地:  0****************/
-/**SC7A20的SDO 脚接电源:1****************/
+/***浣跨敤椹卞姩鍓嶈�鏍规嵁瀹為檯鎺ョ嚎鎯呭喌閰嶇疆******/
+/**SC7A20鐨凷DO 鑴氭帴鍦帮細  0****************/
+/**SC7A20鐨凷DO 鑴氭帴鐢垫簮锛�1****************/
 #define SC7A20_SDO_VDD_GND            1
 /*****************************************/
 
-/***使用驱动前请根据实际IIC情况进行配置***/
-/**SC7A20的IIC 接口地址类型 7bits:  0****/
-/**SC7A20的IIC 接口地址类型 8bits:  1****/
+/***浣跨敤椹卞姩鍓嶈�鏍规嵁瀹為檯IIC鎯呭喌杩涜�閰嶇疆***/
+/**SC7A20鐨処IC 鎺ュ彛鍦板潃绫诲瀷 7bits锛�  0****/
+/**SC7A20鐨処IC 鎺ュ彛鍦板潃绫诲瀷 8bits锛�  1****/
 #define SC7A20_IIC_7BITS_8BITS        0
 /*****************************************/
 
 #define  SL_SC7A20_16BIT_8BIT         1
-/**SC7A20的数据位数选择  16bits:    1****/
-/**SC7A20的数据位数选择   8bits:    0****/
+/**SC7A20鐨勬暟鎹�綅鏁伴€夋嫨  16bits锛�    1****/
+/**SC7A20鐨勬暟鎹�綅鏁伴€夋嫨   8bits锛�    0****/
 /*****************************************/
 
 #define  SL_SC7A20_SPI_IIC_MODE       0
-/**SC7A20 SPI IIC 选择    SPI:      0****/
-/**SC7A20 SPI IIC 选择    IIC:      1****/
+/**SC7A20 SPI IIC 閫夋嫨    SPI锛�      0****/
+/**SC7A20 SPI IIC 閫夋嫨    IIC锛�      1****/
 /*****************************************/
 
 #define SL_6D4D2D1D_SEL   			 6
@@ -89,11 +89,11 @@
 #define  SL_SC7A20_ACT_THS        (uint8)0x3E
 #define  SL_SC7A20_ACT_DURATION   (uint8)0x3F
 	
-/*连续读取数据时的数据寄存器地址*/
+/*杩炵画璇诲彇鏁版嵁鏃剁殑鏁版嵁瀵勫瓨鍣ㄥ湴鍧€*/
 #define  SL_SC7A20_DATA_OUT       (uint8)(SL_SC7A20_OUT_X_L)
 
-/**********特殊功能寄存器**********/
-/*非原厂技术人员请勿修改*/
+/**********鐗规畩鍔熻兘瀵勫瓨鍣�**********/
+/*闈炲師鍘傛妧鏈�汉鍛樿�鍕夸慨鏀�*/
 #define  SL_SC7A20_MTP_ENABLE            0x00
 #define  SL_SC7A20_MTP_CFG    	  (uint8)0x1E
 #define  SL_SC7A20_MTP_VALUE   	  (uint8)0x05
@@ -102,10 +102,10 @@
 #define  SL_SC7A20_I2C_PU_MSK     (uint8)0x04
 #define  SL_SC7A20_HR_ENABLE      (uint8)0X08
 #define  SL_SC7A20_BOOT_ENABLE    (uint8)0X80
-/*非原厂技术人员请勿修改*/
+/*闈炲師鍘傛妧鏈�汉鍛樿�鍕夸慨鏀�*/
 
 
-/***************数据更新速率**加速度计使能**********/
+/***************鏁版嵁鏇存柊閫熺巼**鍔犻€熷害璁′娇鑳�**********/
 #define  SL_SC7A20_ODR_POWER_DOWN (uint8)0x00
 #define  SL_SC7A20_ODR_1HZ        (uint8)0x17
 #define  SL_SC7A20_ODR_10HZ       (uint8)0x27
@@ -125,18 +125,18 @@
 #define  SL_SC7A20_LOWER_POWER_ODR_100HZ      (uint8)0x5F
 #define  SL_SC7A20_LOWER_POWER_ODR_200HZ      (uint8)0x6F
 #define  SL_SC7A20_LOWER_POWER_ODR_400HZ      (uint8)0x7F
-/***************数据更新速率**加速度计使能**********/
+/***************鏁版嵁鏇存柊閫熺巼**鍔犻€熷害璁′娇鑳�**********/
 
 
-/***************传感器量程设置**********************/
+/***************浼犳劅鍣ㄩ噺绋嬭�缃�**********************/
 #define  SL_SC7A20_FS_2G          (uint8)0x00
 #define  SL_SC7A20_FS_4G          (uint8)0x10
 #define  SL_SC7A20_FS_8G          (uint8)0x20
 #define  SL_SC7A20_FS_16G         (uint8)0x30
-/***************传感器量程设置**********************/
+/***************浼犳劅鍣ㄩ噺绋嬭�缃�**********************/
 
 
-/***取值在0-127之间,此处仅举例****/
+/***鍙栧€煎湪0-127涔嬮棿锛屾�澶勪粎涓句緥****/
 #define SL_SC7A20_INT_THS_5PERCENT   (uint8)0x06
 #define SL_SC7A20_INT_THS_10PERCENT  (uint8)0x0C
 #define SL_SC7A20_INT_THS_20PERCENT  (uint8)0x18
@@ -144,41 +144,41 @@
 #define SL_SC7A20_INT_THS_80PERCENT  (uint8)0x60
 
 
-/***取值在0-127之间,此处仅举例 乘以ODR单位时间****/
+/***鍙栧€煎湪0-127涔嬮棿锛屾�澶勪粎涓句緥 涔樹互ODR鍗曚綅鏃堕棿****/
 #define SL_SC7A20_INT_DURATION_2CLK  (uint8)0x02
 #define SL_SC7A20_INT_DURATION_5CLK  (uint8)0x05
 #define SL_SC7A20_INT_DURATION_10CLK (uint8)0x0A
 #define SL_SC7A20_INT_DURATION_30CLK  (uint8)0x2E
 
 
-/***中断有效时的电平设置,高电平相当于上升沿,低电平相当于下降沿****/
-#define SL_SC7A20_INT_ACTIVE_LOWER_LEVEL 0x02 //0x02:中断时INT1脚输出 低电平
-#define SL_SC7A20_INT_ACTIVE_HIGH_LEVEL  0x00 //0x00:中断时INT1脚输出 高电平 
+/***涓�柇鏈夋晥鏃剁殑鐢靛钩璁剧疆锛岄珮鐢靛钩鐩稿綋浜庝笂鍗囨部锛屼綆鐢靛钩鐩稿綋浜庝笅闄嶆部****/
+#define SL_SC7A20_INT_ACTIVE_LOWER_LEVEL 0x02 //0x02:涓�柇鏃禝NT1鑴氳緭鍑� 浣庣數骞�
+#define SL_SC7A20_INT_ACTIVE_HIGH_LEVEL  0x00 //0x00:涓�柇鏃禝NT1鑴氳緭鍑� 楂樼數骞� 
 
-/***中断有效时的电平设置,高电平相当于上升沿,低电平相当于下降沿****/
+/***涓�柇鏈夋晥鏃剁殑鐢靛钩璁剧疆锛岄珮鐢靛钩鐩稿綋浜庝笂鍗囨部锛屼綆鐢靛钩鐩稿綋浜庝笅闄嶆部****/
 #define SL_SC7A20_INT_AOI1_INT1          0x40 //AOI1 TO INT1
 #define SL_SC7A20_INT_AOI2_INT1          0x20 //AOI2 TO INT1
 
-/********客户需要进行的IIC接口封包函数****************/
+/********瀹㈡埛闇€瑕佽繘琛岀殑IIC鎺ュ彛灏佸寘鍑芥暟****************/
 Std_ReturnType Gsensor_SPI_Write(uint8 Addr,uint8 *DataBufferPtr,uint16 Length);
 Std_ReturnType Gsensor_SPI_Read(uint8 Addr,uint8 *DataBufferPtr,uint16 Length);
-/**Gsensor_SPI_Write 函数中, sl_spi_iic:0=spi  1=i2c  Reg:寄存器地址   data:寄存器的配置值******************/
-/**Gsensor_SPI_Write 函数 是一个单次写的函数*******************************************************************/
-/***Gsensor_SPI_Read 函数中, sl_spi_iic:0=spi  1=i2c Reg 同上,len:读取数据长度,buf:存储数据首地址(指针)***/
-/***Gsensor_SPI_Read 函数 是可以进行单次读或多次连续读取的函数*************************************************/
+/**Gsensor_SPI_Write 鍑芥暟涓�紝 sl_spi_iic:0=spi  1=i2c  Reg锛氬瘎瀛樺櫒鍦板潃   data锛氬瘎瀛樺櫒鐨勯厤缃�€�******************/
+/**Gsensor_SPI_Write 鍑芥暟 鏄�竴涓�崟娆″啓鐨勫嚱鏁�*******************************************************************/
+/***Gsensor_SPI_Read 鍑芥暟涓�紝 sl_spi_iic:0=spi  1=i2c Reg 鍚屼笂锛宭en:璇诲彇鏁版嵁闀垮害锛宐uf:瀛樺偍鏁版嵁棣栧湴鍧€锛堟寚閽堬級***/
+/***Gsensor_SPI_Read 鍑芥暟 鏄�彲浠ヨ繘琛屽崟娆¤�鎴栧�娆¤繛缁��鍙栫殑鍑芥暟*************************************************/
 
 
 
-/*** 客户IIC函数封装举例
+/*** 瀹㈡埛IIC鍑芥暟灏佽�涓句緥
 uint8 SL_MEMS_i2c_spi_Write(uint8 reg, uint8 data)
 {
-    i2cWrite(SC7A20_IIC_ADDRESS,  reg,  data);       //由客户的II函数接口决定
+    i2cWrite(SC7A20_IIC_ADDRESS,  reg,  data);       //鐢卞�鎴风殑II鍑芥暟鎺ュ彛鍐冲畾
     return 1;
 }
 
 uint8 SL_MEMS_i2c_spi_Read(uint8 reg, uint8 len, uint8 *buf)
 {
-    i2cRead( SC7A20_IIC_ADDRESS,  reg,  len, buf);//由客户的II函数接口决定
+    i2cRead( SC7A20_IIC_ADDRESS,  reg,  len, buf);//鐢卞�鎴风殑II鍑芥暟鎺ュ彛鍐冲畾
     return 1;
 }
 ***/
@@ -200,7 +200,7 @@ void  SL_SC7A20_AOI2_event(void);
 void  SL_SC7A20_Reg_read_all(void);
 Std_ReturnType GsensorInit(void);
 
-//步骤如下:
+//姝ラ�濡備笅锛�
 //0.signed char  SL_SC7A20_BOOT(void);
 //1.signed char  SL_SC7A20_Online_Test(void);
 //2.signed char  SL_SC7A20_FS_Config(uint8 Sc7a20_FS_Reg);

+ 1 - 4
src/Hal_Fls.c → code/hal/Hal_Fls.c

@@ -1,7 +1,7 @@
 /*
  * Hal_Fls.c
  *
- *  Created on: 2022Äê4ÔÂ6ÈÕ
+ *  Created on: 2022Äê4ÔÂ6ÈÕ
  *      Author: Zhengchao
  */
 #include "Hal_Fls.h"
@@ -224,9 +224,6 @@ static uint8 FlashChecksum(void)
 {
     uint32 xCountCrc = 0u;
     CRC_HAL_CreatSoftwareCrc((const uint8 *)(gs_stAppDownloadInfo.appVectoTableStartAddr + APP_FLAST_START_PHY_ADDR), gs_stAppDownloadInfo.appLength, &xCountCrc);
-#if SEGGER_PRINTF==1
-	SEGGER_RTT_printf("[%d]%X==%X\r\n",__LINE__,gs_stAppDownloadInfo.receivedCRC,xCountCrc);
-#endif
     if(gs_stAppDownloadInfo.receivedCRC == xCountCrc)
     {
     	return TRUE;

+ 1 - 1
src/Hal_Fls.h → code/hal/Hal_Fls.h

@@ -1,7 +1,7 @@
 /*
  * Hal_Fls.h
  *
- *  Created on: 2022Äê4ÔÂ6ÈÕ
+ *  Created on: 2022Äê4ÔÂ6ÈÕ
  *      Author: Zhengchao
  */
 

+ 1 - 1
src/Hal_Var.c → code/hal/Hal_Var.c

@@ -1,7 +1,7 @@
 /*
  * Hal_Var.c
  *
- *  Created on: 2022Äê3ÔÂ14ÈÕ
+ *  Created on: 2022Äę3ÔÂ14Č�
  *      Author: Zhengchao
  */
 #include "Hal_Var.h"

+ 1 - 1
src/Hal_Var.h → code/hal/Hal_Var.h

@@ -1,7 +1,7 @@
 /*
  * Hal_Var.h
  *
- *  Created on: 2022Äê3ÔÂ14ÈÕ
+ *  Created on: 2022Äê3ÔÂ14ÈÕ
  *      Author: Zhengchao
  */
 

+ 0 - 0
src/Hal_Wdg.c → code/hal/Hal_Wdg.c


+ 1 - 1
src/Hal_Wdg.h → code/hal/Hal_Wdg.h

@@ -1,7 +1,7 @@
 /*
  * Hal_Wdg.h
  *
- *  Created on: 2022Äê3ÔÂ14ÈÕ
+ *  Created on: 2022Äê3ÔÂ14ÈÕ
  *      Author: Zhengchao
  */
 

+ 6 - 28
src/hal_adapter.c → code/hal/hal_adapter.c

@@ -1,7 +1,7 @@
 /*
  * hal_adapter.c
- *中间层函数调用库
- *  Created on: 2022年1月18日
+ *涓�棿灞傚嚱鏁拌皟鐢ㄥ簱
+ *  Created on: 2022骞�1鏈�18鏃�
  *      Author: QiXiang_CHENJIE
  */
 #include "hal_adapter.h"
@@ -26,10 +26,6 @@ uint32_t write_ringBuffer(uint8_t *buffer, uint32_t size, ringbuffer_t *ringBuf)
 uint32_t read_ringBuffer(uint8_t *buffer, uint32_t size, ringbuffer_t *ringBuf);
 uint8 ringBufferforUart[3][BUFFER_SIZE];
 ringbuffer_t uartRingBuffer[3];
-#if UARTPRINTF==1
-	uint8 ringbuffer[1024];
-	ringbuffer_t printfRingBuffer;
-#endif
 sint8 AtcmdDelayRecvFunc(uint8 recvChannel,char *ResultStrPtr,uint16 delayTime)
 {
 	sint8 outValue = -1;
@@ -56,7 +52,7 @@ sint8 AtcmdDelayRecvFunc(uint8 recvChannel,char *ResultStrPtr,uint16 delayTime)
 	}
 	return outValue;
 }
-#if UARTPRINTF==1
+#if 0
 	uint16 myPrintf(const char *fmt, ...)
 	{
 		int n;
@@ -108,12 +104,6 @@ uint32_t write_ringBuffer(uint8_t *buffer, uint32_t size, ringbuffer_t *ringBuf)
     memcpy(ringBuf_source + ringBuf_bw, buffer, size);
     ringBuf->bw = (ringBuf_bw + size) % ringBuf_len;
     ringBuf->btoRead += size;
-#if SEGGER_PRINTF==1
-    if(ringBuf->source==ringBufferforUart[1])
-    {
-    	SEGGER_RTT_printf("[%d]buffer=%s\r\nringBuf->bw=%X,size=%X,%X\r\n",__LINE__,buffer,ringBuf->bw,size,ringBuf->bw-size+ringBuf_source);
-    }
-#endif
 /*
     if(ringBuf->br!=0)
     {
@@ -289,7 +279,7 @@ Std_ReturnType UART_Send_Data(uint8 transChannel, const uint8 *txBuffer, uint32
 	 uint8 UartState[3] = {UartAbortRecv,UartAbortRecv,UartAbortRecv};
 	 while(1)
 	 {
-		 if((T_timeout[UartIdx]>1000) && (Uart_ReceiveStatus[UartIdx] != UART_STATUS_NO_ERROR) )//判定UART停止,超时停止,不是接收状态则停止
+		 if((T_timeout[UartIdx]>1000) && (Uart_ReceiveStatus[UartIdx] != UART_STATUS_NO_ERROR) )//鍒ゅ畾UART鍋滄�锛岃秴鏃跺仠姝�紝涓嶆槸鎺ユ敹鐘舵€佸垯鍋滄�
 		 {
 			  Uart_Abort(UartIdx, UART_RECEIVE);
 			  UartState[UartIdx] = UartAbortRecv;
@@ -300,7 +290,7 @@ Std_ReturnType UART_Send_Data(uint8 transChannel, const uint8 *txBuffer, uint32
 			 UartState[UartIdx] = UartRecvComplete;
 		 }
 
-		 if((UartState[UartIdx] == UartAbortRecv) || (UartState[UartIdx] == UartRecvComplete)) //判定UART开始接收:UART停止后开始接收
+		 if((UartState[UartIdx] == UartAbortRecv) || (UartState[UartIdx] == UartRecvComplete)) //鍒ゅ畾UART寮€濮嬫帴鏀讹細UART鍋滄�鍚庡紑濮嬫帴鏀�
 		 {
 			 if(E_OK == UartStartRecvFunc(UartIdx))
 			 {
@@ -321,12 +311,6 @@ Std_ReturnType UART_Send_Data(uint8 transChannel, const uint8 *txBuffer, uint32
 						UartRecvMsg.DataLen = UartHalMsgRecv.value;
 						UartRecvMsg.dataAddr = (uint32)(uartRingBuffer[UartHalMsgRecv.Channel].bw + uartRingBuffer[UartHalMsgRecv.Channel].source - UartHalMsgRecv.value);
 						ret_send = xQueueSend(UartRecvQueue[UartHalMsgRecv.Channel],&UartRecvMsg,10);
-#if SEGGER_PRINTF==1
-						if(UartHalMsgRecv.Channel==1)
-						{
-							SEGGER_RTT_printf("[%d]source=%X,dataAddr=%X\r\n",__LINE__,uartRingBuffer[UartHalMsgRecv.Channel].source,UartRecvMsg.dataAddr);
-						}
-#endif
 					}
 					T_timeout[UartHalMsgRecv.Channel] = 0;
 					UartState[UartHalMsgRecv.Channel] = UartRecvComplete;
@@ -352,12 +336,6 @@ Std_ReturnType UART_Send_Data(uint8 transChannel, const uint8 *txBuffer, uint32
 			 {
 				 Dio_WriteChannel(DioConf_DioChannel_PTB4_GPIO_OUT_MCU_RS485_EN, STD_ON);
 			 }
-#if SEGGER_PRINTF==2
-					if(UartIdx==1)
-					{
-						SEGGER_RTT_printf("[%d]uart1_s=%s\r\n",__LINE__,UartSendMsg.dataPtr);
-					}
-#endif
 			 T_Uart_Status[UartIdx] = Uart_AsyncSend(UartIdx, UartSendMsg.dataPtr, UartSendMsg.DataLen);
 		     if (E_OK != T_Uart_Status[UartIdx])
 		     {
@@ -369,7 +347,7 @@ Std_ReturnType UART_Send_Data(uint8 transChannel, const uint8 *txBuffer, uint32
 		    	 UartSendState[UartIdx] = UartStartSend;
 		     }
 		 }
-		 /*开始发送后的判定*/
+		 /*寮€濮嬪彂閫佸悗鐨勫垽瀹�*/
 		 if(UartSendState[UartIdx] == UartStartSend)
 		 {
 			 Uart_TransmitStatus[UartIdx] = Uart_GetStatus(UartIdx, &T_bytesRemaining[UartIdx], UART_SEND);

+ 6 - 13
src/hal_adapter.h → code/hal/hal_adapter.h

@@ -9,8 +9,8 @@
  */
 /*
  * hal_adapter.h
- *Öмä²ãº¯Êýµ÷Óÿâ
- *  Created on: 2022Äê1ÔÂ18ÈÕ
+ *中间层函数调用库
+ *  Created on: 2022年1月18日
  *      Author: QiXiang_CHENJIE
  */
 
@@ -43,7 +43,7 @@
 #include "SL_Sc7a20_Driver.h"
 #include "SEGGER_RTT_Conf.h"
 #include "SEGGER_RTT.h"
-/*ÊÊÓ¦ÐÔ¶¨Òå*/
+/*适应性定义*/
 typedef unsigned char UINT8;
 typedef unsigned short UINT16;
 typedef unsigned long UINT32;
@@ -52,8 +52,6 @@ typedef signed char INT8;
 typedef signed short INT16;
 typedef signed long INT32;
 
-#define UARTPRINTF 0
-#define SEGGER_PRINTF 1
 #define CAN0 0
 #define CAN1 1
 #ifndef min
@@ -62,9 +60,9 @@ typedef signed long INT32;
 #ifndef max
 #define max(A, B) ((A) < (B) ? (B) : (A))
 #endif
-#define getbit(x, y) ((x) >> (y)&1) //»ñÈ¡xµÄµÚyλµÄÊýÖµ
-#define setbit(x, y) x |= (1 << y)  // xµÄµÚyλÖÃ1
-#define clrbit(x, y) x &= ~(1 << y) // xµÄµÚyλÖÃ0
+#define getbit(x, y) ((x) >> (y)&1) //获�x的第y�的数值
+#define setbit(x, y) x |= (1 << y)  // x的第y�置1
+#define clrbit(x, y) x &= ~(1 << y) // x的第y�置0
 #define UART_LPUART0 0
 #define UART_LPUART1 1
 #define UART_LPUART2 2
@@ -249,9 +247,4 @@ void create_ringBuffer(ringbuffer_t *ringBuf, uint8_t *buf, uint32_t buf_len);
 void clear_ringBuffer(ringbuffer_t *ringBuf);
 uint32_t write_ringBuffer(uint8_t *buffer, uint32_t size, ringbuffer_t *ringBuf);
 uint32_t read_ringBuffer(uint8_t *buffer, uint32_t size, ringbuffer_t *ringBuf);
-#if UARTPRINTF==1
-	uint16 myPrintf(const char *fmt, ...);
-	extern uint8 ringbuffer[1024];
-	extern ringbuffer_t printfRingBuffer;
-#endif
 #endif /* HAL_ADAPTER_H_ */

+ 11 - 7
src/main.c → code/main.c

@@ -24,7 +24,7 @@
 
 /**
  *   @file main.c
- * Ö÷º¯ÊýÈë¿Ú
+ * 主函数入�
  *   @addtogroup main_module main module documentation
  *   @{
  */
@@ -61,7 +61,7 @@
 #include "AppTaskCan.h"
 #include "AppTaskGps.h"
 #include "Hal_Fls.h"
-
+#include "SEGGER_SYSVIEW.h"
 #include "cm_backtrace.h"
 #define APPNAME                        "S32K146_4G"
 #define HARDWARE_VERSION               "V1.0.0"
@@ -168,12 +168,16 @@ int main(void)
 	Dio_WriteChannel(DioConf_DioChannel_PTE7_GPIO_OUT_MCU_LED3, STD_OFF);
 	Dio_WriteChannel(DioConf_DioChannel_PTE8_GPIO_OUT_MCU_LED4, STD_OFF);
 	Dio_WriteChannel(DioConf_DioChannel_PTE9_GPIO_OUT_MCU_LED5, STD_OFF);
-	Mcu_ResetType bootreason;
-	bootreason = Mcu_GetResetReason();
-	cm_backtrace_init(APPNAME,HARDWARE_VERSION,SOFTWARE_VERSION);
-#if SEGGER_PRINTF==1
+
+#ifdef SEGGER_SYSTEMVIEW
+	SEGGER_SYSVIEW_Conf();
+	SEGGER_SYSVIEW_Start();
+#endif
+
+#ifdef SEGGER_RTT_PRINTF
 	SEGGER_RTT_Init();
-	SEGGER_RTT_printf("[%d] boot -%d\r\n",__LINE__,bootreason);
+	cm_backtrace_init(APPNAME,HARDWARE_VERSION,SOFTWARE_VERSION);
+	SEGGER_RTT_printf("[%d] boot\r\n",__LINE__);
 #endif
 	UartInit();
 	xTaskCreate(MainTask, (const char *const)"MainTask", 256, (void *)0, main_TASK_PRIORITY + 6, NULL);

+ 0 - 97
src/AppGlobalVar.c

@@ -1,97 +0,0 @@
-/*
- * @Author       : ChenJie
- * @Date         : 2022-01-23 13:45:09
- * @Version      : V3.0
- * @LastEditors  : ChenJie
- * @LastEditTime : 2022-02-23 16:59:13
- * @Description  : file content
- * @FilePath     : \S32K146_4G\src\AppGlobalVar.c
- */
-/*
- * AppGlobalVar.c
- *应用层全局变量
- *  Created on: 2022年1月19日
- *      Author: QiXiang_CHENJIE
- */
-
-#include "AppGlobalVar.h"
-//测试
-
-//*????*//
-uint8 TcpbattSN[17] = {0x31}; //???SN??
-
-volatile uint32 TimerCounter = 0; // ms单位
-uint8 Fota_update_flag = 0;
-uint8 Fota_error_flag = 0;
-/*GPS*/
-QueueHandle_t GpsDataQueueHandle;
-sint16 xyzData[3] = {0};
-/*Hal_Can*/
-uint8 CanIf_u8TxConfirmCnt = 0U;
-boolean CanIf_bTxFlag = false;
-uint8 CanIf_u8RxIndicationCnt = 0U;
-boolean CanIf_bRxFlag = false;
-QueueHandle_t CanRecvQueueHandle;
-
-/*TCP相关变量*/
-bool TcpSysReboot = 1;//tcp无法联网时,重启使能
-char ImeiNum[15] = {0};
-char IccidNum[20] = {0};
-uint8 CSQValue = 0;
-sint8 SocketId = -1;//联网状态
-sint8 RegChkRet = 0;//驻网状态
-char WebSiteIp[20] = {0};
-uint8 TcpWorkState = 0;
-const char WebSiteName[] = "\"iotp.fast-fun.cn\"";
-uint16 WebSitePort = 8712;
-//const char WebSiteName[] = "\"nas.fast-fun.cn\"";
-//uint16 WebSitePort = 8812;
-
-#define EEP_START_SEC_VAR_INIT_8_NO_CACHEABLE
-#include "Eep_MemMap.h"
-AppConfigBody AppConfigInfo={false,false,{defaultSn},{0}};
-#define EEP_STOP_SEC_VAR_INIT_8_NO_CACHEABLE
-#include "Eep_MemMap.h"
-
-/*以下变量均为串口协议相关变量*/
-#ifdef APP_UART0_ENABLE
-AppDataBody AppDataInfo = {BMS_CELLNUM, BMS_TEMPNUM};
-uint16 avrgCellVol = 0;			 //平均电压
-uint16 bmsHwVersion = 0;
-uint32 bmsSwVersion = 0;
-uint16 battCellU[BMS_CELLNUM];	 //电池电压
-uint16 battI = 0;				 // BMS电流(tcp上传)
-uint16 battPackVol = 0;			 // bms电压
-uint16 maxCellVol = 0;			 //最大单体电压
-uint16 minCellVol = 0;			 //最小单体电压
-//uint16 socd_pct_vcuSoc = 0;		 // soc(tcp上传,精度0.1)
-//uint16 sohd_pct_bcuSoh = 0;		 // soh(tcp上传,精度0.1)
-uint32 battBalanceoInfo = 0;  //
-uint32 battProtectState = 0;	 // bms保护状态
-uint32 battWarningState = 0;	 // bms告警状态
-uint8 AvgBattTemp = 0;			 //平均单体温度
-uint8 battCellTemp[BMS_TEMPNUM]; //电池温度
-uint8 Battdesigncap = 0;		 //电池包设计容量
-uint8 battHeatEnableState = 0;	 // bms加热状态
-uint8 battMOSSwitchState = 0;	 // bms mos开关状态
-uint8 battSOC = 0;				 // bms发送soc
-uint8 battSOH = 0;				 // bms发送soh
-uint8 battWorkState = 0;		 // bms工作状态
-uint8 BmsOtherTemp = 0;			 // BMS其他温度,没有其他温度,为0
-uint8 maxCellTemp = 0;			 //最大单体温度
-uint8 minCellTemp = 0;			 //最小单体温度
-uint8 OtherTemp = 0;			 //通讯模块其他温度
-uint8 battHeatState = 0;
-uint8 battFanState = 0;
-uint8 battRelayState = 0;
-uint8 battConverState = 0;
-uint8 battSeparateEnable = 0;
-uint8 battSeparateCtlState = 0;
-uint8 battSeparateState = 0;
-uint16 ErrorArray[5] = {0};
-uint32 meterAllPwr[2] = {0};
-uint32 meterPosPwr[2] = {0};
-uint32 meterNegPwr[2] = {0};
-//test
-uint32 BattTempR[4] = {0xFF};
-#endif

+ 0 - 131
src/AppGlobalVar.h

@@ -1,131 +0,0 @@
-/*
- * @Author       : ChenJie
- * @Date         : 2022-01-23 13:45:09
- * @Version      : V3.0
- * @LastEditors  : ChenJie
- * @LastEditTime : 2022-02-23 17:02:37
- * @Description  : file content
- * @FilePath     : \S32K146_4G\src\AppGlobalVar.h
- */
-/*
- * AppGlobal.h
- *Ӧ�ò�ȫ�ֱ���
- *  Created on: 2022��1��19��
- *      Author: QiXiang_CHENJIE
- */
-#ifndef APPGLOBALVAR_H_
-#define APPGLOBALVAR_H_
-
-#define APP_UART0_ENABLE //ƽ����Ŀ
-//#define APP_CAN_ENABLE //�ؿ���Ŀ
-
-#include "hal_adapter.h"
-
-#define defaultSn "SPFPFL264S226D001"
-#define BATT_SN_LEN 17
-#define HWVERSION 0x0001
-#define BLSWVERSION 0x00000002
-#define DRVSWVERSION 0x00000004
-#define APPSWVERSION 0x00000105
-#define BMS_MANUFACTURE 0xFF
-#define BMS_INFO 0xFF
-#define DATA_MODULE_TYPE 0x02
-//*ȫ�ֱ���*//
-extern bool TcpSysReboot;
-extern uint8 TcpbattSN[17];
-extern uint8 VIN[17];
-extern volatile uint32 TimerCounter;
-extern uint8 Fota_update_flag;
-extern uint8 Fota_error_flag;
-typedef struct
-{
-    uint8 RealLen;
-    uint8 *DataPtr;
-} QueueDataTrans_Type;
-/*GPS*/
-extern QueueHandle_t GpsDataQueueHandle;
-extern sint16 xyzData[3];
-/*Hal_Can*/
-extern uint8 CanIf_u8TxConfirmCnt;
-extern boolean CanIf_bTxFlag;
-extern uint8 CanIf_u8RxIndicationCnt;
-extern boolean CanIf_bRxFlag;
-extern QueueHandle_t CanRecvQueueHandle;
-
-/*���±�����ΪTCP��ر���*/
-extern uint8 CSQValue;
-extern sint8 SocketId;
-extern sint8 RegChkRet;
-extern char WebSiteIp[20];
-extern const char WebSiteName[];
-extern uint16 WebSitePort;
-extern char ImeiNum[15];
-extern char IccidNum[20];
-extern uint8 TcpWorkState;
-typedef struct _AppEppType
-{
-	uint32 battDischrgAccCap; //单位maH
-	uint32 battDischrgAccEnrg;//单位wh
-	uint16 battCycleTimes;
-}AppEppBody;
-typedef struct _AppConfigType
-{
-	bool appSaveFlg;
-	bool eolFlg;
-	uint8 deviceSn[17];
-	AppEppBody AppDataInfo;
-	uint8 re[20];
-} AppConfigBody;
-extern AppConfigBody AppConfigInfo;
-
-/*���±�����Ϊ����Э����ر���*/
-#define BMS_CELLNUM 120
-#define BMS_TEMPNUM 40
-typedef struct _AppDataType
-{
-    uint8 BattCellCount; //���ģ�����
-    uint8 BattTempCount; //����¶ȸ���
-} AppDataBody;
-extern AppDataBody AppDataInfo;
-extern uint16 avrgCellVol;              //ƽ����ѹ
-extern uint16 battCellU[BMS_CELLNUM];   //��ص�ѹ
-extern uint16 battI;                    // BMS������tcp�ϴ���
-extern uint16 bmsHwVersion;
-extern uint32 bmsSwVersion;
-extern uint16 battPackVol;              // bms��ѹ
-
-extern uint16 maxCellVol;               //������ѹ
-extern uint16 minCellVol;               //��С�����ѹ
-//extern uint16 socd_pct_vcuSoc;          // soc(tcp�ϴ�������0.1)
-//extern uint16 sohd_pct_bcuSoh;          // soh(tcp�ϴ�������0.1)
-extern uint32 battBalanceoInfo;
-extern uint32 battProtectState;         // bms����״̬
-extern uint32 battWarningState;         // bms�澯״̬
-extern uint8 AvgBattTemp;               //ƽ�������¶�
-extern uint8 battCellTemp[BMS_TEMPNUM]; //����¶�
-extern uint8 Battdesigncap;             //��ذ��������
-extern uint8 battHeatEnableState;       // bms����ʹ��״̬
-extern uint8 battMOSSwitchState;        // bms mos����״̬
-extern uint8 battSOC;                   // bms����soc
-extern uint8 battSOH;                   // bms����soh
-extern uint8 battWorkState;             // bms����״̬
-extern uint8 BmsOtherTemp;              // BMS�����¶�
-extern uint8 maxCellTemp;               //������¶�
-extern uint8 minCellTemp;               //��С�����¶�
-extern uint8 OtherTemp;                 //ͨѶģ�������¶�
-extern uint8 battHeatState ;
-extern uint8 battFanState ;
-extern uint8 battRelayState ;
-extern uint8 battConverState ;
-extern uint8 battSeparateEnable ;
-extern uint8 battSeparateCtlState ;
-extern uint8 battSeparateState ;
-extern uint16 ErrorArray[5];
-extern uint32 meterAllPwr[2];
-extern uint32 meterPosPwr[2];
-extern uint32 meterNegPwr[2];
-extern uint32 BattTempR[4];
-extern uint32 battAccEnrg ;
-extern uint32 battAccCap ;
-extern uint16 battAccUseTimes ;
-#endif /* APPGLOBALVAR_H_ */

+ 0 - 16
src/AppTaskMain.h

@@ -1,16 +0,0 @@
-/*
- * AppTaskMain.h
- *
- *  Created on: 2022Äê2ÔÂ22ÈÕ
- *      Author: QiXiang_CHENJIE
- */
-
-#ifndef APPTASKMAIN_H_
-#define APPTASKMAIN_H_
-#include "hal_adapter.h"
-#include "AppFunclib.h"
-#include "AppGlobalVar.h"
-#include "Hal_Wdg.h"
-void MainTask(void *pvParameters);
-
-#endif /* APPTASKMAIN_H_ */

+ 0 - 476
src/AppTaskUart0.c

@@ -1,476 +0,0 @@
-/*
- * AppTaskUart0.c
- *
- *  Created on: 2022年2月22日
- *      Author: QiXiang_CHENJIE
- */
-#include "AppTaskUart0.h"
-#ifdef APP_UART0_ENABLE
-static process_Uart0 gProcess_Uart0_Task = PROCESS_UART_STATE_IDLE;
-#define PROC_UART0_STATE_SWITCH(a) (gProcess_Uart0_Task = a)
-bool bmsCellInfoDecode(uint8 *dataPtr);
-bool bmsOtherInfoDecode(uint8 *dataPtr);
-void battDataCalFunc(void);
-void Uart0Task(void *pvParameters)
-{
-	(void)pvParameters;
-	UartQueryType Uart0AskMsg;
-	uint16 Reg_Num = 0;
-	uint16 RegAddrBegin = 0;
-	uint16 CRC_chk_buffer = 0;
-	uint16 pReadLen = 0;
-	UartAnsType UartAnsData;
-	static uint8 writecounter = 0;
-	uint16 UartNoDataReadCounter = 0;
-	uint8 UartDataRecv[256];
-	while (1)
-	{
-		switch (gProcess_Uart0_Task)
-		{
-		case PROCESS_UART_STATE_IDLE:
-		{
-			vTaskDelay(pdMS_TO_TICKS(10));
-			if ((TimerCounter % 1000) == 0 && 1)
-			{
-				PROC_UART0_STATE_SWITCH(PROCESS_UART_STATE_READ);
-			}
-			else if (TimerCounter % 100 == 0)
-			{
-				PROC_UART0_STATE_SWITCH(PROCESS_UART_STATE_WRITE);
-			}
-			break;
-		}
-		case PROCESS_UART_STATE_READ:
-		{
-
-			static uint16 readCnt = 0;
-			/*电压电流数据读取(第一次读取)*/
-			pReadLen = 0;
-			Dio_FlipChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2);
-			RegAddrBegin = 0x00;
-			Reg_Num =AppDataInfo.BattCellCount + 3;
-			Uart0AskMsg.Bms_Address = BMS_ADDRESS_CODE;
-			Uart0AskMsg.Bms_Funcode = UART_READ_CODE;
-			Uart0AskMsg.Reg_Begin_H = RegAddrBegin>>8;
-			Uart0AskMsg.Reg_Begin_L = RegAddrBegin;
-			Uart0AskMsg.Reg_Num_H = Reg_Num >> 8;
-			Uart0AskMsg.Reg_Num_L = Reg_Num;
-			CRC_chk_buffer = crc_chk((uint8 *)&Uart0AskMsg, 6);
-			Uart0AskMsg.CRC_L = CRC_chk_buffer;
-			Uart0AskMsg.CRC_H = CRC_chk_buffer >> 8;
-			/*RS485查询命令需要使能*/
-			UART_Send_Data(UART_LPUART0, (uint8 *)&Uart0AskMsg, sizeof(Uart0AskMsg), 1000);
-			uint16 ReadLen1 = 0;
-			uint16 ReadLenTar = 0;
-			uint8 ReadDelayCounter = 0;
-			ReadLenTar = (Reg_Num)*2+5;
-			memset((uint8 *)&UartAnsData,0x00,sizeof(UartAnsData));
-			while(1)
-			{
-				UART_Receive_Data(UART_LPUART0, UartDataRecv, &pReadLen, 100);
-				if(pReadLen>2)
-				{
-					memcpy((uint8 *)&UartAnsData+ReadLen1,UartDataRecv,pReadLen);
-					ReadLen1 = ReadLen1 + pReadLen;
-				}
-				else
-				{
-					ReadDelayCounter++;
-				}
-				if(ReadLen1>=ReadLenTar)
-				{
-					ReadDelayCounter = 0;
-					pReadLen = ReadLen1;
-					ReadLen1 = 0;
-					break;
-				}
-				if(ReadDelayCounter>=20)
-				{
-					ReadDelayCounter = 0;
-					pReadLen = 0;
-					ReadLen1 = 0;
-					break;
-				}
-			}
-			if (pReadLen > 0)
-			{
-				uint16 CrcChkGet = 0xffff;
-				uint16 CrcChkCal = 0x0000;
-				CrcChkCal = crc_chk((uint8 *)&UartAnsData, pReadLen-2);
-				CrcChkGet = ((uint16)(UartAnsData.Data[pReadLen-1-3])<<8) | ((uint16)(UartAnsData.Data[pReadLen-2-3]));
-				if(CrcChkCal==CrcChkGet)
-				{
-					bmsCellInfoDecode(UartAnsData.Data);
-					UartNoDataReadCounter = 0;
-				}
-				else
-				{
-					UartNoDataReadCounter++;
-				}
-			}
-			else
-			{
-				UartNoDataReadCounter++;
-			}
-			/*温度及其他状态信息读取(第二次读取)*/
-			pReadLen = 0;
-			RegAddrBegin = 0x03 + AppDataInfo.BattCellCount;
-			Reg_Num = 0x1B + AppDataInfo.BattTempCount; //读取的寄存器数据,暂定,分开读取
-			Uart0AskMsg.Bms_Address = BMS_ADDRESS_CODE;
-			Uart0AskMsg.Bms_Funcode = UART_READ_CODE;
-			Uart0AskMsg.Reg_Begin_H = RegAddrBegin>>8;
-			Uart0AskMsg.Reg_Begin_L = RegAddrBegin;
-			Uart0AskMsg.Reg_Num_H = Reg_Num >> 8;
-			Uart0AskMsg.Reg_Num_L = Reg_Num;
-			CRC_chk_buffer = crc_chk((uint8 *)&Uart0AskMsg, 6);
-			Uart0AskMsg.CRC_L = CRC_chk_buffer;
-			Uart0AskMsg.CRC_H = CRC_chk_buffer >> 8;
-			/*RS485查询命令需要使能*/
-			UART_Send_Data(UART_LPUART0, (uint8 *)&Uart0AskMsg, sizeof(Uart0AskMsg), 1000);
-			memset((uint8 *)&UartAnsData,0x00,sizeof(UartAnsData));
-			ReadLenTar = (Reg_Num)*2+5;
-			while(1)
-			{
-				UART_Receive_Data(UART_LPUART0, UartDataRecv, &pReadLen, 100);
-				if(pReadLen>2)
-				{
-					memcpy((uint8 *)&UartAnsData+ReadLen1,UartDataRecv,pReadLen);
-					ReadLen1 = ReadLen1 + pReadLen;
-				}
-				else
-				{
-					ReadDelayCounter++;
-				}
-				if(ReadLen1>=ReadLenTar)
-				{
-					ReadDelayCounter = 0;
-					pReadLen = ReadLen1;
-					ReadLen1 = 0;
-					break;
-				}
-				if(ReadDelayCounter>=20)
-				{
-					ReadDelayCounter = 0;
-					pReadLen = 0;
-					ReadLen1 = 0;
-					break;
-				}
-			}
-			if (pReadLen > 0)
-			{
-				uint16 CrcChkGet = 0xffff;
-				uint16 CrcChkCal = 0x0000;
-				CrcChkCal = crc_chk((uint8 *)&UartAnsData, pReadLen-2);
-				CrcChkGet =  ((uint16)(UartAnsData.Data[pReadLen-1-3])<<8) | ((uint16)(UartAnsData.Data[pReadLen-2-3]));
-				if(CrcChkCal==CrcChkGet)
-				{
-					bmsOtherInfoDecode(UartAnsData.Data);
-					UartNoDataReadCounter = 0;
-				}
-				else
-				{
-					UartNoDataReadCounter++;
-				}
-			}
-			else
-			{
-				UartNoDataReadCounter++;
-			}
-			//没有读到数据时的默认值
-			if(UartNoDataReadCounter>10)
-			{
-				memset((uint8 *)&UartAnsData,0x00,sizeof(UartAnsData));
-				bmsCellInfoDecode(UartAnsData.Data);
-				bmsOtherInfoDecode(UartAnsData.Data);
-				PutErrorNum(ErrorArray, sizeof(ErrorArray)/2, 1);
-				vTaskDelay(pdMS_TO_TICKS(5000));
-			}
-			if(readCnt%10==0||0)
-			{
-				/**电表数据读取*/
-				for(uint8 i=0;i<2;i++)
-				{
-					/*电表参数读取*/
-					static uint16 pt[2] = {0};
-					static uint16 ct[2] = {0};
-					pReadLen = 0;
-					RegAddrBegin = 0x03;
-					Reg_Num = 0x02;
-					Uart0AskMsg.Bms_Address = METER1_ADDRESS_CODE+i;//第一次读02,第二次读03
-					Uart0AskMsg.Bms_Funcode = UART_READ_CODE;
-					Uart0AskMsg.Reg_Begin_H = RegAddrBegin>>8;
-					Uart0AskMsg.Reg_Begin_L = RegAddrBegin;
-					Uart0AskMsg.Reg_Num_H = Reg_Num >> 8;
-					Uart0AskMsg.Reg_Num_L = Reg_Num;
-					CRC_chk_buffer = crc_chk((uint8 *)&Uart0AskMsg, 6);
-					Uart0AskMsg.CRC_L = CRC_chk_buffer;
-					Uart0AskMsg.CRC_H = CRC_chk_buffer >> 8;
-					UART_Send_Data(UART_LPUART0, (uint8 *)&Uart0AskMsg, sizeof(Uart0AskMsg), 100);
-					UART_Receive_Data(UART_LPUART0, UartDataRecv, &pReadLen, 1000);
-					//电表数据解析
-					if (pReadLen > 5)
-					{
-						uint16 CrcChkGet = 0xffff;
-						uint16 CrcChkCal = 0x0000;
-						CrcChkCal = crc_chk(UartDataRecv, pReadLen-2);
-						CrcChkGet =  ((uint16)(*(UartDataRecv+pReadLen-1))<<8) | ((uint16)(*(UartDataRecv+pReadLen-2)));
-						if(CrcChkCal==CrcChkGet)
-						{
-							pt[i] = ((uint16)(*(UartDataRecv+3))<<8) | ((uint16)(*(UartDataRecv+4)));
-							ct[i] = ((uint16)(*(UartDataRecv+5))<<8) | ((uint16)(*(UartDataRecv+6)));
-						}
-					}
-					/*电表电量数据读取*/
-					pReadLen = 0;
-					RegAddrBegin = 0x3F;
-					Reg_Num = 0x04;
-					Uart0AskMsg.Bms_Address = METER1_ADDRESS_CODE+i;//第一次读02,第二次读03
-					Uart0AskMsg.Bms_Funcode = UART_READ_CODE;
-					Uart0AskMsg.Reg_Begin_H = RegAddrBegin>>8;
-					Uart0AskMsg.Reg_Begin_L = RegAddrBegin;
-					Uart0AskMsg.Reg_Num_H = Reg_Num >> 8;
-					Uart0AskMsg.Reg_Num_L = Reg_Num;
-					CRC_chk_buffer = crc_chk((uint8 *)&Uart0AskMsg, 6);
-					Uart0AskMsg.CRC_L = CRC_chk_buffer;
-					Uart0AskMsg.CRC_H = CRC_chk_buffer >> 8;
-					UART_Send_Data(UART_LPUART0, (uint8 *)&Uart0AskMsg, sizeof(Uart0AskMsg), 100);
-					UART_Receive_Data(UART_LPUART0, UartDataRecv, &pReadLen, 1000);
-					//电表数据解析
-					if (pReadLen > 5)
-					{
-						uint16 CrcChkGet = 0xffff;
-						uint16 CrcChkCal = 0x0000;
-						CrcChkCal = crc_chk(UartDataRecv, pReadLen-2);
-						CrcChkGet =  ((uint16)(*(UartDataRecv+pReadLen-1))<<8) | ((uint16)(*(UartDataRecv+pReadLen-2)));
-						if(CrcChkCal==CrcChkGet)
-						{
-							//meterAllPwr[i] = pt[i]*ct[i]*(((uint32)(*(UartRecvPtr+3))<<24)|((uint32)(*(UartRecvPtr+4))<<16)|((uint32)(*(UartRecvPtr+5))<<8) | ((uint32)(*(UartRecvPtr+6))));
-							meterPosPwr[i] = pt[i]*ct[i]*((uint32)(*(UartDataRecv+3))<<24)|((uint32)(*(UartDataRecv+4))<<16)|((uint32)(*(UartDataRecv+5))<<8) | ((uint32)(*(UartDataRecv+6)));
-							meterNegPwr[i] = pt[i]*ct[i]*((uint32)(*(UartDataRecv+7))<<24)|((uint32)(*(UartDataRecv+8))<<16)|((uint32)(*(UartDataRecv+9))<<8) | ((uint32)(*(UartDataRecv+10)));
-							meterPosPwr[i] = meterPosPwr[i] * 100;
-							meterNegPwr[i] = meterNegPwr[i] * 100;
-							meterAllPwr[i] = meterPosPwr[i] + meterNegPwr[i];
-						}
-					}
-				}
-			}
-			readCnt++;
-			PROC_UART0_STATE_SWITCH(PROCESS_UART_STATE_IDLE);
-			break;
-		}
-		case PROCESS_UART_STATE_WRITE:
-		{
-			if(battSeparateEnable)//最多重新写5次
-			{
-				uint16 RegAddress = 0;
-				uint16 CRC_chk_buffer = 0;
-				uint8 WriteData[2] = {0x00,0x00};
-				uint8 UartRecvBuffer[10];
-				if(!battSeparateCtlState)
-				{
-					setbit(WriteData[0],7);
-				}
-				else
-				{
-					clrbit(WriteData[0],7);
-				}
-				RegAddress = 0x1B + AppDataInfo.BattCellCount + AppDataInfo.BattTempCount;
-				UartWriteMsgType Uart_Write_Msg;
-				Uart_Write_Msg.Bms_Address = BMS_ADDRESS_CODE;
-				Uart_Write_Msg.Bms_Funcode = UART_WRITE_CODE;
-				Uart_Write_Msg.Reg_Begin_H = RegAddress >> 8;
-				Uart_Write_Msg.Reg_Begin_L = RegAddress;
-				Uart_Write_Msg.Reg_Num_H = 0x00;
-				Uart_Write_Msg.Reg_Num_L = 0x01;
-				Uart_Write_Msg.Data_Count = 0x02; //要写入的字节数
-				memcpy(Uart_Write_Msg.Data, WriteData, 2);
-				CRC_chk_buffer = crc_chk((uint8 *)&Uart_Write_Msg, sizeof(Uart_Write_Msg) - 2);
-				Uart_Write_Msg.CRC_L = CRC_chk_buffer;
-				Uart_Write_Msg.CRC_H = CRC_chk_buffer >> 8;
-				UART_Query_Data(UART_LPUART0,UART_LPUART0,(uint8 *)&Uart_Write_Msg,sizeof(Uart_Write_Msg),UartRecvBuffer, &pReadLen,500);
-				if (pReadLen>3&&*(UartRecvBuffer+1) == 0x10)
-				{
-					writecounter = 0;
-					battSeparateEnable = 0;
-				}
-				else
-				{
-					writecounter++;
-				}
-			}
-			if(writecounter>=5)
-			{
-				battSeparateEnable = 0;
-				writecounter = 0;
-			}
-			PROC_UART0_STATE_SWITCH(PROCESS_UART_STATE_IDLE);
-			break;
-		}
-		case PROCESS_UART_STATE_SLEEP:
-		{
-			break;
-		}
-		default:
-			break;
-		}
-	}
-}
-bool bmsCellInfoDecode(uint8 *dataPtr) //根据串口协议确定的解码函数,电压电流解码
-{
-	uint8 i = 0;
-	sint8 BattCurrentNegFlag = 1;
-	uint16 Batt_current;
-	uint8 BATT_CELL_VOL_NUM = 0, BATT_TEMP_NUM = 0;
-	uint32 Battsumvoltage = 0;
-	BATT_CELL_VOL_NUM = (dataPtr[(0x00) * 2] << 8) | (dataPtr[(0x00) * 2 + 1]);
-	BATT_TEMP_NUM = ((dataPtr[(0x01) * 2] << 8) | (dataPtr[(0x01) * 2 + 1])) - BmsOtherTemp;
-	if (BATT_CELL_VOL_NUM != AppDataInfo.BattCellCount || BATT_TEMP_NUM != AppDataInfo.BattTempCount)
-	{
-		BATT_CELL_VOL_NUM = AppDataInfo.BattCellCount;
-		BATT_TEMP_NUM = AppDataInfo.BattTempCount;
-	}
-	Batt_current = (dataPtr[(0x02 + BATT_CELL_VOL_NUM) * 2] << 8) | (dataPtr[(0x02 + BATT_CELL_VOL_NUM) * 2 + 1]);
-	Batt_current = Batt_current*100;//平峰协议单位是1A
-	//原始数据:充电为负,放电为正
-	if (Batt_current < 0x8000) //充电过程
-	{
-		if (Batt_current > 0x8000) // 数据为负
-		{
-			//求补码,结果为负
-			Batt_current = (uint16)((uint16)(~(Batt_current)) + 1);
-			Batt_current = Batt_current / 10;
-			BattCurrentNegFlag = -1;
-		}
-		else
-		{
-			//源码,结果为负
-			Batt_current = Batt_current / 10;
-			BattCurrentNegFlag = -1;
-		}
-	}
-	else //放电过程
-	{
-		if (Batt_current > 0x8000) // 数据为负
-		{
-			//求补码,结果为正
-			Batt_current = (uint16)((uint16)(~(Batt_current)) + 1);
-			Batt_current = Batt_current / 10;
-			BattCurrentNegFlag = 1;
-		}
-		else
-		{
-			//源码,结果为正
-			Batt_current = Batt_current / 10;
-			BattCurrentNegFlag = 1;
-		}
-	}
-	battI = Batt_current * BattCurrentNegFlag + 0x2710;
-	// sint16 BattI_Temp = 0;//做电压补偿需要的参数
-	// BattI_Temp = Batt_current * BattCurrentNegFlag;
-	for (i = 0; i < BATT_CELL_VOL_NUM; i++)
-	{
-		//battCellU[i] = ((dataPtr[(0x02 + i) * 2] << 8) | dataPtr[(0x02 + i) * 2 + 1]) + (INT16)(cmnm_R_voloffset[i] * BattI_Temp / 10000);//不使用电压补偿
-		battCellU[i] = ((dataPtr[(0x02 + i) * 2] << 8) | dataPtr[(0x02 + i) * 2 + 1]);
-		Battsumvoltage = Battsumvoltage + battCellU[i];
-	}
-	avrgCellVol = Battsumvoltage / BATT_CELL_VOL_NUM;
-	battPackVol = Battsumvoltage/100;
-	battDataCalFunc();
-	return true;
-}
-bool bmsOtherInfoDecode(uint8 *dataPtr)//其他数据解析
-{
-	uint8 TEMP_NUM = 0, temp = 0;
-
-	sint8 OtherInfoAddrOffset = -3;//其他数据解析的起始位置改变,需要向前减3
-	TEMP_NUM = AppDataInfo.BattTempCount + BmsOtherTemp;
-	 bmsHwVersion = dataPtr[(0x08 + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1];
-	 bmsSwVersion = dataPtr[(0x08 + OtherInfoAddrOffset + TEMP_NUM) * 2];
-
-	temp = ((dataPtr[(0x09 + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1]) >> 1) & 0x03;
-	battMOSSwitchState = ((temp & 0x01) << 1) | ((temp & 0x02) >> 1);
-	battSOC = dataPtr[(0x0B + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1];
-	battSOH = dataPtr[(0x0C + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1];
-	Battdesigncap = (dataPtr[(0x0E + OtherInfoAddrOffset + TEMP_NUM) * 2]) << 24 | (dataPtr[(0x0E + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1]) << 16 | (dataPtr[(0x0F + OtherInfoAddrOffset + TEMP_NUM) * 2]) << 8 | (dataPtr[(0x0F + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1]);
-//	battPackVol = ((dataPtr[(0x18 + OtherInfoAddrOffset + TEMP_NUM) * 2]) << 8 | (dataPtr[(0x18 + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1])) / 10; // uint 100mV
-	maxCellVol = (dataPtr[(0x19 + OtherInfoAddrOffset + TEMP_NUM) * 2] << 8) | dataPtr[(0x19 + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1];
-	minCellVol = (dataPtr[(0x1A + OtherInfoAddrOffset + TEMP_NUM) * 2] << 8) | dataPtr[(0x1A + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1];
-	for (uint8 i = 0; i < AppDataInfo.BattTempCount; i++)
-	{
-		battCellTemp[i] = dataPtr[(0x06 + OtherInfoAddrOffset + i) * 2 + 1];
-	}
-	battWorkState = (dataPtr[(0x03 + OtherInfoAddrOffset) * 2 + 1]) & 0x03; //电池状态(原始数据),0表示静置,1表示放电,2表示充电
-	//状态量上传
-	battHeatState = getbit(dataPtr[(0x09 + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1],5);
-	battFanState = getbit(dataPtr[(0x09 + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1],3);
-	battRelayState = getbit(dataPtr[(0x09 + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1],4);
-	battConverState = getbit(dataPtr[(0x09 + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1],6);
-	battSeparateState = !getbit(dataPtr[(0x1B + OtherInfoAddrOffset + TEMP_NUM) * 2],7);
-	if (battSeparateState==1)
-	{
-		battMOSSwitchState = battMOSSwitchState | (0x01 << 2);
-	}
-	else
-	{
-		battMOSSwitchState = battMOSSwitchState | (0x00 << 2);
-	}
-	//故障状态映关系(先完成告警状态简单上传)
-	uint8 ErrorArrayTemp[32] ={0};
-	uint8 ErrorArrayNumTemp[32]={81,87,83,89,97,99,132,131,134,84,90,82,88,135,136,98,100};
-	ErrorArrayTemp[0] = getbit(dataPtr[(0x03 + OtherInfoAddrOffset) * 2],0);//电芯电压过高切断告警-0-81
-	ErrorArrayTemp[1] = getbit(dataPtr[(0x03 + OtherInfoAddrOffset) * 2],1);//总压过高切断告警-1-87
-	ErrorArrayTemp[2] = getbit(dataPtr[(0x04 + OtherInfoAddrOffset) * 2 + 1],0);//电芯电压过低切断告警2-83
-	ErrorArrayTemp[3] = getbit(dataPtr[(0x04 + OtherInfoAddrOffset) * 2 + 1],1);//总压过低切断告警3-89
-	ErrorArrayTemp[4] = getbit(dataPtr[(0x04 + OtherInfoAddrOffset) * 2],4);//单节温度过高切断4-97
-	ErrorArrayTemp[5] = getbit(dataPtr[(0x04 + OtherInfoAddrOffset) * 2],5);//单节温度过低切断5-99
-	ErrorArrayTemp[6] = getbit(dataPtr[(0x05 + OtherInfoAddrOffset) * 2 + 1],1);//放电电流切断6-132
-	ErrorArrayTemp[7] = getbit(dataPtr[(0x05 + OtherInfoAddrOffset) * 2 + 1],2);//充电电流切断7-131
-	ErrorArrayTemp[8] = getbit(dataPtr[(0x05 + OtherInfoAddrOffset) * 2 + 1],3);//BTU连接告警8-134
-	ErrorArrayTemp[9] = getbit(dataPtr[(0x0A + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1],0);//单节电压下限告警9-84
-	ErrorArrayTemp[10] = getbit(dataPtr[(0x0A + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1],1);//组电压下限告警10-90
-	ErrorArrayTemp[11] = getbit(dataPtr[(0x0A + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1],2);//单节电压上限告警11-82
-	ErrorArrayTemp[12] = getbit(dataPtr[(0x0A + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1],3);//组单节电压上限告警12-88
-	ErrorArrayTemp[13] = getbit(dataPtr[(0x0A + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1],4);//放电电流告警13-135
-	ErrorArrayTemp[14] = getbit(dataPtr[(0x0A + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1],5);//充电电流告警14-136
-	ErrorArrayTemp[15] = getbit(dataPtr[(0x0A + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1],6);//单节温度上限告警15-98
-	ErrorArrayTemp[16] = getbit(dataPtr[(0x0A + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1],7);//单节温度下线告警16-100
-	for(uint8 i=0,j=0;(i<32&&j<5);i++)
-	{
-		if(ErrorArrayTemp[i]==1)
-		{
-			PutErrorNum(ErrorArray, sizeof(ErrorArray)/2, ErrorArrayNumTemp[i]);
-			j++;
-		}
-	}
-	return true;
-}
-void battDataCalFunc(void)
-{
-	static uint32 timercounterCal = 0;
-	uint16 timediff = 0;
-	float battCapTempOnce = 0;
-	static float battCapTemp = 0;
-	static float battEnrgTemp = 0;
-	timediff = TimerCounter - timercounterCal;
-	timercounterCal = TimerCounter;
-	if(timediff==0 ||timediff>60*1000)
-	{
-		return;
-	}
-	if(battI>10000)
-	{
-		battCapTempOnce = ((battI - 10000)/10.0)*(timediff/3600.0);
-		battCapTemp =  battCapTempOnce + battCapTemp;
-		battEnrgTemp = (battCapTempOnce*battPackVol)/10000.0 + battEnrgTemp;
-		if(battEnrgTemp>10)
-		{
-			AppConfigInfo.AppDataInfo.battDischrgAccCap = AppConfigInfo.AppDataInfo.battDischrgAccCap + (uint32)battCapTemp;
-			AppConfigInfo.AppDataInfo.battDischrgAccEnrg = AppConfigInfo.AppDataInfo.battDischrgAccEnrg + (uint32)battEnrgTemp;
-			AppConfigInfo.AppDataInfo.battCycleTimes = AppConfigInfo.AppDataInfo.battDischrgAccEnrg/49000;
-			AppConfigInfo.appSaveFlg = true;
-			battEnrgTemp = 0;
-			battCapTemp = 0;
-		}
-	}
-}
-#endif

+ 0 - 249
src/SEGGER_RTT.h

@@ -1,249 +0,0 @@
-/*********************************************************************
-*                SEGGER Microcontroller GmbH & Co. KG                *
-*                        The Embedded Experts                        *
-**********************************************************************
-*                                                                    *
-*       (c) 2014 - 2016  SEGGER Microcontroller GmbH & Co. KG        *
-*                                                                    *
-*       www.segger.com     Support: support@segger.com               *
-*                                                                    *
-**********************************************************************
-*                                                                    *
-*       SEGGER RTT * Real Time Transfer for embedded targets         *
-*                                                                    *
-**********************************************************************
-*                                                                    *
-* All rights reserved.                                               *
-*                                                                    *
-* SEGGER strongly recommends to not make any changes                 *
-* to or modify the source code of this software in order to stay     *
-* compatible with the RTT protocol and J-Link.                       *
-*                                                                    *
-* Redistribution and use in source and binary forms, with or         *
-* without modification, are permitted provided that the following    *
-* conditions are met:                                                *
-*                                                                    *
-* o Redistributions of source code must retain the above copyright   *
-*   notice, this list of conditions and the following disclaimer.    *
-*                                                                    *
-* o Redistributions in binary form must reproduce the above          *
-*   copyright notice, this list of conditions and the following      *
-*   disclaimer in the documentation and/or other materials provided  *
-*   with the distribution.                                           *
-*                                                                    *
-* o Neither the name of SEGGER Microcontroller GmbH & Co. KG         *
-*   nor the names of its contributors may be used to endorse or      *
-*   promote products derived from this software without specific     *
-*   prior written permission.                                        *
-*                                                                    *
-* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND             *
-* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,        *
-* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF           *
-* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE           *
-* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
-* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR           *
-* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT  *
-* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;    *
-* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF      *
-* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT          *
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE  *
-* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH   *
-* DAMAGE.                                                            *
-*                                                                    *
-**********************************************************************
-*                                                                    *
-*       RTT version: 6.10i                                           *
-*                                                                    *
-**********************************************************************
----------------------------END-OF-HEADER------------------------------
-File    : SEGGER_RTT.h
-Purpose : Implementation of SEGGER real-time transfer which allows
-          real-time communication on targets which support debugger 
-          memory accesses while the CPU is running.
-Revision: $Rev: 4351 $
-----------------------------------------------------------------------
-*/
-
-#ifndef SEGGER_RTT_H
-#define SEGGER_RTT_H
-
-#include "SEGGER_RTT_Conf.h"
-
-/*********************************************************************
-*
-*       Defines, fixed
-*
-**********************************************************************
-*/
-
-/*********************************************************************
-*
-*       Types
-*
-**********************************************************************
-*/
-
-//
-// Description for a circular buffer (also called "ring buffer")
-// which is used as up-buffer (T->H)
-//
-typedef struct {
-  const     char*    sName;         // Optional name. Standard names so far are: "Terminal", "SysView", "J-Scope_t4i4"
-            char*    pBuffer;       // Pointer to start of buffer
-            unsigned SizeOfBuffer;  // Buffer size in bytes. Note that one byte is lost, as this implementation does not fill up the buffer in order to avoid the problem of being unable to distinguish between full and empty.
-            unsigned WrOff;         // Position of next item to be written by either target.
-  volatile  unsigned RdOff;         // Position of next item to be read by host. Must be volatile since it may be modified by host.
-            unsigned Flags;         // Contains configuration flags
-} SEGGER_RTT_BUFFER_UP;
-
-//
-// Description for a circular buffer (also called "ring buffer")
-// which is used as down-buffer (H->T)
-//
-typedef struct {
-  const     char*    sName;         // Optional name. Standard names so far are: "Terminal", "SysView", "J-Scope_t4i4"
-            char*    pBuffer;       // Pointer to start of buffer
-            unsigned SizeOfBuffer;  // Buffer size in bytes. Note that one byte is lost, as this implementation does not fill up the buffer in order to avoid the problem of being unable to distinguish between full and empty.
-  volatile  unsigned WrOff;         // Position of next item to be written by host. Must be volatile since it may be modified by host.
-            unsigned RdOff;         // Position of next item to be read by target (down-buffer).
-            unsigned Flags;         // Contains configuration flags
-} SEGGER_RTT_BUFFER_DOWN;
-
-//
-// RTT control block which describes the number of buffers available
-// as well as the configuration for each buffer
-//
-//
-typedef struct {
-  char                    acID[16];                                 // Initialized to "SEGGER RTT"
-  int                     MaxNumUpBuffers;                          // Initialized to SEGGER_RTT_MAX_NUM_UP_BUFFERS (type. 2)
-  int                     MaxNumDownBuffers;                        // Initialized to SEGGER_RTT_MAX_NUM_DOWN_BUFFERS (type. 2)
-  SEGGER_RTT_BUFFER_UP    aUp[SEGGER_RTT_MAX_NUM_UP_BUFFERS];       // Up buffers, transferring information up from target via debug probe to host
-  SEGGER_RTT_BUFFER_DOWN  aDown[SEGGER_RTT_MAX_NUM_DOWN_BUFFERS];   // Down buffers, transferring information down from host via debug probe to target
-} SEGGER_RTT_CB;
-
-/*********************************************************************
-*
-*       Global data
-*
-**********************************************************************
-*/
-extern SEGGER_RTT_CB _SEGGER_RTT;
-
-/*********************************************************************
-*
-*       RTT API functions
-*
-**********************************************************************
-*/
-#ifdef __cplusplus
-  extern "C" {
-#endif
-int          SEGGER_RTT_AllocDownBuffer         (const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
-int          SEGGER_RTT_AllocUpBuffer           (const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
-int          SEGGER_RTT_ConfigUpBuffer          (unsigned BufferIndex, const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
-int          SEGGER_RTT_ConfigDownBuffer        (unsigned BufferIndex, const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
-int          SEGGER_RTT_GetKey                  (void);
-unsigned     SEGGER_RTT_HasData                 (unsigned BufferIndex);
-int          SEGGER_RTT_HasKey                  (void);
-void         SEGGER_RTT_Init                    (void);
-unsigned     SEGGER_RTT_Read                    (unsigned BufferIndex,       void* pBuffer, unsigned BufferSize);
-unsigned     SEGGER_RTT_ReadNoLock              (unsigned BufferIndex,       void* pData,   unsigned BufferSize);
-int          SEGGER_RTT_SetNameDownBuffer       (unsigned BufferIndex, const char* sName);
-int          SEGGER_RTT_SetNameUpBuffer         (unsigned BufferIndex, const char* sName);
-int          SEGGER_RTT_SetFlagsDownBuffer      (unsigned BufferIndex, unsigned Flags);
-int          SEGGER_RTT_SetFlagsUpBuffer        (unsigned BufferIndex, unsigned Flags);
-int          SEGGER_RTT_WaitKey                 (void);
-unsigned     SEGGER_RTT_Write                   (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
-unsigned     SEGGER_RTT_WriteNoLock             (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
-unsigned     SEGGER_RTT_WriteSkipNoLock         (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
-unsigned     SEGGER_RTT_WriteString             (unsigned BufferIndex, const char* s);
-void         SEGGER_RTT_WriteWithOverwriteNoLock(unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
-//
-// Function macro for performance optimization
-//
-#define      SEGGER_RTT_HASDATA(n)       (_SEGGER_RTT.aDown[n].WrOff - _SEGGER_RTT.aDown[n].RdOff)
-
-/*********************************************************************
-*
-*       RTT "Terminal" API functions
-*
-**********************************************************************
-*/
-int     SEGGER_RTT_SetTerminal        (char TerminalId);
-int     SEGGER_RTT_TerminalOut        (char TerminalId, const char* s);
-
-/*********************************************************************
-*
-*       RTT printf functions (require SEGGER_RTT_printf.c)
-*
-**********************************************************************
-*/
-//int SEGGER_RTT_printf(unsigned BufferIndex, const char * sFormat, ...);
-int SEGGER_RTT_printf(const char * sFormat, ...);
-#ifdef __cplusplus
-  }
-#endif
-
-/*********************************************************************
-*
-*       Defines
-*
-**********************************************************************
-*/
-
-//
-// Operating modes. Define behavior if buffer is full (not enough space for entire message)
-//
-#define SEGGER_RTT_MODE_NO_BLOCK_SKIP         (0U)     // Skip. Do not block, output nothing. (Default)
-#define SEGGER_RTT_MODE_NO_BLOCK_TRIM         (1U)     // Trim: Do not block, output as much as fits.
-#define SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL    (2U)     // Block: Wait until there is space in the buffer.
-#define SEGGER_RTT_MODE_MASK                  (3U)
-
-//
-// Control sequences, based on ANSI.
-// Can be used to control color, and clear the screen
-//
-#define RTT_CTRL_RESET                ""         // Reset to default colors
-#define RTT_CTRL_CLEAR                ""         // Clear screen, reposition cursor to top left
-
-#define RTT_CTRL_TEXT_BLACK           ""
-#define RTT_CTRL_TEXT_RED             ""
-#define RTT_CTRL_TEXT_GREEN           ""
-#define RTT_CTRL_TEXT_YELLOW          ""
-#define RTT_CTRL_TEXT_BLUE            ""
-#define RTT_CTRL_TEXT_MAGENTA         ""
-#define RTT_CTRL_TEXT_CYAN            ""
-#define RTT_CTRL_TEXT_WHITE           ""
-
-#define RTT_CTRL_TEXT_BRIGHT_BLACK    ""
-#define RTT_CTRL_TEXT_BRIGHT_RED      ""
-#define RTT_CTRL_TEXT_BRIGHT_GREEN    ""
-#define RTT_CTRL_TEXT_BRIGHT_YELLOW   ""
-#define RTT_CTRL_TEXT_BRIGHT_BLUE     ""
-#define RTT_CTRL_TEXT_BRIGHT_MAGENTA  ""
-#define RTT_CTRL_TEXT_BRIGHT_CYAN     ""
-#define RTT_CTRL_TEXT_BRIGHT_WHITE    ""
-
-#define RTT_CTRL_BG_BLACK             ""
-#define RTT_CTRL_BG_RED               ""
-#define RTT_CTRL_BG_GREEN             ""
-#define RTT_CTRL_BG_YELLOW            ""
-#define RTT_CTRL_BG_BLUE              ""
-#define RTT_CTRL_BG_MAGENTA           ""
-#define RTT_CTRL_BG_CYAN              ""
-#define RTT_CTRL_BG_WHITE             ""
-
-#define RTT_CTRL_BG_BRIGHT_BLACK      ""
-#define RTT_CTRL_BG_BRIGHT_RED        ""
-#define RTT_CTRL_BG_BRIGHT_GREEN      ""
-#define RTT_CTRL_BG_BRIGHT_YELLOW     ""
-#define RTT_CTRL_BG_BRIGHT_BLUE       ""
-#define RTT_CTRL_BG_BRIGHT_MAGENTA    ""
-#define RTT_CTRL_BG_BRIGHT_CYAN       ""
-#define RTT_CTRL_BG_BRIGHT_WHITE      ""
-
-
-#endif
-
-/*************************** End of file ****************************/

+ 0 - 269
src/SEGGER_RTT_Conf.h

@@ -1,269 +0,0 @@
-/*********************************************************************
-*                SEGGER Microcontroller GmbH & Co. KG                *
-*                        The Embedded Experts                        *
-**********************************************************************
-*                                                                    *
-*       (c) 2014 - 2016  SEGGER Microcontroller GmbH & Co. KG        *
-*                                                                    *
-*       www.segger.com     Support: support@segger.com               *
-*                                                                    *
-**********************************************************************
-*                                                                    *
-*       SEGGER RTT * Real Time Transfer for embedded targets         *
-*                                                                    *
-**********************************************************************
-*                                                                    *
-* All rights reserved.                                               *
-*                                                                    *
-* SEGGER strongly recommends to not make any changes                 *
-* to or modify the source code of this software in order to stay     *
-* compatible with the RTT protocol and J-Link.                       *
-*                                                                    *
-* Redistribution and use in source and binary forms, with or         *
-* without modification, are permitted provided that the following    *
-* conditions are met:                                                *
-*                                                                    *
-* o Redistributions of source code must retain the above copyright   *
-*   notice, this list of conditions and the following disclaimer.    *
-*                                                                    *
-* o Redistributions in binary form must reproduce the above          *
-*   copyright notice, this list of conditions and the following      *
-*   disclaimer in the documentation and/or other materials provided  *
-*   with the distribution.                                           *
-*                                                                    *
-* o Neither the name of SEGGER Microcontroller GmbH & Co. KG         *
-*   nor the names of its contributors may be used to endorse or      *
-*   promote products derived from this software without specific     *
-*   prior written permission.                                        *
-*                                                                    *
-* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND             *
-* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,        *
-* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF           *
-* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE           *
-* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
-* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR           *
-* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT  *
-* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;    *
-* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF      *
-* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT          *
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE  *
-* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH   *
-* DAMAGE.                                                            *
-*                                                                    *
-**********************************************************************
-*                                                                    *
-*       RTT version: 6.10i                                           *
-*                                                                    *
-**********************************************************************
----------------------------END-OF-HEADER------------------------------
-File    : SEGGER_RTT_Conf.h
-Purpose : Implementation of SEGGER real-time transfer (RTT) which
-          allows real-time communication on targets which support
-          debugger memory accesses while the CPU is running.
-Revision: $Rev: 4351 $
-----------------------------------------------------------------------
-*/
-
-#ifndef SEGGER_RTT_CONF_H
-#define SEGGER_RTT_CONF_H
-
-#ifdef __IAR_SYSTEMS_ICC__
-  #include <intrinsics.h>
-#endif
-
-/*********************************************************************
-*
-*       Defines, configurable
-*
-**********************************************************************
-*/
-
-#define SEGGER_RTT_MAX_NUM_UP_BUFFERS             (3)     // Max. number of up-buffers (T->H) available on this target    (Default: 3)
-#define SEGGER_RTT_MAX_NUM_DOWN_BUFFERS           (3)     // Max. number of down-buffers (H->T) available on this target  (Default: 3)
-
-#define BUFFER_SIZE_UP                            (1200)  // Size of the buffer for terminal output of target, up to host (Default: 1k)
-#define BUFFER_SIZE_DOWN                          (16)    // Size of the buffer for terminal input to target from host (Usually keyboard input) (Default: 16)
-
-#define SEGGER_RTT_PRINTF_BUFFER_SIZE             (64u)    // Size of buffer for RTT printf to bulk-send chars via RTT     (Default: 64)
-
-#define SEGGER_RTT_MODE_DEFAULT                   SEGGER_RTT_MODE_NO_BLOCK_SKIP // Mode for pre-initialized terminal channel (buffer 0)
-
-//
-// Target is not allowed to perform other RTT operations while string still has not been stored completely.
-// Otherwise we would probably end up with a mixed string in the buffer.
-// If using  RTT from within interrupts, multiple tasks or multi processors, define the SEGGER_RTT_LOCK() and SEGGER_RTT_UNLOCK() function here.
-//
-// SEGGER_RTT_MAX_INTERRUPT_PRIORITY can be used in the sample lock routines on Cortex-M3/4.
-// Make sure to mask all interrupts which can send RTT data, i.e. generate SystemView events, or cause task switches.
-// When high-priority interrupts must not be masked while sending RTT data, SEGGER_RTT_MAX_INTERRUPT_PRIORITY needs to be adjusted accordingly.
-// (Higher priority = lower priority number)
-// Default value for embOS: 128u
-// Default configuration in FreeRTOS: configMAX_SYSCALL_INTERRUPT_PRIORITY: ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
-// In case of doubt mask all interrupts: 1 << (8 - BASEPRI_PRIO_BITS) i.e. 1 << 5 when 3 bits are implemented in NVIC
-// or define SEGGER_RTT_LOCK() to completely disable interrupts.
-//
-
-#define SEGGER_RTT_MAX_INTERRUPT_PRIORITY         (0x20)   // Interrupt priority to lock on SEGGER_RTT_LOCK on Cortex-M3/4 (Default: 0x20)
-
-/*********************************************************************
-*
-*       RTT lock configuration for SEGGER Embedded Studio,
-*       Rowley CrossStudio and GCC
-*/
-#if (defined __SES_ARM) || (defined __CROSSWORKS_ARM) || (defined __GNUC__)
-  #ifdef __ARM_ARCH_6M__
-    #define SEGGER_RTT_LOCK()   {                                                                   \
-                                    unsigned int LockState;                                         \
-                                  __asm volatile ("mrs   %0, primask  \n\t"                         \
-                                                  "mov   r1, $1     \n\t"                           \
-                                                  "msr   primask, r1  \n\t"                         \
-                                                  : "=r" (LockState)                                \
-                                                  :                                                 \
-                                                  : "r1"                                            \
-                                                  );
-
-    #define SEGGER_RTT_UNLOCK()   __asm volatile ("msr   primask, %0  \n\t"                         \
-                                                  :                                                 \
-                                                  : "r" (LockState)                                 \
-                                                  :                                                 \
-                                                  );                                                \
-                                }
-
-  #elif (defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__))
-    #ifndef   SEGGER_RTT_MAX_INTERRUPT_PRIORITY
-      #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY   (0x20)
-    #endif
-    #define SEGGER_RTT_LOCK()   {                                                                   \
-                                    unsigned int LockState;                                         \
-                                  __asm volatile ("mrs   %0, basepri  \n\t"                         \
-                                                  "mov   r1, %1       \n\t"                         \
-                                                  "msr   basepri, r1  \n\t"                         \
-                                                  : "=r" (LockState)                                \
-                                                  : "i"(SEGGER_RTT_MAX_INTERRUPT_PRIORITY)          \
-                                                  : "r1"                                            \
-                                                  );
-
-    #define SEGGER_RTT_UNLOCK()   __asm volatile ("msr   basepri, %0  \n\t"                         \
-                                                  :                                                 \
-                                                  : "r" (LockState)                                 \
-                                                  :                                                 \
-                                                  );                                                \
-                                }
-
-  #elif defined(__ARM_ARCH_7A__)
-    #define SEGGER_RTT_LOCK() {                                                \
-                                 unsigned int LockState;                       \
-                                 __asm volatile ("mrs r1, CPSR \n\t"           \
-                                                 "mov %0, r1 \n\t"             \
-                                                 "orr r1, r1, #0xC0 \n\t"      \
-                                                 "msr CPSR_c, r1 \n\t"         \
-                                                 : "=r" (LockState)            \
-                                                 :                             \
-                                                 : "r1"                        \
-                                                 );
-
-    #define SEGGER_RTT_UNLOCK() __asm volatile ("mov r0, %0 \n\t"              \
-                                                "mrs r1, CPSR \n\t"            \
-                                                "bic r1, r1, #0xC0 \n\t"       \
-                                                "and r0, r0, #0xC0 \n\t"       \
-                                                "orr r1, r1, r0 \n\t"          \
-                                                "msr CPSR_c, r1 \n\t"          \
-                                                :                              \
-                                                : "r" (LockState)              \
-                                                : "r0", "r1"                   \
-                                                );                             \
-                            }
-#else
-    #define SEGGER_RTT_LOCK()
-    #define SEGGER_RTT_UNLOCK()
-  #endif
-#endif
-
-/*********************************************************************
-*
-*       RTT lock configuration for IAR EWARM
-*/
-#ifdef __ICCARM__
-  #if (defined (__ARM6M__) && (__CORE__ == __ARM6M__))
-    #define SEGGER_RTT_LOCK()   {                                                                   \
-                                  unsigned int LockState;                                           \
-                                  LockState = __get_PRIMASK();                                      \
-                                  __set_PRIMASK(1);
-
-    #define SEGGER_RTT_UNLOCK()   __set_PRIMASK(LockState);                                         \
-                                }
-  #elif ((defined (__ARM7EM__) && (__CORE__ == __ARM7EM__)) || (defined (__ARM7M__) && (__CORE__ == __ARM7M__)))
-    #ifndef   SEGGER_RTT_MAX_INTERRUPT_PRIORITY
-      #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY   (0x20)
-    #endif
-    #define SEGGER_RTT_LOCK()   {                                                                   \
-                                  unsigned int LockState;                                           \
-                                  LockState = __get_BASEPRI();                                      \
-                                  __set_BASEPRI(SEGGER_RTT_MAX_INTERRUPT_PRIORITY);
-
-    #define SEGGER_RTT_UNLOCK()   __set_BASEPRI(LockState);                                         \
-                                }
-  #endif
-#endif
-
-/*********************************************************************
-*
-*       RTT lock configuration for IAR RX
-*/
-#ifdef __ICCRX__
-  #define SEGGER_RTT_LOCK()   {                                                                     \
-                                unsigned long LockState;                                            \
-                                LockState = __get_interrupt_state();                                \
-                                __disable_interrupt();
-
-  #define SEGGER_RTT_UNLOCK()   __set_interrupt_state(LockState);                                   \
-                              }
-#endif
-
-/*********************************************************************
-*
-*       RTT lock configuration for KEIL ARM
-*/
-#ifdef __CC_ARM
-  #if (defined __TARGET_ARCH_6S_M)
-    #define SEGGER_RTT_LOCK()   {                                                                   \
-                                  unsigned int LockState;                                           \
-                                  register unsigned char PRIMASK __asm( "primask");                 \
-                                  LockState = PRIMASK;                                              \
-                                  PRIMASK = 1u;                                                     \
-                                  __schedule_barrier();
-
-    #define SEGGER_RTT_UNLOCK()   PRIMASK = LockState;                                              \
-                                  __schedule_barrier();                                             \
-                                }
-  #elif (defined(__TARGET_ARCH_7_M) || defined(__TARGET_ARCH_7E_M))
-    #ifndef   SEGGER_RTT_MAX_INTERRUPT_PRIORITY
-      #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY   (0x20)
-    #endif
-    #define SEGGER_RTT_LOCK()   {                                                                   \
-                                  unsigned int LockState;                                           \
-                                  register unsigned char BASEPRI __asm( "basepri");                 \
-                                  LockState = BASEPRI;                                              \
-                                  BASEPRI = SEGGER_RTT_MAX_INTERRUPT_PRIORITY;                      \
-                                  __schedule_barrier();
-
-    #define SEGGER_RTT_UNLOCK()   BASEPRI = LockState;                                              \
-                                  __schedule_barrier();                                             \
-                                }
-  #endif
-#endif
-
-/*********************************************************************
-*
-*       RTT lock configuration fallback
-*/
-#ifndef   SEGGER_RTT_LOCK
-  #define SEGGER_RTT_LOCK()                // Lock RTT (nestable)   (i.e. disable interrupts)
-#endif
-
-#ifndef   SEGGER_RTT_UNLOCK
-  #define SEGGER_RTT_UNLOCK()              // Unlock RTT (nestable) (i.e. enable previous interrupt lock state)
-#endif
-
-#endif
-/*************************** End of file ****************************/

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.