Prechádzať zdrojové kódy

2020.03.11 / Folus Wen

Actions:
1. Add PlugIt360 project.

Files:
1. As follow commit history

Image version: D0.00.XX.XXXX.XX
Image checksum: XXXXXXXX

Hardware PWB P/N : XXXXXXX
Hardware Version : XXXXXXX
FolusWen 5 rokov pred
rodič
commit
09c2e1f96f
49 zmenil súbory, kde vykonal 15625 pridanie a 929 odobranie
  1. 156 0
      EVSE/Projects/PlugIt360/Apps/Config.h
  2. 175 0
      EVSE/Projects/PlugIt360/Apps/Ev_Comm.c
  3. BIN
      EVSE/Projects/PlugIt360/Apps/FactoryConfig
  4. 313 0
      EVSE/Projects/PlugIt360/Apps/FactoryConfig.c
  5. 94 0
      EVSE/Projects/PlugIt360/Apps/Makefile
  6. BIN
      EVSE/Projects/PlugIt360/Apps/Module_EvComm
  7. 1384 0
      EVSE/Projects/PlugIt360/Apps/Module_EvComm.c
  8. 77 0
      EVSE/Projects/PlugIt360/Apps/Module_EvComm.h
  9. BIN
      EVSE/Projects/PlugIt360/Apps/Module_EventLogging
  10. 313 0
      EVSE/Projects/PlugIt360/Apps/Module_EventLogging.c
  11. BIN
      EVSE/Projects/PlugIt360/Apps/Module_InternalComm
  12. 1498 0
      EVSE/Projects/PlugIt360/Apps/Module_InternalComm.c
  13. 151 0
      EVSE/Projects/PlugIt360/Apps/Module_LcmContro.h
  14. BIN
      EVSE/Projects/PlugIt360/Apps/Module_LcmControl
  15. 904 0
      EVSE/Projects/PlugIt360/Apps/Module_LcmControl.c
  16. BIN
      EVSE/Projects/PlugIt360/Apps/Module_PrimaryComm
  17. 419 0
      EVSE/Projects/PlugIt360/Apps/Module_PrimaryComm.c
  18. BIN
      EVSE/Projects/PlugIt360/Apps/Module_PsuComm
  19. 1244 0
      EVSE/Projects/PlugIt360/Apps/Module_PsuComm.c
  20. 91 0
      EVSE/Projects/PlugIt360/Apps/Module_PsuComm.h
  21. 363 0
      EVSE/Projects/PlugIt360/Apps/PrimaryComm.c
  22. 79 0
      EVSE/Projects/PlugIt360/Apps/PrimaryComm.h
  23. BIN
      EVSE/Projects/PlugIt360/Apps/ReadCmdline
  24. 865 0
      EVSE/Projects/PlugIt360/Apps/ReadCmdline.c
  25. 11 0
      EVSE/Projects/PlugIt360/Apps/init.sh
  26. 835 0
      EVSE/Projects/PlugIt360/Apps/internalComm.c
  27. 194 0
      EVSE/Projects/PlugIt360/Apps/internalComm.h
  28. 12 0
      EVSE/Projects/PlugIt360/Apps/kill.sh
  29. BIN
      EVSE/Projects/PlugIt360/Apps/main
  30. 3743 0
      EVSE/Projects/PlugIt360/Apps/main.c
  31. 5 0
      EVSE/Projects/PlugIt360/Apps/timeout.c
  32. 53 0
      EVSE/Projects/PlugIt360/Apps/timeout.h
  33. BIN
      EVSE/Projects/PlugIt360/Images/MLO
  34. BIN
      EVSE/Projects/PlugIt360/Images/am335x-evm.dtb
  35. BIN
      EVSE/Projects/PlugIt360/Images/ramdisk.gz
  36. BIN
      EVSE/Projects/PlugIt360/Images/u-boot.img
  37. BIN
      EVSE/Projects/PlugIt360/Images/zImage
  38. 8 0
      EVSE/Projects/define.h
  39. 73 0
      Makefile
  40. 295 295
      board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/.tmp_System.map
  41. 289 289
      board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/.tmp_kallsyms1.S
  42. 289 289
      board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/.tmp_kallsyms2.S
  43. BIN
      board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/.tmp_vmlinux1
  44. BIN
      board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/.tmp_vmlinux2
  45. 1 1
      board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/.version
  46. 98 19
      board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/arch/arm/boot/dts/.am335x-evm.dtb.dts.tmp
  47. 711 0
      board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/arch/arm/boot/dts/[PlugIt360]am335x-evm.dts
  48. 80 36
      board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/arch/arm/boot/dts/am335x-evm.dts
  49. 802 0
      board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[PlugIt360]am335x-evm.dts

+ 156 - 0
EVSE/Projects/PlugIt360/Apps/Config.h

@@ -0,0 +1,156 @@
+/*
+ * Config.h
+ *
+ *  Created on: 2019年4月23日
+ *      Author: foluswen
+ */
+#ifndef CONFIG_H_
+#define CONFIG_H_
+
+typedef unsigned char			byte;
+
+#define TOTAL_QUANTITY_GUN			4				//Max Count
+#define DEBUG						0
+
+#define MODE_BOOT					0
+#define MODE_IDLE					1
+#define MODE_AUTHORIZING			2
+#define MODE_REASSIGN_CHECK			3
+#define MODE_REASSIGN				4
+#define MODE_PRECHARGE				5
+#define MODE_PREPARE_FOR_EV			6
+#define MODE_PREPARE_FOR_EVSE		7
+#define MODE_CHARGING				8
+#define MODE_TERMINATING			9
+#define MODE_COMPLETE				10
+#define MODE_ALARM					11
+#define MODE_FAULT					12
+#define MODE_RESERVATION			13
+#define MODE_BOOKING				14
+#define MODE_MAINTAIN				15
+#define MODE_DEBUG					16
+#define MODE_CCS_PRECHARGE_STEP0	17 	// ready for ccs precharge processing, For D+ relay to precharge relay
+#define MODE_CCS_PRECHARGE_STEP1	18	// waitting for ev board inform to enter to charging, For precharge relay to D+ relay
+#define MODE_SINGLE_RUN				19
+
+#define GFD_WAIT			0
+#define GFD_PASS			1
+#define GFD_FAIL			2
+#define GFD_WARNING			3
+
+#define PRECHARGE_WAIT				0
+#define PRECHARGE_READY				1
+#define PRECHARGE_PRERELAY_PASS		2
+#define PRECHARGE_CHARELAY_PASS		3
+
+#define BOOTTING			0
+#define BOOT_COMPLETE		1
+
+enum _SYSTEM_STATUS
+{
+	S_BOOTING = 						0,
+    S_IDLE,
+	S_AUTHORIZING,
+	S_REASSIGN_CHECK,
+	S_REASSIGN,
+	S_PREPARNING,
+	S_PREPARING_FOR_EV,
+	S_PREPARING_FOR_EVSE,
+    S_CHARGING,
+	S_TERMINATING,
+	S_COMPLETE,
+	S_ALARM,
+	S_FAULT,
+	S_RESERVATION,
+	S_BOOKING,
+	S_MAINTAIN,
+	S_DEBUG,
+	S_CCS_PRECHARGE_ST0,
+	S_CCS_PRECHARGE_ST1,
+	S_SINGLE_RUN,
+	S_NONE,
+};
+
+enum _GUN_TYPE
+{
+	_Type_Chademo = 		0,
+	_Type_CCS_2,
+	_Type_GB,
+
+};
+
+enum _LCM_INDEX
+{
+	_LCM_INIT = 			0x00,
+	_LCM_IDLE = 			0x01,
+	_LCM_AUTHORIZING = 		0x04,
+	_LCM_AUTHORIZ_COMP = 	0x05,
+	_LCM_AUTHORIZ_FAIL = 	0x06,
+	_LCM_WAIT_FOR_PLUG = 	0x07,
+	_LCM_PRE_CHARGE = 		0x08,
+	_LCM_CHARGING = 		0x09,
+	_LCM_COMPLETE = 		0x0A,
+	_LCM_FIX = 				0x0B,
+	_LCM_NONE = 			0xFF,
+};
+
+enum _SELF_TEST_SEQ
+{
+	_STEST_VERSION = 0x00,
+	_STEST_AC_CONTACTOR = 0x01,
+	_STEST_PSU_DETECT = 0x02,
+	_STEST_PSU_CAP = 0x03,
+	_STEST_FAIL = 0x04,
+	_STEST_COMPLETE = 0xFE,
+};
+
+enum _MODULE_PSU_WORK_STEP
+{
+	ASSIGN_START 	= 			0,
+	ASSIGN_COMP 	= 			1,
+	ENABLE_POW		=			2,
+	_TEST_LINE_STEP 	= 		3,
+	_TEST_POWER_STEP 	= 		4,
+	_TEST_COMPLETE 		= 		5,
+
+	_WORK_CHARGING 	= 			10,
+
+	_NO_WORKING			= 		254,
+	_INIT_PSU_STATUS	= 		255
+};
+
+enum _OFFLINE_POLICY
+{
+	_OFFLINE_POLICY_LOCAL_LIST = 0x00,
+	_OFFLINE_POLICY_PHIHONG_RFID_TAG = 0x01,
+	_OFFLINE_POLICY_FREE_CHARGING = 0x02,
+	_OFFLINE_POLICY_NO_CHARGING = 0x03,
+};
+
+enum _SYS_AUTHORIZE_MODE
+{
+	_SYS_AUTHORIZE_OCPP = 0x00,
+	_SYS_AUTHORIZE_FREE = 0x01
+};
+
+enum _REASSIGNED_RESOURCE_STEP
+{
+	_REASSIGNED_NONE = 			0,	//
+	_REASSIGNED_PREPARE = 		1,	// 系統收到需要降載需求 (輸出總電流降低),PSU Task 收到將狀態切換至下個狀態
+	_REASSIGNED_GET_NEW_CAP = 	2,	// 充電中的重新取得屬於自己火線上的總能量並透過小板通知車端 - 超過10秒直接跳下一步
+	_REASSIGNED_MAIN = 			3,  // 重新分配 PSU
+	_REASSIGNED_ADJUST = 		4,	// 模塊重新分配完成
+	_REASSIGNED_RELAY = 		5,	// 切斷橋接的 Relay
+	_REASSIGNED_COMP = 			6,	// 完成
+	_REASSIGNED_M_RELAY = 		7,	// 搭接橋接的 Relay
+	_REASSIGNED_M_MAIN = 		8,	// 重新分配 PSU (最大充)
+	_REASSIGNED_M_GET_NEW_CAP = 9	// 取得新的 CAP 並通知車端
+};
+
+enum _MAIN_CHARGING_MODE
+{
+	_MAIN_CHARGING_MODE_MAX = 0,
+	_MAIN_CHARGING_MODE_AVER = 1,
+};
+
+#endif /* CONFIG_H_ */

+ 175 - 0
EVSE/Projects/PlugIt360/Apps/Ev_Comm.c

@@ -0,0 +1,175 @@
+#include "Module_EvComm.h"
+#include 	<linux/can.h>
+#include 	<linux/can/raw.h>
+#include 	<string.h>
+#include    <stdio.h>      /*標準輸入輸出定義*/
+#include    <stdlib.h>     /*標準函數庫定義*/
+#include    <unistd.h>     /*Unix 標準函數定義*/
+#include    <fcntl.h>      /*檔控制定義*/
+#include    <termios.h>    /*PPSIX 終端控制定義*/
+#include    <errno.h>      /*錯誤號定義*/
+
+//================================================
+//================================================
+// CANBUS send cmd
+//================================================
+//================================================
+
+int PackageIdCmd(int cmd)
+{
+	return cmd | 0x80000000;
+}
+
+void SendCmdToEvboard(int cmd, byte *data, byte dataLen)
+{
+    struct can_frame frame;
+
+    frame.can_id = cmd;
+    frame.can_dlc = dataLen;
+    memcpy(frame.data, data, sizeof(frame.data));
+
+    write(CanFd, &frame, sizeof(struct can_frame));
+}
+
+void SetTargetAddr(byte *target_number, byte index)
+{
+	int id = PackageIdCmd(Ev_Cmd.address_assignment + index);
+	//printf("intCmd = %x \n", cmd & CAN_EFF_MASK);
+	//cmd = cmd & CAN_EFF_MASK;
+
+	byte data[8];
+
+	data[0] = *target_number;
+	data[1] = *(target_number + 1);
+	data[2] = *(target_number + 2);
+	data[3] = *(target_number + 3);
+	data[4] = index;
+
+	SendCmdToEvboard(id, data, 5);
+}
+
+void GetFirmwareVersion(byte gun_index, byte toId)
+{
+	int id = PackageIdCmd(Ev_Cmd.get_firmware_ver + toId);
+	byte data[8];
+
+	SendCmdToEvboard(id, data, 0);
+}
+
+void GetHardwareVersion(byte gun_index, byte toId)
+{
+	int id = PackageIdCmd(Ev_Cmd.get_hardware_ver + toId);
+	byte data[8];
+
+	SendCmdToEvboard(id, data, 0);
+}
+
+void SetChargingPermission(byte gun_index, byte permissionStatus, short aOutputPw, short aOutputCur, short aOutputVol, byte toId)
+{
+	int id = PackageIdCmd(Ev_Cmd.charging_permission + toId);
+	byte data[8];
+
+	data[0] = permissionStatus;
+	data[1] = aOutputPw & 0xff;
+	data[2] = (aOutputPw >> 8) & 0xff;
+	data[3] = aOutputCur & 0xff;
+	data[4] = (aOutputCur >> 8) & 0xff;
+	data[5] = aOutputVol & 0xff;
+	data[6] = (aOutputVol >> 8) & 0xff;
+	data[7] = 0xff;
+
+	SendCmdToEvboard(id, data, sizeof(data));
+}
+
+void SetPresentOutputPower(short outputVol_b1, short outputCur_b1, short outputVol_b2, short outputCur_b2)
+{
+	int id = PackageIdCmd(Ev_Cmd.present_output_power);
+	byte data[8];
+
+	data[0] = outputVol_b1 & 0xff;
+	data[1] = (outputVol_b1 >> 8) & 0xff;
+	data[2] = outputCur_b1 & 0xff;
+	data[3] = (outputCur_b1 >> 8) & 0xff;
+	data[4] = outputVol_b2 & 0xff;
+	data[5] = (outputVol_b2 >> 8) & 0xff;
+	data[6] = outputCur_b2 & 0xff;
+	data[7] = (outputCur_b2 >> 8) & 0xff;
+
+	SendCmdToEvboard(id, data, 8);
+}
+
+void SetPresentOutputCapacity(short aOutputPw_b1, short aOutputCur_b1, short aOutputPw_b2, short aOutputCur_b2)
+{
+	int id = PackageIdCmd(Ev_Cmd.present_output_cap);
+	byte data[8];
+
+	data[0] = aOutputPw_b1 & 0xff;
+	data[1] = (aOutputPw_b1 >> 8) & 0xff;
+	data[2] = aOutputCur_b1 & 0xff;
+	data[3] = (aOutputCur_b1 >> 8) & 0xff;
+	data[4] = aOutputPw_b2 & 0xff;
+	data[5] = (aOutputPw_b2 >> 8) & 0xff;
+	data[6] = aOutputCur_b2 & 0xff;
+	data[7] = (aOutputCur_b2 >> 8) & 0xff;
+
+	SendCmdToEvboard(id, data, 8);
+}
+
+void GetOutputReq(byte gun_index, byte toId)
+{
+	int id = PackageIdCmd(Ev_Cmd.get_output_req + toId);
+	byte data[8];
+
+	SendCmdToEvboard(id, data, 0);
+}
+
+void GetEvBatteryInfo(byte gun_index, byte toId)
+{
+	int id = PackageIdCmd(Ev_Cmd.get_battery_info + toId);
+	byte data[8];
+
+	SendCmdToEvboard(id, data, 0);
+}
+
+void EvseStopChargingEvent(byte stopResult, byte *stopReason, byte toId)
+{
+	int id = PackageIdCmd(Ev_Cmd.evse_stop_charging + toId);
+	byte data[8];
+
+	data[0] = stopResult;
+	data[1] = *stopReason;
+	data[2] = *(stopReason + 1);
+	data[3] = *(stopReason + 2);
+	data[4] = *(stopReason + 3);
+	data[5] = *(stopReason + 4);
+	data[6] = *(stopReason + 5);
+
+	SendCmdToEvboard(id, data, 7);
+}
+
+void GetMiscellaneousInfo(byte gun_index, byte toId)
+{
+	int id = PackageIdCmd(Ev_Cmd.get_miscellaneous_info + toId);
+	byte data[8];
+
+	SendCmdToEvboard(id, data, 0);
+}
+
+void SetIsolationStatus(byte gun_index, byte result, byte toId)
+{
+	int id = PackageIdCmd(Ev_Cmd.isolation_status + toId);
+	byte data[8];
+
+	data[0] = result;
+	SendCmdToEvboard(id, data, 1);
+}
+
+void SetEvsePrechargeInfo(byte gun_index, byte result, byte toId)
+{
+	int id = PackageIdCmd(Ev_Cmd.evse_precharge_info + toId);
+	byte data[8];
+
+	data[0] = result;
+	SendCmdToEvboard(id, data, 1);
+}
+

BIN
EVSE/Projects/PlugIt360/Apps/FactoryConfig


+ 313 - 0
EVSE/Projects/PlugIt360/Apps/FactoryConfig.c

@@ -0,0 +1,313 @@
+#include 	<sys/time.h>
+#include 	<sys/timeb.h>
+#include    <sys/types.h>
+#include    <sys/stat.h>
+#include 	<sys/types.h>
+#include 	<sys/ioctl.h>
+#include 	<sys/socket.h>
+#include 	<sys/ipc.h>
+#include 	<sys/shm.h>
+#include 	<sys/shm.h>
+#include 	<sys/mman.h>
+#include 	<linux/can.h>
+#include 	<linux/can/raw.h>
+#include 	<linux/wireless.h>
+#include 	<arpa/inet.h>
+#include 	<netinet/in.h>
+
+#include 	<unistd.h>
+#include 	<stdarg.h>
+#include    <stdio.h>      /*標準輸入輸出定義*/
+#include    <stdlib.h>     /*標準函數庫定義*/
+#include    <unistd.h>     /*Unix 標準函數定義*/
+#include    <fcntl.h>      /*檔控制定義*/
+#include    <termios.h>    /*PPSIX 終端控制定義*/
+#include    <errno.h>      /*錯誤號定義*/
+#include 	<errno.h>
+#include 	<string.h>
+#include	<time.h>
+#include	<ctype.h>
+#include 	<ifaddrs.h>
+#include	"../../define.h"
+#include 	"Config.h"
+
+#define Debug
+#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
+#define PASS				1
+#define FAIL				-1
+#define OUTPUT_FLASH		0x01
+#define OUTPUT_FILE			0x02
+
+struct SysConfigData 			SysConfig;
+
+int StoreLogMsg(const char *fmt, ...);
+
+int StoreLogMsg(const char *fmt, ...)
+{
+	char Buf[4096+256];
+	char buffer[4096];
+	time_t CurrentTime;
+	struct tm *tm;
+	va_list args;
+
+	va_start(args, fmt);
+	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
+	va_end(args);
+
+	memset(Buf,0,sizeof(Buf));
+	CurrentTime = time(NULL);
+	tm=localtime(&CurrentTime);
+	sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
+			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
+			buffer,
+			tm->tm_year+1900,tm->tm_mon+1);
+	system(Buf);
+
+	return rc;
+}
+
+void helpOutput(void)
+{
+	printf("Usage: Module_FactoryConfig [OPTION]...\r\n\r\n");
+	printf("Generate factory default configuration value\r\n\r\n");
+	printf("OPTION:\r\n");
+	printf("	-a Write to file(/mnt) & flash\r\n");
+	printf("	-f Write to file(/mnt)\r\n");
+	printf("	-m Write to flash\r\n");
+}
+
+/**************************************************************************************/
+/************This task will create Factory default confgiuration file *****************/
+ /***********and store it into mtdblock 10,11,12                               ****************/
+/**************************************************************************************/
+int main(int argc,char *argv[])
+{
+	unsigned char outType=0;
+	unsigned int i,Chk, MtdBlockSize=0x600000;
+	unsigned char *ptr;
+	int fd,wrd;
+
+	ptr=malloc(MtdBlockSize);
+	if(ptr==NULL)
+	{
+		#ifdef SystemLogMessage
+		StoreLogMsg("[FactoryConfig]main: malloc for SysConfigData NG");
+		#endif
+		return 0;
+	}
+	memset(ptr, 0, MtdBlockSize);
+	memset(&SysConfig, 0, sizeof(struct SysConfigData));
+
+	/*
+	 * TODO: Set factory default configuration
+	*/
+	//********** System **********// udhcpc -i eth1 -s ./dhcp_script/eth1.script
+	//
+	strcpy((char *)SysConfig.ModelName, "DSYE601J0EW2PH");
+	strcpy((char *)SysConfig.SerialNumber, "");
+
+	memset(SysConfig.SystemId, 0x00, sizeof(SysConfig.SystemId));
+	char Dash = '-';
+
+	strcat((char *)SysConfig.SystemId, (char *)SysConfig.ModelName);
+	strncat((char *)SysConfig.SystemId, &Dash, 1);
+	strcat((char *)SysConfig.SystemId, (char *)SysConfig.SerialNumber);
+
+	strcpy((char *)SysConfig.SystemDateTime, "");
+	SysConfig.AuthorisationMode = _SYS_AUTHORIZE_OCPP;
+	SysConfig.DefaultLanguage = 0;
+	SysConfig.RfidCardNumEndian = 0;
+	SysConfig.AcPlugInTimes = 0;
+	SysConfig.GbPlugInTimes = 0;
+	SysConfig.Ccs1PlugInTime = 0;
+	SysConfig.Ccs2PlugInTimes = 0;
+	SysConfig.ChademoPlugInTimes = 0;
+	//********** Charging **********//
+	SysConfig.RatingCurrent = 1200;			// 最大可輸出電流 120 A
+	SysConfig.MaxChargingEnergy = 0;
+	SysConfig.MaxChargingPower = 600; 		// 最大功率 : 跟著 model name 跑
+	SysConfig.MaxChargingCurrent = 1200;		// 最大可輸出電流 120 A
+	SysConfig.MaxChargingDuration = 0;
+	SysConfig.PhaseLossPolicy = 0;
+	for(unsigned char i = 0; i < 10; i++)
+		strcpy((char *)SysConfig.LocalWhiteCard, "");
+
+	strcpy((char *)SysConfig.UserId, "");
+	//********** Network **********//
+	strcpy((char *)SysConfig.FtpServer, "");
+	SysConfig.Eth0Interface.EthDhcpClient = 0;
+	strcpy((char *) SysConfig.Eth0Interface.EthMacAddress, "AA:BB:CC:DD:EE:FF");
+	strcpy((char *) SysConfig.Eth0Interface.EthIpAddress, "192.168.1.10");
+	strcpy((char *) SysConfig.Eth0Interface.EthSubmaskAddress, "255.255.255.0");
+	strcpy((char *) SysConfig.Eth0Interface.EthGatewayAddress, "192.168.1.254");
+	SysConfig.Eth1Interface.EthDhcpClient = 0;
+	strcpy((char *) SysConfig.Eth1Interface.EthMacAddress, "AA:BB:CC:DD:EE:FF");
+	strcpy((char *) SysConfig.Eth1Interface.EthIpAddress, "192.168.0.10");
+	strcpy((char *) SysConfig.Eth1Interface.EthSubmaskAddress, "255.255.255.0");
+	strcpy((char *) SysConfig.Eth1Interface.EthGatewayAddress, "192.168.0.254");
+	SysConfig.AthInterface.WifiMode = 0;
+	strcpy((char *) SysConfig.AthInterface.WifiSsid, "");
+	strcpy((char *) SysConfig.AthInterface.WifiPassword, "");
+	SysConfig.AthInterface.WifiRssi = 0;
+	SysConfig.AthInterface.WifiDhcpServer = 0;
+	SysConfig.AthInterface.WifiDhcpClient = 0;
+	strcpy((char *) SysConfig.AthInterface.WifiMacAddress, "");
+	strcpy((char *) SysConfig.AthInterface.WifiIpAddress, "");
+	strcpy((char *) SysConfig.AthInterface.WifiSubmaskAddress, "");
+	strcpy((char *) SysConfig.AthInterface.WifiGatewayAddress, "");
+	SysConfig.AthInterface.WifiNetworkConn = 0;
+	strcpy((char *) SysConfig.TelecomInterface.TelcomModelName, "");
+	strcpy((char *) SysConfig.TelecomInterface.TelcomSoftwareVer, "");
+	strcpy((char *) SysConfig.TelecomInterface.TelcomApn, "Internet");
+	SysConfig.TelecomInterface.TelcomRssi = 0;
+	strcpy((char *) SysConfig.TelecomInterface.TelcomChapPapId, " ");
+	strcpy((char *) SysConfig.TelecomInterface.TelcomChapPapPwd, " ");
+	strcpy((char *) SysConfig.TelecomInterface.TelcomModemImei, "");
+	strcpy((char *) SysConfig.TelecomInterface.TelcomSimImsi, "");
+	strcpy((char *) SysConfig.TelecomInterface.TelcomSimIccid, "");
+	SysConfig.TelecomInterface.TelcomSimStatus = 0;
+	SysConfig.TelecomInterface.TelcomModemMode = 0;
+	strcpy((char *) SysConfig.TelecomInterface.TelcomIpAddress, "");
+	SysConfig.TelecomInterface.TelcomNetworkConn = 0;
+	strcpy((char *)SysConfig.chargePointVendor, "Phihong Technology");
+	//********** Backend **********//
+	SysConfig.BackendConnTimeout = 300; //300 seconds
+	SysConfig.OfflinePolicy = 0;
+	SysConfig.OfflineMaxChargeEnergy = 0;
+	SysConfig.OfflineMaxChargeDuration = 0;
+	strcpy((char *) SysConfig.OcppServerURL, "ws://test.evsocket.phihong.com.cn:2012/ocpp/");
+	strcpy((char *) SysConfig.ChargeBoxId, "DemoDC_Alston");
+
+	//copy default configuration to pointer
+	memcpy(ptr,&SysConfig,sizeof(struct SysConfigData));
+
+	//calculate CRC
+	Chk=0;
+	for(i=0;i<(MtdBlockSize-4);i++)
+	{
+		Chk+=*(ptr+i);
+	}
+	memcpy(	ptr+MtdBlockSize-4,&Chk,4);
+
+	/*
+	* Parameter process
+	*/
+	if (argc > 1)
+	{
+		char *arg = argv[1];
+		switch (arg[0])
+		{
+		case '-':
+			switch (arg[1])
+			{
+				case 'a':
+					outType |= OUTPUT_FILE;
+					outType |= OUTPUT_FLASH;
+					break;
+				case 'f':
+					outType |= OUTPUT_FILE;
+					break;
+				case 'm':
+					outType |= OUTPUT_FLASH;
+					break;
+				default:
+					helpOutput();
+					break;
+			}
+				break;
+			default:
+				helpOutput();
+				break;
+		}
+	}
+	else
+	{
+		helpOutput();
+	}
+
+	/*
+	 * Configuration bin file generate
+	*/
+	if((outType&OUTPUT_FILE)>0)
+	{
+		fd = open("/mnt/FactoryDefaultConfig.bin", O_RDWR | O_CREAT);
+		if (fd < 0)
+		{
+			StoreLogMsg("[FactoryConfig]main: open /mnt/FactoryDefaultConfig.bin NG");
+			free(ptr);
+			return 0;
+		}
+		wrd=write(fd, ptr, MtdBlockSize);
+		close(fd);
+		if(wrd<MtdBlockSize)
+		{
+			StoreLogMsg("write /mnt/FactoryDefaultConfig.bin NG\r\n");
+			free(ptr);
+			return 0;
+		}
+		StoreLogMsg("FactoryConfig write to file in /mnt OK.\r\n");
+	}
+
+	/*
+	* Flash memory write
+	*/
+	if((outType&OUTPUT_FLASH)>0)
+	{
+		// Save factory default setting value to flash factory default setting block
+		fd = open("/dev/mtdblock12", O_RDWR);
+		if (fd < 0)
+		{
+			StoreLogMsg("open /dev/mtdblock12 NG\r\n");
+			free(ptr);
+			return 0;
+		}
+		wrd=write(fd, ptr, MtdBlockSize);
+		close(fd);
+		if(wrd<MtdBlockSize)
+		{
+			StoreLogMsg("write /dev/mtdblock12 NG\r\n");
+			free(ptr);
+			return 0;
+		}
+
+		// Save factory default setting value to flash backup setting block
+		fd = open("/dev/mtdblock11", O_RDWR);
+		if (fd < 0)
+		{
+			StoreLogMsg("open /dev/mtdblock11 NG\r\n");
+			free(ptr);
+			return 0;
+		}
+		wrd=write(fd, ptr, MtdBlockSize);
+		close(fd);
+		if(wrd<MtdBlockSize)
+		{
+			StoreLogMsg("write /dev/mtdblock11 NG\r\n");
+			free(ptr);
+			return 0;
+		}
+
+		// Save factory default setting value to flash setting block
+		fd = open("/dev/mtdblock10", O_RDWR);
+		if (fd < 0)
+		{
+			StoreLogMsg("open /dev/mtdblock10 NG\r\n");
+			free(ptr);
+			return 0;
+		}
+		wrd=write(fd, ptr, MtdBlockSize);
+		close(fd);
+		if(wrd<MtdBlockSize)
+		{
+			StoreLogMsg("write /dev/mtdblock10 NG\r\n");
+			free(ptr);
+			return 0;
+		}
+		StoreLogMsg("FactoryConfig write to flash OK\r\n");
+	}
+
+	free(ptr);
+
+	return FAIL;
+}
+

+ 94 - 0
EVSE/Projects/PlugIt360/Apps/Makefile

@@ -0,0 +1,94 @@
+-include ../../../../Rules.make
+export PATH=/bin:/sbin:/usr/bin:$(SDK_PATH_TARGET)/usr/bin:$PATH
+
+#define library variable
+Internal485ProtocolLib = -L ../../../Modularization/Internal485Protocol -lInternal485Protocol
+#PsuCommProtocolLib = -L ../../../Modularization/PsuCommProtocol -lPsuCommProtocol
+
+all: CopyFile apps
+#apps: Module_CSU Module_EvComm Module_EventLogging Module_InternalComm Module_LcmControl Module_PrimaryComm Module_PsuComm 
+# ReadCmdline kill.sh
+apps: MainTask EvCommTask EventLoggingTask InternalCommTask LcmControlTask PrimaryCommTask PsuCommTask ReadCmdlineTask WebService 4GTask FactoryConfigApp OtherTools
+
+MainTask:
+	rm -f *.o
+	rm -f main;
+	$(CC) -D $(Project) -include../../../Modularization/Module_RFID.h -O0 -g3 -Wall -c -fmessage-length=0 -o main.o main.c
+	$(CC) -D $(Project) -include../../../Modularization/Module_RFID.h -O0 -g3 -Wall -c -fmessage-length=0 -o timeout.o timeout.c
+	$(CC) -o main main.o timeout.o ../../../Modularization/libModule_RFID.a ../../../Modularization/libModule_Upgrade.a	
+	cp -f main ../Images/root
+
+EvCommTask:
+	rm -f Module_EvComm;
+	$(CC) -D $(Project) -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o Ev_Comm.o Ev_Comm.c
+	$(CC) -D $(Project) -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o Module_EvComm.o Module_EvComm.c
+	$(CC) -o Module_EvComm Ev_Comm.o Module_EvComm.o
+	cp -f Module_EvComm ../Images/root	
+	
+EventLoggingTask:
+	rm -f Module_EventLogging;
+	$(CC) -D $(Project) -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o Module_EventLogging.o Module_EventLogging.c
+	$(CC) -o Module_EventLogging Module_EventLogging.o 	
+	cp -f Module_EventLogging ../Images/root	
+	
+InternalCommTask:
+	rm -f Module_InternalComm; 
+	$(CC) -D $(Project) -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o internalComm.o internalComm.c
+	$(CC) -D $(Project) -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o Module_InternalComm.o Module_InternalComm.c
+	$(CC) -o Module_InternalComm Module_InternalComm.o internalComm.o 	
+	cp -f Module_InternalComm ../Images/root
+	
+LcmControlTask:
+	rm -f Module_LcmControl; 
+	$(CC) -D $(Project) -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o Module_LcmControl.o Module_LcmControl.c
+	$(CC) -o Module_LcmControl Module_LcmControl.o
+	cp -f Module_LcmControl ../Images/root			
+
+PrimaryCommTask:
+	rm -f Module_PrimaryComm; 
+	$(CC) -D $(Project) -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o Module_PrimaryComm.o Module_PrimaryComm.c
+	$(CC) -D $(Project) -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o PrimaryComm.o PrimaryComm.c
+	$(CC) -o Module_PrimaryComm Module_PrimaryComm.o PrimaryComm.o
+	cp -f Module_PrimaryComm ../Images/root	
+
+PsuCommTask:
+	rm -f Module_PsuComm; 
+	$(CC) -D $(Project) -include../../../Modularization/Infypwr_PsuCommObj.h -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o Module_PsuComm.o Module_PsuComm.c
+	$(CC) -o Module_PsuComm Module_PsuComm.o ../../../Modularization/libInfypwr_PsuCommObj.a
+	cp -f Module_PsuComm ../Images/root	
+	
+ReadCmdlineTask:
+	rm -f ReadCmdline; 
+	$(CC) -D $(Project) -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o ReadCmdline.o ReadCmdline.c
+	$(CC) -o ReadCmdline ReadCmdline.o
+	cp -f ReadCmdline ../Images/root
+
+FactoryConfigApp:
+	@echo "===== Module_FactoryConfig_Task =================================="
+	rm -f FactoryConfig
+	gcc -D $(Project) "-I../../" -o FactoryConfig "./FactoryConfig.c"
+	mkdir -p /Storage/SystemLog	
+	./FactoryConfig -f;true
+	cp /mnt/FactoryDefaultConfig.bin ../Images
+	rm -f FactoryConfig; 
+	$(CC) -D $(Project) -O0 -g3 -Wall -c -fmessage-length=0 -o FactoryConfig.o FactoryConfig.c 
+	$(CC) -o FactoryConfig FactoryConfig.o 
+	cp -f FactoryConfig ../Images/root
+
+WebService:
+	cp -f ../../../Modularization/WebService ../Images/root
+
+4GTask:
+	cp -f ../../../Modularization/Module_4g ../Images/root
+
+OtherTools:
+	cp -f init.sh ../Images/root
+	cp -f kill.sh ../Images/root
+
+CopyFile: 
+	rm -rfv ../Images/root
+	mkdir -p ../Images/root
+
+
+
+	

BIN
EVSE/Projects/PlugIt360/Apps/Module_EvComm


+ 1384 - 0
EVSE/Projects/PlugIt360/Apps/Module_EvComm.c

@@ -0,0 +1,1384 @@
+#include 	<sys/time.h>
+#include 	<sys/timeb.h>
+#include    <sys/types.h>
+#include    <sys/stat.h>
+#include 	<sys/types.h>
+#include 	<sys/ioctl.h>
+#include 	<sys/socket.h>
+#include 	<sys/ipc.h>
+#include 	<sys/shm.h>
+#include 	<sys/shm.h>
+#include 	<sys/mman.h>
+#include 	<linux/can.h>
+#include 	<linux/can/raw.h>
+#include 	<linux/wireless.h>
+#include 	<arpa/inet.h>
+#include 	<netinet/in.h>
+
+#include 	<unistd.h>
+#include 	<stdarg.h>
+#include    <stdio.h>      /*標準輸入輸出定義*/
+#include    <stdlib.h>     /*標準函數庫定義*/
+#include    <unistd.h>     /*Unix 標準函數定義*/
+#include    <fcntl.h>      /*檔控制定義*/
+#include    <termios.h>    /*PPSIX 終端控制定義*/
+#include    <errno.h>      /*錯誤號定義*/
+#include 	<errno.h>
+#include 	<string.h>
+#include	<time.h>
+#include	<ctype.h>
+#include 	<ifaddrs.h>
+#include	"../../define.h"
+#include 	"Module_EvComm.h"
+
+#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
+#define PASS				1
+#define FAIL				-1
+#define START				1
+#define STOP				0
+#define YES					1
+#define NO					0
+
+struct SysConfigAndInfo			*ShmSysConfigAndInfo;
+struct StatusCodeData 			*ShmStatusCodeData;
+struct FanModuleData			*ShmFanModuleData;
+struct CHAdeMOData				*ShmCHAdeMOData;
+struct CcsData					*ShmCcsData;
+
+byte gun_count = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
+int chargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+
+// 限制最大充電電壓,因應不同 type 槍線來限制
+// Chademo : 500V, CCS : 950V
+float maxChargingVol[2] = { 5000, 9500 };			// 限制最大充電電壓,如依照模塊則填上 0
+// 限制最大充電電流與能量透過 Web
+float maxChargingCur[2] = { 0, 0 };					// 限制最大充電電流,如依照模塊則填上 0
+float maxChargingPow = 0;							// 限制最大充電能量,如依照模塊則填上 0
+
+// 槍資訊
+struct ChargingInfoData *_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+
+struct Ev_Board_Cmd Ev_Cmd={
+		0,
+		0x00000200,
+		0x00000400,
+		0x00000500,
+		0x00000600,
+		0x00000700,
+		0x00000800,
+		0x00000900,
+		0x00000A00,
+		0x00000C00,
+		0x00000D00,
+
+		0x00000E00,
+		0x00000F00,
+		0x00001000,
+		0x00001100,
+
+		0x00001200,
+		0x00001500,
+};
+
+unsigned char mask_table[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
+
+void PRINTF_FUNC(char *string, ...);
+
+void GetMaxVolAndCurMethod(byte index, float *vol, float *cur);
+void GetMaxPowerMethod(float *pow);
+unsigned long GetTimeoutValue(struct timeval _sour_time);
+
+#define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+
+unsigned long GetTimeoutValue(struct timeval _sour_time)
+{
+	struct timeval _end_time;
+	gettimeofday(&_end_time, NULL);
+
+	return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
+}
+
+int StoreLogMsg(const char *fmt, ...)
+{
+	char Buf[4096+256];
+	char buffer[4096];
+	time_t CurrentTime;
+	struct tm *tm;
+	va_list args;
+
+	va_start(args, fmt);
+	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
+	va_end(args);
+
+	memset(Buf,0,sizeof(Buf));
+	CurrentTime = time(NULL);
+	tm=localtime(&CurrentTime);
+	sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
+			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
+			buffer,
+			tm->tm_year+1900,tm->tm_mon+1);
+	system(Buf);
+
+	return rc;
+}
+
+int DiffTimeb(struct timeb ST, struct timeb ET)
+{
+	//return milli-second
+	unsigned int StartTime,StopTime;
+
+	StartTime=(unsigned int)ST.time;
+	StopTime=(unsigned int)ET.time;
+	return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
+}
+
+void PRINTF_FUNC(char *string, ...)
+{
+	if (DEBUG)
+	{
+		va_list args;
+		char buffer[4096];
+
+		va_start(args, string);
+		vsnprintf(buffer, sizeof(buffer), string, args);
+		va_end(args);
+		printf("%s \n", buffer);
+	}
+}
+
+//=================================
+// Common routine
+//=================================
+void getTimeString(char *buff)
+{
+	time_t timep;
+	struct tm *p;
+	time(&timep);
+	p=gmtime(&timep);
+
+	sprintf(buff, "[%04d-%02d-%02d %02d:%02d:%02d]", (1900+p->tm_year), (1+p->tm_mon), p->tm_mday, p->tm_hour, p->tm_hour, p->tm_sec);
+}
+
+bool CheckUniqNumber(byte value)
+{
+	for (byte index = 0; index < gun_count; index++)
+	{
+		if (_chargingData[index]->Evboard_id == value)
+		{
+			struct timeval _end_time;
+			gettimeofday(&_end_time, NULL);
+			unsigned long diff = 1000000 *	(_end_time.tv_sec - _id_assign_time.tv_sec) + _end_time.tv_usec - _id_assign_time.tv_usec;
+			if (diff >= 3000000)
+			{
+				gettimeofday(&_id_assign_time, NULL);
+				return true;
+			}
+			else
+			{
+				return false;
+			}
+		}
+	}
+
+	gettimeofday(&_id_assign_time, NULL);
+	return true;
+}
+
+//==========================================
+// Init all share memory
+//==========================================
+int InitShareMemory()
+{
+	int result = PASS;
+	int MeterSMId;
+
+	//initial ShmSysConfigAndInfo
+	if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0)
+    {
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
+		#endif
+		result = FAIL;
+	}
+    else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+    {
+    	#ifdef SystemLogMessage
+    	DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
+		#endif
+    	result = FAIL;
+   	 }
+    else
+    {}
+
+   	 //initial ShmStatusCodeData
+   	 if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0)
+    {
+		#ifdef SystemLogMessage
+   		DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
+		#endif
+   		result = FAIL;
+	}
+    else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+    {
+    	#ifdef SystemLogMessage
+    	DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
+		#endif
+    	result = FAIL;
+   	}
+    else
+    {}
+
+   	if(CHAdeMO_QUANTITY > 0)
+   	{
+   		if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData),	IPC_CREAT | 0777)) < 0)
+   		{
+   			#ifdef SystemLogMessage
+   		   	DEBUG_ERROR("[shmget ShmCHAdeMOData NG \n");
+   			#endif
+   			return FAIL;
+   		}
+   		else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+   		{
+   			#ifdef SystemLogMessage
+   		   	DEBUG_ERROR("shmat ShmCHAdeMOData NG \n");
+   			#endif
+   			return FAIL;
+   		}
+   		else
+   		{}
+   	}
+
+   	if(CCS_QUANTITY > 0)
+   	{
+   		if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData),	IPC_CREAT | 0777)) < 0)
+   		{
+   			#ifdef SystemLogMessage
+   			DEBUG_ERROR("shmget ShmCcsData NG \n");
+   			#endif
+   			return FAIL;
+   		}
+   		else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1) {
+   			#ifdef SystemLogMessage
+   		   	DEBUG_ERROR("shmat ShmCcsData NG \n");
+   			#endif
+   			return FAIL;
+   		}
+   		else
+   		{}
+   	}
+
+    return result;
+}
+
+//================================================
+// initial can-bus
+//================================================
+int InitCanBus()
+{
+	int 					s0,nbytes;
+	struct timeval			tv;
+	struct ifreq 			ifr0;
+	struct sockaddr_can		addr0;
+
+	system("/sbin/ip link set can0 down");
+	system("/sbin/ip link set can0 type can bitrate 500000 restart-ms 100");
+	system("/sbin/ip link set can0 up");
+
+	s0 = socket(PF_CAN, SOCK_RAW, CAN_RAW);
+
+	tv.tv_sec = 0;
+	tv.tv_usec = 10000;
+   	if (setsockopt(s0, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct	timeval)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("Set SO_RCVTIMEO NG");
+		#endif
+	}
+	nbytes=40960;
+	if (setsockopt(s0, SOL_SOCKET,  SO_RCVBUF, &nbytes, sizeof(int)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("Set SO_RCVBUF NG");
+		#endif
+	}
+	nbytes=40960;
+	if (setsockopt(s0, SOL_SOCKET, SO_SNDBUF, &nbytes, sizeof(int)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("Set SO_SNDBUF NG");
+		#endif
+	}
+
+   	strcpy(ifr0.ifr_name, "can0" );
+	ioctl(s0, SIOCGIFINDEX, &ifr0); /* ifr.ifr_ifindex gets filled with that device's index */
+	addr0.can_family = AF_CAN;
+	addr0.can_ifindex = ifr0.ifr_ifindex;
+	bind(s0, (struct sockaddr *)&addr0, sizeof(addr0));
+	return s0;
+}
+
+//================================================
+//================================================
+// CANBUS receive task
+//================================================
+//================================================
+bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
+{
+	for (byte index = 0; index < CHAdeMO_QUANTITY; index++)
+	{
+		if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)
+		{
+			chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
+			return true;
+		}
+	}
+
+	for (byte index = 0; index < CCS_QUANTITY; index++)
+	{
+		if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)
+		{
+			chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
+			return true;
+		}
+	}
+
+	for (byte index = 0; index < GB_QUANTITY; index++)
+	{
+		if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)
+		{
+			chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
+			return true;
+		}
+	}
+
+	return false;
+}
+
+void AddrAssignment(byte *data)
+{
+	byte target_number[8];
+	byte index = 0x00;
+
+	memcpy(target_number, data, sizeof(target_number));
+	index = *(data + 4);
+
+	if (CheckUniqNumber(index))
+	{
+		PRINTF_FUNC("EV board id = %x \n", index);
+//		PRINTF_FUNC("target_number[0] = %x \n", target_number[0]);
+//		PRINTF_FUNC("target_number[1] = %x \n", target_number[1]);
+//		PRINTF_FUNC("target_number[2] = %x \n", target_number[2]);
+//		PRINTF_FUNC("target_number[3] = %x \n", target_number[3]);
+//		PRINTF_FUNC("target_number[4] = %x \n", target_number[4]);
+
+		PRINTF_FUNC("SetTargetAddr = %d, type = %d \n", index, _chargingData[index - 1]->Type);
+		SetTargetAddr(target_number, index);
+	}
+}
+
+void ClearAbnormalStatus_Chademo(byte gun_index)
+{
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoEvCommFail = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.PilotFault = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryMalfun = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoNoPermission = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryIncompatibility = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOVP = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryUVP = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOTP = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryCurrentDiff = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryVoltageDiff = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoShiftPosition = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOtherFault = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargingSystemError = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoEvNormalStop = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoTempSensorBroken = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoConnectorLockFail = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoD1OnNoReceive = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsKtoJTimeout = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsChargeAllowTimeout = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoWaitGfdTimeout = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsEvRelayTimeout = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsReqCurrentTimeout = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsKtoJOffTimeout = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsEvRelayOffTimeout = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoAdcMoreThan10V = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoAdcMoreThan20V = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsChargeBeforeStop = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetNormalStop = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoIsolationResultFail = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoMissLinkWithMotherBoard = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoOutputVolMoreThanLimit = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoReqCurrentMoreThanLimit = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoReCapBmsEqrCurrentExceed = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargeRemainCountDown = 0x00;
+}
+
+void ClearAbnormalStatus_CCS(byte gun_index)
+{
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsRESTemperatureInhibit = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVShiftPosition = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargerConnectorLockFault = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVRESSMalfunction = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingCurrentdifferential = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingVoltageOutOfRange = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingSystemIncompatibility = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEmergencyEvent = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsBreaker = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoData = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_DIN_A = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_DIN_B = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_DIN_C = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_ISO_1 = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_ISO_2 = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_ISO_3 = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_1 = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_2 = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_3 = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_4 = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_5 = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSequenceError = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSignatureError = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsUnknownSession = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServiceIDInvalid = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPaymentSelectionInvalid = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsIdentificationSelectionInvalid = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServiceSelectionInvalid = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateExpired = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateNotYetValid = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateRevoked = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoCertificateAvailable = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertChainError = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertValidationError = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertVerificationError = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContractCanceled = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChallengeInvalid = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsWrongEnergyTransferMode = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsWrongChargeParameter = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingProfileInvalid = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTariffSelectionInvalid = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVSEPresentVoltageToLow = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPowerDeliveryNotApplied = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMeteringSignatureNotValid = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoChargeServiceSelected = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContactorError = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateNotAllowedAtThisEVSE = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsGAChargeStop = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsAlignmentError = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsACDError = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsAssociationError = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVSEChargeAbort = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoSupportedAppProtocol = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContractNotAccepted = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMOUnknown = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_Prov_CertificateRevoke = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_SubCA1_CertificateRevoked = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_SubCA2_CertificateRevoked = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_RootCA_CertificateRevoked = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_Prov_CertificateRevoked = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_SubCA1_CertificateRevoked = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_SubCA2_CertificateRevoked = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_RootCA_CertificateRevoked = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_Prov_CertificateRevoked = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_SubCA1_CertificateRevoked = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_SubCA2_CertificateRevoked = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_RootCA_CertificateRevoked = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_SLAC_init = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_match_response = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_match_sequence = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_match_MNBC = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_avg_atten_calc = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_match_response = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_match_session = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_assoc_session = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_vald_toggle = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsUDP_TT_match_join = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTCP_TT_match_join = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_amp_map_exchange = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_link_ready_notification = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSupportedAppProtocolRes = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSessionSetupRes = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServiceDiscoveryRes = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServicePaymentSelectionRes = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContractAuthenticationRes = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargeParameterDiscoveryRes = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPowerDeliveryRes = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCableCheckRes = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPreChargeRes = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCurrentDemandRes = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsWeldingDetectionRes = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSessionStopRes = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSequence_Time = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsReadyToCharge_Performance_Time = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCommunicationSetup_Performance_Time = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCableCheck_Performance_Time = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPState_Detection_Time = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPOscillator_Retain_Time = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_EV_TARGET_INFO = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_EV_TARGET_INFO = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_EV_BATTERY_INFO = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_EV_BATTERY_INFO = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EV_STOP_EVENT = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EV_STOP_EVENT = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_STOP_EVENT = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_STOP_EVENT = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_MISC_INFO = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_MISC_INFO = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DOWNLOAD_REQUEST = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DOWNLOAD_REQUEST = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_START_BLOCK_TRANSFER = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_START_BLOCK_TRANSFER = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DATA_TRANSFER = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DATA_TRANSFER = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DOWNLOAD_FINISH = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DOWNLOAD_FINISH = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_ISOLATION_STATUS = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_ISOLATION_STATUS = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_CONNECTOR_INFO = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_CONNECTOR_INFO = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_RTC_INFO = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_RTC_INFO = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_PRECHARGE_INFO = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_PRECHARGE_INFO = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMSG_Sequence = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCAN_MSG_Unrecognized_CMD_ID = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsDIN_Msg_Decode_Error = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsDIN_Msg_Encode_Error = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO1_Msg_Decode_Error = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO1_Msg_Encode_Error = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO2_Msg_Decode_Error = 0x00;
+	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO2_Msg_Encode_Error = 0x00;
+
+}
+
+void AbnormalStopAnalysis(byte gun_index, byte *errCode)
+{
+	char string[7];
+	sprintf(string, "%d%d%d%d%d%d", *(errCode + 5), *(errCode + 4), *(errCode + 3), *(errCode + 2), *(errCode + 1), *(errCode + 0));
+
+	PRINTF_FUNC("NOTIFICATION_EV_STOP : Err Code = %s \n", string);
+
+	if (strcmp(string, "023700") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoEvCommFail = 0x01;
+	if (strcmp(string, "023701") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEvCommFail = 0x01;
+	if (strcmp(string, "023702") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.GbEvCommFail = 0x01;
+	if (strcmp(string, "023703") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.PilotFault = 0x01;
+	if (strcmp(string, "023704") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryMalfun = 0x01;
+	if (strcmp(string, "023705") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoNoPermission = 0x01;
+	if (strcmp(string, "023706") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryIncompatibility = 0x01;
+	if (strcmp(string, "023707") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOVP = 0x01;
+	if (strcmp(string, "023708") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryUVP = 0x01;
+	if (strcmp(string, "023709") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOTP = 0x01;
+	if (strcmp(string, "023710") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryCurrentDiff = 0x01;
+	if (strcmp(string, "023711") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryVoltageDiff = 0x01;
+	if (strcmp(string, "023712") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoShiftPosition = 0x01;
+	if (strcmp(string, "023713") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOtherFault = 0x01;
+	if (strcmp(string, "023714") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargingSystemError = 0x01;
+	if (strcmp(string, "023715") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoEvNormalStop = 0x01;
+	if (strcmp(string, "023716") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoTempSensorBroken = 0x01;
+	if (strcmp(string, "023717") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoConnectorLockFail = 0x01;
+	if (strcmp(string, "023718") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoD1OnNoReceive = 0x01;
+	if (strcmp(string, "023719") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsKtoJTimeout = 0x01;
+	if (strcmp(string, "023720") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsChargeAllowTimeout = 0x01;
+	if (strcmp(string, "023721") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoWaitGfdTimeout = 0x01;
+	if (strcmp(string, "023722") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsEvRelayTimeout = 0x01;
+	if (strcmp(string, "023723") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsReqCurrentTimeout = 0x01;
+	if (strcmp(string, "023724") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsKtoJOffTimeout = 0x01;
+	if (strcmp(string, "023725") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsEvRelayOffTimeout = 0x01;
+	if (strcmp(string, "023726") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoAdcMoreThan10V = 0x01;
+	if (strcmp(string, "023727") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoAdcMoreThan20V = 0x01;
+	if (strcmp(string, "023728") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsChargeBeforeStop = 0x01;
+	if (strcmp(string, "023729") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetNormalStop = 0x01;
+	if (strcmp(string, "023730") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop = 0x01;
+	if (strcmp(string, "023731") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoIsolationResultFail = 0x01;
+	if (strcmp(string, "023732") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoMissLinkWithMotherBoard = 0x01;
+	if (strcmp(string, "023733") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoOutputVolMoreThanLimit = 0x01;
+	if (strcmp(string, "023734") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoReqCurrentMoreThanLimit = 0x01;
+	if (strcmp(string, "023735") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoReCapBmsEqrCurrentExceed = 0x01;
+	if (strcmp(string, "023736") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargeRemainCountDown = 0x01;
+
+	if (strcmp(string, "23737") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsRESTemperatureInhibit = 0x01;
+	if (strcmp(string, "23738") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVShiftPosition = 0x01;
+	if (strcmp(string, "23739") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargerConnectorLockFault = 0x01;
+	if (strcmp(string, "23740") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVRESSMalfunction = 0x01;
+	if (strcmp(string, "23741") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingCurrentdifferential = 0x01;
+	if (strcmp(string, "23742") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingVoltageOutOfRange = 0x01;
+	if (strcmp(string, "23743") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingSystemIncompatibility = 0x01;
+	if (strcmp(string, "23744") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEmergencyEvent = 0x01;
+	if (strcmp(string, "23745") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsBreaker = 0x01;
+	if (strcmp(string, "23746") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoData = 0x01;
+	if (strcmp(string, "23747") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_DIN_A = 0x01;
+	if (strcmp(string, "23748") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_DIN_B = 0x01;
+	if (strcmp(string, "23749") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_DIN_C = 0x01;
+	if (strcmp(string, "23750") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_ISO_1 = 0x01;
+	if (strcmp(string, "23751") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_ISO_2 = 0x01;
+	if (strcmp(string, "23752") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_ISO_3 = 0x01;
+	if (strcmp(string, "23753") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_1 = 0x01;
+	if (strcmp(string, "23754") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_2 = 0x01;
+	if (strcmp(string, "23755") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_3 = 0x01;
+	if (strcmp(string, "23756") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_4 = 0x01;
+	if (strcmp(string, "23757") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_5 = 0x01;
+	if (strcmp(string, "23758") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSequenceError = 0x01;
+	if (strcmp(string, "23759") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSignatureError = 0x01;
+	if (strcmp(string, "23760") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsUnknownSession = 0x01;
+	if (strcmp(string, "23761") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServiceIDInvalid = 0x01;
+	if (strcmp(string, "23762") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPaymentSelectionInvalid = 0x01;
+	if (strcmp(string, "23763") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsIdentificationSelectionInvalid = 0x01;
+	if (strcmp(string, "23764") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServiceSelectionInvalid = 0x01;
+	if (strcmp(string, "23765") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateExpired = 0x01;
+	if (strcmp(string, "23766") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateNotYetValid = 0x01;
+	if (strcmp(string, "23767") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateRevoked = 0x01;
+	if (strcmp(string, "23768") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoCertificateAvailable = 0x01;
+	if (strcmp(string, "23769") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertChainError = 0x01;
+	if (strcmp(string, "23770") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertValidationError = 0x01;
+	if (strcmp(string, "23771") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertVerificationError = 0x01;
+	if (strcmp(string, "23772") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContractCanceled = 0x01;
+	if (strcmp(string, "23773") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChallengeInvalid = 0x01;
+	if (strcmp(string, "23774") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsWrongEnergyTransferMode = 0x01;
+	if (strcmp(string, "23775") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsWrongChargeParameter = 0x01;
+	if (strcmp(string, "23776") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingProfileInvalid = 0x01;
+	if (strcmp(string, "23777") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTariffSelectionInvalid = 0x01;
+	if (strcmp(string, "23778") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVSEPresentVoltageToLow = 0x01;
+	if (strcmp(string, "23779") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPowerDeliveryNotApplied = 0x01;
+	if (strcmp(string, "23780") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMeteringSignatureNotValid = 0x01;
+	if (strcmp(string, "23781") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoChargeServiceSelected = 0x01;
+	if (strcmp(string, "23782") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContactorError = 0x01;
+	if (strcmp(string, "23783") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateNotAllowedAtThisEVSE = 0x01;
+	if (strcmp(string, "23784") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsGAChargeStop = 0x01;
+	if (strcmp(string, "23785") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsAlignmentError = 0x01;
+	if (strcmp(string, "23786") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsACDError = 0x01;
+	if (strcmp(string, "23787") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsAssociationError = 0x01;
+	if (strcmp(string, "23788") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVSEChargeAbort = 0x01;
+	if (strcmp(string, "23789") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoSupportedAppProtocol = 0x01;
+	if (strcmp(string, "23790") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContractNotAccepted = 0x01;
+	if (strcmp(string, "23791") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMOUnknown = 0x01;
+	if (strcmp(string, "23792") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_Prov_CertificateRevoke = 0x01;
+	if (strcmp(string, "23793") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_SubCA1_CertificateRevoked = 0x01;
+	if (strcmp(string, "23794") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_SubCA2_CertificateRevoked = 0x01;
+	if (strcmp(string, "23795") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_RootCA_CertificateRevoked = 0x01;
+	if (strcmp(string, "23796") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_Prov_CertificateRevoked = 0x01;
+	if (strcmp(string, "23797") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_SubCA1_CertificateRevoked = 0x01;
+	if (strcmp(string, "23798") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_SubCA2_CertificateRevoked = 0x01;
+	if (strcmp(string, "23799") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_RootCA_CertificateRevoked = 0x01;
+	if (strcmp(string, "23800") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_Prov_CertificateRevoked = 0x01;
+	if (strcmp(string, "23801") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_SubCA1_CertificateRevoked = 0x01;
+	if (strcmp(string, "23802") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_SubCA2_CertificateRevoked = 0x01;
+	if (strcmp(string, "23803") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_RootCA_CertificateRevoked = 0x01;
+	if (strcmp(string, "23809") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_SLAC_init = 0x01;
+	if (strcmp(string, "23810") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_match_response = 0x01;
+	if (strcmp(string, "23811") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_match_sequence = 0x01;
+	if (strcmp(string, "23812") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_match_MNBC = 0x01;
+	if (strcmp(string, "23813") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_avg_atten_calc = 0x01;
+	if (strcmp(string, "23814") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_match_response = 0x01;
+	if (strcmp(string, "23815") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_match_session = 0x01;
+	if (strcmp(string, "23816") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_assoc_session = 0x01;
+	if (strcmp(string, "23817") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_vald_toggle = 0x01;
+	if (strcmp(string, "23823") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsUDP_TT_match_join = 0x01;
+	if (strcmp(string, "23824") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTCP_TT_match_join = 0x01;
+	if (strcmp(string, "23825") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_amp_map_exchange = 0x01;
+	if (strcmp(string, "23826") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_link_ready_notification = 0x01;
+	if (strcmp(string, "23832") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSupportedAppProtocolRes = 0x01;
+	if (strcmp(string, "23833") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSessionSetupRes = 0x01;
+	if (strcmp(string, "23834") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServiceDiscoveryRes = 0x01;
+	if (strcmp(string, "23835") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServicePaymentSelectionRes = 0x01;
+	if (strcmp(string, "23836") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContractAuthenticationRes = 0x01;
+	if (strcmp(string, "23837") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargeParameterDiscoveryRes = 0x01;
+	if (strcmp(string, "23838") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPowerDeliveryRes = 0x01;
+	if (strcmp(string, "23839") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCableCheckRes = 0x01;
+	if (strcmp(string, "23840") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPreChargeRes = 0x01;
+	if (strcmp(string, "23841") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCurrentDemandRes = 0x01;
+	if (strcmp(string, "23842") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsWeldingDetectionRes = 0x01;
+	if (strcmp(string, "23843") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSessionStopRes = 0x01;
+	if (strcmp(string, "23844") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSequence_Time = 0x01;
+	if (strcmp(string, "23845") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsReadyToCharge_Performance_Time = 0x01;
+	if (strcmp(string, "23846") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCommunicationSetup_Performance_Time = 0x01;
+	if (strcmp(string, "23847") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCableCheck_Performance_Time = 0x01;
+	if (strcmp(string, "23848") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPState_Detection_Time = 0x01;
+	if (strcmp(string, "23849") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPOscillator_Retain_Time = 0x01;
+	if (strcmp(string, "23855") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_EV_TARGET_INFO = 0x01;
+	if (strcmp(string, "23856") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_EV_TARGET_INFO = 0x01;
+	if (strcmp(string, "23857") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_EV_BATTERY_INFO = 0x01;
+	if (strcmp(string, "23858") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_EV_BATTERY_INFO = 0x01;
+	if (strcmp(string, "23859") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EV_STOP_EVENT = 0x01;
+	if (strcmp(string, "23860") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EV_STOP_EVENT = 0x01;
+	if (strcmp(string, "23861") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_STOP_EVENT = 0x01;
+	if (strcmp(string, "23862") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_STOP_EVENT = 0x01;
+	if (strcmp(string, "23863") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_MISC_INFO = 0x01;
+	if (strcmp(string, "23864") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_MISC_INFO = 0x01;
+	if (strcmp(string, "23865") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DOWNLOAD_REQUEST = 0x01;
+	if (strcmp(string, "23866") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DOWNLOAD_REQUEST = 0x01;
+	if (strcmp(string, "23867") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_START_BLOCK_TRANSFER = 0x01;
+	if (strcmp(string, "23868") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_START_BLOCK_TRANSFER = 0x01;
+	if (strcmp(string, "23869") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DATA_TRANSFER = 0x01;
+	if (strcmp(string, "23870") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DATA_TRANSFER = 0x01;
+	if (strcmp(string, "23871") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DOWNLOAD_FINISH = 0x01;
+	if (strcmp(string, "23872") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DOWNLOAD_FINISH = 0x01;
+	if (strcmp(string, "23873") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_ISOLATION_STATUS = 0x01;
+	if (strcmp(string, "23874") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_ISOLATION_STATUS = 0x01;
+	if (strcmp(string, "23875") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_CONNECTOR_INFO = 0x01;
+	if (strcmp(string, "23876") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_CONNECTOR_INFO = 0x01;
+	if (strcmp(string, "23877") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_RTC_INFO = 0x01;
+	if (strcmp(string, "23878") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_RTC_INFO = 0x01;
+	if (strcmp(string, "23879") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_PRECHARGE_INFO = 0x01;
+	if (strcmp(string, "23880") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_PRECHARGE_INFO = 0x01;
+	if (strcmp(string, "23881") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMSG_Sequence = 0x01;
+	if (strcmp(string, "23882") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCAN_MSG_Unrecognized_CMD_ID = 0x01;
+	if (strcmp(string, "23883") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsDIN_Msg_Decode_Error = 0x01;
+	if (strcmp(string, "23884") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsDIN_Msg_Encode_Error = 0x01;
+	if (strcmp(string, "23885") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO1_Msg_Decode_Error = 0x01;
+	if (strcmp(string, "23886") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO1_Msg_Encode_Error = 0x01;
+	if (strcmp(string, "23887") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO2_Msg_Decode_Error = 0x01;
+	if (strcmp(string, "23888") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO2_Msg_Encode_Error = 0x01;
+}
+
+void CANReceiver()
+{
+	pid_t canRecPid;
+
+	canRecPid = fork();
+
+	if(canRecPid > 0)
+	{
+		int nbytes;
+		struct can_frame frame;
+		int intCmd;
+		// 槍資訊
+		struct ChargingInfoData *_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+		struct timeval _cmd_ack_timeout[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+
+		bool isPass = false;
+		while(!isPass)
+		{
+			isPass = true;
+			for (byte _index = 0; _index < gun_count; _index++)
+			{
+				if (!FindChargingInfoData(_index, &_chargingData[0]))
+				{
+					DEBUG_ERROR("EvComm (main) : FindChargingInfoData false \n");
+					isPass = false;
+					break;
+				}
+			}
+		}
+
+		for (byte _index = 0; _index < gun_count; _index++)
+			gettimeofday(&_cmd_ack_timeout[_index], NULL);
+
+		while (1)
+		{
+			memset(&frame, 0, sizeof(struct can_frame));
+			nbytes = read(CanFd, &frame, sizeof(struct can_frame));
+
+			for (byte _index = 0; _index < gun_count; _index++)
+			{
+				if (GetTimeoutValue(_cmd_ack_timeout[_index]) >= 5000000)
+				{
+					// ACK timeout
+					//PRINTF_FUNC("gun = %x, ack timeout \n", _index);
+				}
+			}
+
+			if (nbytes > 0)
+			{
+				byte target;
+				byte targetGun = 0x00;
+				intCmd = (int) (frame.can_id & CAN_EFF_MASK);
+
+				if (intCmd == ADDRESS_REQ)
+				{
+					AddrAssignment(frame.data);
+					continue;
+				}
+
+				intCmd = (int) (frame.can_id & CAN_EFF_MASK & 0xFFFFFF00);
+				target = ((byte) (frame.can_id & 0x000000FF));		// 0x01 or 0x02
+
+				for (byte _index = 0; _index < gun_count; _index++)
+				{
+					if (_chargingData[_index]->Evboard_id == target)
+					{
+						targetGun = _index;
+						break;
+					}
+				}
+
+				if(targetGun < 0 || targetGun >= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)
+				{
+					PRINTF_FUNC("EvComm (CANReceiver) : Target index = %x is < 0 or > QUANTITY \n", targetGun);
+					continue;
+				}
+				if(intCmd == 256)
+				{
+					continue;
+				}
+
+				gettimeofday(&_cmd_ack_timeout[targetGun], NULL);
+				switch (intCmd)
+				{
+					case NOTIFICATION_EV_STATUS:
+					{
+						_chargingData[targetGun]->ConnectorPlugIn = frame.data[0];
+						_chargingData[targetGun]->PilotVoltage = frame.data[1];
+
+						//PRINTF_FUNC("index = %d, ConnectorPlugIn = %x, data[0] = %x \n", targetGun, _chargingData[targetGun]->ConnectorPlugIn, frame.data[0]);
+						//PRINTF_FUNC("ConnectorPlugIn = %x \n", (-120 + frame.data[1]) / 10);
+					}
+						break;
+					case ACK_EV_FW_VERSION:
+					{
+						if (_chargingData[targetGun]->Type == _Type_Chademo)
+						{
+							memcpy(ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].version, frame.data, ARRAY_SIZE(frame.data));
+							ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].SelfTest_Comp = PASS;
+							PRINTF_FUNC("chademo ver. : %s\n", ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].version);
+						}
+						else if (_chargingData[targetGun]->Type == _Type_CCS_2)
+						{
+							if (ShmCcsData->CommProtocol == 0x01)
+							{
+								memcpy(&ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index].version, frame.data, ARRAY_SIZE(frame.data));
+								ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index].SelfTest_Comp = PASS;
+								PRINTF_FUNC("CCS FW = %s \n", ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index].version);
+							}
+						}
+					}
+						break;
+					case ACK_EV_HW_VERSION:
+					{
+						//PRINTF_FUNC("Get EV HW = %s \n", frame.data);
+					}
+						break;
+					case ACK_GET_OUTPUT_REQ:
+					{
+						_chargingData[targetGun]->EvBatterySoc = frame.data[1];
+						_chargingData[targetGun]->EvBatterytargetVoltage = ((short) frame.data[3] << 8) + (short) frame.data[2];
+						_chargingData[targetGun]->EvBatterytargetCurrent = ((short) frame.data[5] << 8) + (short) frame.data[4];
+						_chargingData[targetGun]->PresentChargedDuration = ((short) frame.data[7] << 8) + (short) frame.data[6];
+
+						if (_chargingData[targetGun]->Type == _Type_Chademo)
+						{
+							if (ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].EvDetection != frame.data[0])
+							{
+								ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].PresentMsgFlowStatus = frame.data[0];
+							}
+
+							ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].EvDetection = frame.data[0];
+							ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].SOC = _chargingData[targetGun]->EvBatterySoc;
+							ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].TargetBatteryVoltage = _chargingData[targetGun]->EvBatterytargetVoltage;
+							ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].ChargingCurrentRequest = _chargingData[targetGun]->EvBatterytargetCurrent;
+						}
+						else if (_chargingData[targetGun]->Type == _Type_CCS_2)
+						{
+							if(ShmCcsData->CommProtocol == 0x01)
+							{
+								ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index].PresentMsgFlowStatus = frame.data[0];
+							}
+						}
+
+						//PRINTF_FUNC("EvBatterytargetVoltage = %f \n", _chargingData[targetGun]->EvBatterytargetVoltage);
+						//PRINTF_FUNC("EvBatterytargetCurrent = %f \n", _chargingData[targetGun]->EvBatterytargetCurrent);
+						//PRINTF_FUNC("BatteryVoltage = %d \n", ShmCHAdeMOData->ev[_chargingData[target]->type_index].TargetBatteryVoltage);
+						//PRINTF_FUNC("CurrentRequest = %d \n", ShmCHAdeMOData->ev[_chargingData[target]->type_index].ChargingCurrentRequest);
+					}
+						break;
+					case ACK_GET_EV_BATTERY_INFO:
+					{
+						//_chargingData[target].EvACorDCcharging = frame.data[0];
+						//_chargingData[target]->TotalBatteryCap = ((float) frame.data[4] << 8) + (short) frame.data[3];
+						_chargingData[targetGun]->EvBatteryMaxVoltage = ((short) frame.data[4] << 8) + (short) frame.data[3];
+						//_chargingData[target]->EvBatteryMaxCurrent = ((float) frame.data[4] << 8) + (short) frame.data[3];
+						//_chargingData[target].MaxiBatteryCurrent = ((short) frame.data[6] << 8) + (short) frame.data[5];
+						if (_chargingData[targetGun]->Type == _Type_Chademo)
+						{
+							ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].TotalBatteryCapacity = ((short) frame.data[2] << 8) + (short) frame.data[1];
+							ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].MaxiBatteryVoltage = _chargingData[targetGun]->EvBatteryMaxVoltage;
+
+							//PRINTF_FUNC("EvBatteryMaxVoltage = %f \n", _chargingData[target]->EvBatteryMaxVoltage);
+							//PRINTF_FUNC("TotalBatteryCapacity = %d \n", ShmCHAdeMOData->ev[_chargingData[target]->type_index].TotalBatteryCapacity);
+							//PRINTF_FUNC("MaxiBatteryVoltage = %d \n", ShmCHAdeMOData->ev[_chargingData[target]->type_index].MaxiBatteryVoltage);
+						}
+						else if (_chargingData[targetGun]->Type == _Type_CCS_2)
+						{
+
+						}
+					}
+						break;
+					case ACK_GET_MISCELLANEOUS_INFO:
+					{
+						if (_chargingData[targetGun]->Type == _Type_Chademo)
+						{
+							_chargingData[targetGun]->GunLocked = frame.data[0];
+							ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].ConnectorTemperatureP = frame.data[1];
+							ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].ConnectorTemperatureN = frame.data[2];
+							_chargingData[targetGun]->PilotVoltage = (float)(-120 + frame.data[3]) / 10;
+							ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].EvboardStatus = frame.data[7];
+						}
+						else if (_chargingData[targetGun]->Type == _Type_CCS_2)
+						{
+							if (ShmCcsData->CommProtocol == 0x01)
+							{
+								_chargingData[targetGun]->GunLocked = frame.data[0];
+								//ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index]. .ConnectorTemperatureP = frame.data[1];
+								//ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index]. .ConnectorTemperatureN = frame.data[2];
+								_chargingData[targetGun]->PilotVoltage = (float)(-120 + frame.data[3]) / 10;
+							}
+						}
+
+						//PRINTF_FUNC("EvboardStatus = %x \n", ShmCHAdeMOData->evse[_chargingData[target]->type_index].EvboardStatus);
+						//PRINTF_FUNC("ConnectorPlug locked = %x \n", frame.data[0]);
+						//PRINTF_FUNC("ConnectorTemp 0= %d \n", ShmCHAdeMOData->evse[_chargingData[target]->type_index].ConnectorTemperatureP);
+						//PRINTF_FUNC("ConnectorTemp 1= %d \n", ShmCHAdeMOData->evse[_chargingData[target]->type_index].ConnectorTemperatureN);
+						//PRINTF_FUNC("PilotVoltage = %x \n", (-120 + frame.data[3]) / 10);
+					}
+						break;
+					case ACK_EVSE_ISOLATION_STATUS:	{}
+						break;
+					case ACK_EVSE_PRECHAGE_INFO:
+					{
+						_chargingData[targetGun]->PrechargeStatus = frame.data[0];
+					}
+						break;
+					case NOTIFICATION_EV_STOP:
+					{
+						// 車端要求停止
+						// frame.data[0] : 0x01 => normal stop, 0x02 => ev emergency stop
+						PRINTF_FUNC("NOTIFICATION_EV_STOP -----------------------------\n");
+						if (frame.data[0] == 0x02)
+						{
+							AbnormalStopAnalysis(targetGun, frame.data + 1);
+						}
+						_chargingData[targetGun]->StopChargeFlag = YES;
+					}
+						break;
+					default:
+						PRINTF_FUNC("EV board = %d, Ack none defined. intCmd = %d  \n", targetGun, intCmd);
+						break;
+				}
+			}
+			usleep(10000);
+		}
+	}
+}
+
+//================================================
+// Main process
+//================================================
+// 檢查 Byte 中某個 Bit 的值
+// _byte : 欲改變的 byte
+// _bit : 該 byte 的第幾個 bit
+unsigned char EvDetectionStatus(unsigned char _byte, unsigned char _bit)
+{
+	return ( _byte & mask_table[_bit] ) != 0x00;
+}
+
+bool IsConnectorPlugIn(struct ChargingInfoData *chargingData)
+{
+	return (chargingData->ConnectorPlugIn == 0x01) ? true : false;
+}
+
+void SetPresentChargingOutputPower(struct ChargingInfoData *chargingData_1, struct ChargingInfoData *chargingData_2)
+{
+	float vol1 = 0, cur1 = 0;
+	float vol2 = 0, cur2 = 0;
+
+	//PRINTF_FUNC("f vol - 0 = %f \n", chargingData_1->FireChargingVoltage);
+	//PRINTF_FUNC("f cur - 0 = %f \n", chargingData_1->PresentChargingCurrent);
+	//PRINTF_FUNC("***********************f vol - 1 = %f \n", chargingData_2->FireChargingVoltage);
+	//PRINTF_FUNC("***********************f cur - 1 = %f \n", chargingData_2->PresentChargingCurrent);
+
+	vol1 = chargingData_1->FireChargingVoltage;
+	cur1 = chargingData_1->PresentChargingCurrent;
+
+	vol2 = chargingData_2->FireChargingVoltage;
+	cur2 = chargingData_2->PresentChargingCurrent;
+
+	SetPresentOutputPower(vol1, cur1, vol2, cur2);
+}
+
+void SetPresentChargingOutputCap(struct ChargingInfoData *chargingData_1, struct ChargingInfoData *chargingData_2)
+{
+	float pow1 = 0, cur1 = 0;
+	float pow2 = 0, cur2 = 0;
+	float vol = 0;
+
+	if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_NONE)
+	{
+		pow1 = chargingData_1->DeratingChargingPower;
+		cur1 = chargingData_1->DeratingChargingCurrent;
+	}
+	else
+	{
+		pow1 = chargingData_1->AvailableChargingPower;
+		cur1 = chargingData_1->AvailableChargingCurrent;
+	}
+	vol = chargingData_1->MaximumChargingVoltage;
+	GetMaxVolAndCurMethod(chargingData_1->Index, &vol, &cur1);
+	GetMaxPowerMethod(&pow1);
+
+	if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_NONE)
+	{
+		pow2 = chargingData_2->DeratingChargingPower;
+		cur2 = chargingData_2->DeratingChargingCurrent;
+	}
+	else
+	{
+		pow2 = chargingData_2->AvailableChargingPower;
+		cur2 = chargingData_2->AvailableChargingCurrent;
+	}
+	vol = chargingData_2->MaximumChargingVoltage;
+	GetMaxVolAndCurMethod(chargingData_2->Index, &vol, &cur2);
+	GetMaxPowerMethod(&pow2);
+
+	PRINTF_FUNC("To EV Power_1 = %f, Cur_1 = %f, Power_2 = %f, Cur_2 = %f \n", pow1, cur1, pow2, cur2);
+	SetPresentOutputCapacity(pow1, cur1, pow2, cur2);
+}
+
+void Initialization()
+{
+	bool isPass = false;
+	while(!isPass)
+	{
+		isPass = true;
+		for (byte _index = 0; _index < gun_count; _index++)
+		{
+			if (!FindChargingInfoData(_index, &_chargingData[0]))
+			{
+				DEBUG_ERROR("EvComm (main) : FindChargingInfoData false \n");
+				isPass = false;
+				break;
+			}
+		}
+	}
+}
+
+void GetMaxVolAndCurMethod(byte index, float *vol, float *cur)
+{
+	if (maxChargingVol[index] != 0 && maxChargingVol[index] <= *vol)
+		*vol = maxChargingVol[index];
+
+	if (maxChargingCur[index] != 0 && maxChargingCur[index] <= *cur)
+		*cur = maxChargingCur[index];
+}
+
+void GetMaxPowerMethod(float *pow)
+{
+	if (maxChargingPow != 0 && maxChargingPow <= *pow)
+		*pow = maxChargingPow;
+}
+
+byte GetStopChargingReasonByEvse(byte gunIndex, byte *reason)
+{
+	byte result = NO;
+
+	if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == 0x01)
+	{
+		// 012251
+		*(reason + 5) = 0;
+		*(reason + 4)  = 1;
+		*(reason + 3)  = 2;
+		*(reason + 2)  = 2;
+		*(reason + 1)  = 5;
+		*(reason + 0)  = 1;
+		result = YES;
+	}
+	else if (_chargingData[gunIndex]->Type == _Type_Chademo &&
+			ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault == 0x01)
+	{
+		// 011012
+		*(reason + 5) = 0;
+		*(reason + 4) = 1;
+		*(reason + 3) = 1;
+		*(reason + 2) = 0;
+		*(reason + 1) = 1;
+		*(reason + 0) = 2;
+		result = YES;
+	}
+	else if (_chargingData[gunIndex]->Type == _Type_CCS_2 &&
+			ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault == 0x01)
+	{
+		// 011014
+		*(reason + 5) = 0;
+		*(reason + 4) = 1;
+		*(reason + 3) = 1;
+		*(reason + 2) = 0;
+		*(reason + 1) = 1;
+		*(reason + 0) = 4;
+		result = YES;
+	}
+
+	return result;
+}
+
+int main(int argc, char *argv[])
+{
+	if(InitShareMemory() == FAIL)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("InitShareMemory NG\n");
+		#endif
+		if(ShmStatusCodeData != NULL)
+		{
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
+		}
+		sleep(5);
+		return 0;
+	}
+
+	Initialization();
+	CanFd = InitCanBus();
+	CANReceiver();
+
+	byte priorityLow = 1;
+	while(CanFd)
+	{
+		for(byte _index = 0; _index < gun_count; _index++)
+		{
+			if (priorityLow == 1)
+			{
+				// 優先權較低 - 只要有回應即不會再詢問
+				if (_chargingData[_index]->Type == _Type_Chademo &&
+						ShmCHAdeMOData->evse[_chargingData[_index]->type_index].SelfTest_Comp != PASS)
+				{
+					GetFirmwareVersion(_index, _chargingData[_index]->Evboard_id);
+					GetHardwareVersion(_index, _chargingData[_index]->Evboard_id);
+				}
+				else if (_chargingData[_index]->Type == _Type_CCS_2)
+				{
+					if (ShmCcsData->CommProtocol == 0x01 &&
+						ShmCcsData->V2GMessage_DIN70121[_chargingData[_index]->type_index].SelfTest_Comp != PASS)
+					{
+						GetFirmwareVersion(_index, _chargingData[_index]->Evboard_id);
+						GetHardwareVersion(_index, _chargingData[_index]->Evboard_id);
+					}
+				}
+
+				// 固定要取得的資訊 : 1.槍鎖狀態, 2."Connector 1" 溫度, 3."Connector 2" 溫度, 4.Pilot Voltage
+				//PRINTF_FUNC("GetMiscellaneousInfo. index = %d, Eid = %d \n", _index, _chargingData[_index]->Evboard_id);
+				GetMiscellaneousInfo(_index, _chargingData[_index]->Evboard_id);
+			}
+
+			switch (_chargingData[_index]->SystemStatus)
+			{
+				case S_IDLE:
+				case S_RESERVATION:
+					_chargingData[_index]->PresentChargedEnergy = 0;
+					_chargingData[_index]->PresentChargingPower = 0;
+					_chargingData[_index]->GroundFaultStatus = GFD_WAIT;
+					_chargingData[_index]->StopChargeFlag = NO;
+					chargingTime[_index] = 0;
+
+					if (_chargingData[_index]->Type == _Type_Chademo)
+					{
+						ClearAbnormalStatus_Chademo(_index);
+					}
+					else if (_chargingData[_index]->Type == _Type_CCS_2)
+					{
+						ClearAbnormalStatus_CCS(_index);
+					}
+
+					if (priorityLow == 1)
+					{
+						maxChargingCur[_index] = ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent;
+						maxChargingPow = ShmSysConfigAndInfo->SysConfig.MaxChargingPower;
+					}
+					break;
+				case S_PREPARING_FOR_EV:
+				{
+					// 開始確認車端是否同意開始充電 : 1.SOC, 2.Target Vol, 3.Target Cur, 4.Charging remaining time
+					GetOutputReq(_index, _chargingData[_index]->Evboard_id);
+
+					//PRINTF_FUNC("PresentChargingVoltage = %f \n", _chargingData[_index]->PresentChargingVoltage);
+					//PRINTF_FUNC("PresentChargingCurrent = %f \n", _chargingData[_index]->PresentChargingCurrent);
+					//PRINTF_FUNC("AvailableChargingPower = %f \n", _chargingData[_index]->AvailableChargingPower);
+					//PRINTF_FUNC("AvailableChargingCurrent = %f \n", _chargingData[_index]->AvailableChargingCurrent);
+					//PRINTF_FUNC("MaximumChargingVoltage = %f \n", _chargingData[_index]->MaximumChargingVoltage);
+
+					// 設定當前輸出
+					if (gun_count == 1)
+						SetPresentChargingOutputPower(_chargingData[0], _chargingData[0]);
+					else if (gun_count == 2)
+						SetPresentChargingOutputPower(_chargingData[0], _chargingData[1]);
+
+					if (priorityLow == 1)
+					{
+						float maxVol, maxCur;
+						// 樁端輸出能力
+						if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_NONE)
+						{
+							maxVol = _chargingData[_index]->MaximumChargingVoltage;
+							maxCur = _chargingData[_index]->DeratingChargingCurrent;
+						}
+						else
+						{
+							maxVol = _chargingData[_index]->MaximumChargingVoltage;
+							maxCur = _chargingData[_index]->AvailableChargingCurrent;
+						}
+						GetMaxVolAndCurMethod(_index, &maxVol, &maxCur);
+
+						PRINTF_FUNC("To EV Max_Vol = %f, Cap_Cur = %f \n", maxVol, maxCur);
+						SetChargingPermission(_index, START,
+						_chargingData[_index]->AvailableChargingPower,
+								maxCur,
+								maxVol,
+								_chargingData[_index]->Evboard_id);
+
+						// 取得車端電池資訊 : 1.AC or DC ? 2.Total battery cap, 3.Max battery vol, 4.Max battery cur
+						GetEvBatteryInfo(_index, _chargingData[_index]->Evboard_id);
+					}
+				}
+					break;
+				case S_PREPARING_FOR_EVSE:
+				case S_CCS_PRECHARGE_ST0:
+				case S_CCS_PRECHARGE_ST1:
+				{
+					// 開始確認車端是否同意開始充電
+					GetOutputReq(_index, _chargingData[_index]->Evboard_id);
+
+					// 設定當前輸出
+					if (gun_count == 1)
+						SetPresentChargingOutputPower(_chargingData[0], _chargingData[0]);
+					else if (gun_count == 2)
+						SetPresentChargingOutputPower(_chargingData[0], _chargingData[1]);
+
+					if (priorityLow % 5 == 1)
+					{
+						// 樁端輸出能力改變
+						if (gun_count == 1)
+							SetPresentChargingOutputCap(_chargingData[0], _chargingData[0]);
+						else if (gun_count == 2)
+							SetPresentChargingOutputCap(_chargingData[0], _chargingData[1]);
+					}
+
+					// 持續通知 Isolation 測試狀態
+					if (priorityLow == 1)
+					{
+						// 拉 500 V 如果在一秒鐘內 GFD 都符合則 PASS
+						if(_chargingData[_index]->GroundFaultStatus != GFD_WAIT)
+						{
+							SetIsolationStatus(_index, _chargingData[_index]->GroundFaultStatus, _chargingData[_index]->Evboard_id);
+						}
+
+						if(_chargingData[_index]->SystemStatus == S_CCS_PRECHARGE_ST0 &&
+							_chargingData[_index]->PrechargeStatus == PRECHARGE_READY)
+						{
+							SetEvsePrechargeInfo(_index, PRECHARGE_PRERELAY_PASS, _chargingData[_index]->Evboard_id);
+						}
+					}
+				}
+					break;
+				case S_CHARGING:
+				{
+					// 計算 Power
+					_chargingData[_index]->PresentChargingPower = ((float)((_chargingData[_index]->PresentChargingVoltage / 10) * (_chargingData[_index]->PresentChargingCurrent / 10)) / 1000);
+
+					if (chargingTime[_index] == 0)
+					{
+						chargingTime[_index] = _chargingData[_index]->RemainChargingDuration;
+					}
+					else
+					{
+						int passTime = _chargingData[_index]->RemainChargingDuration - chargingTime[_index];
+
+						if (passTime > 0)
+						{
+							_chargingData[_index]->PresentChargedEnergy += (_chargingData[_index]->PresentChargingPower) * passTime / 3600;
+							chargingTime[_index] = _chargingData[_index]->RemainChargingDuration;
+						}
+					}
+
+					// 開始確認車端是否同意開始充電
+					GetOutputReq(_index, _chargingData[_index]->Evboard_id);
+
+					// 設定當前輸出
+					if (gun_count == 1)
+						SetPresentChargingOutputPower(_chargingData[0], _chargingData[0]);
+					else if (gun_count == 2)
+						SetPresentChargingOutputPower(_chargingData[0], _chargingData[1]);
+
+					// for test end
+					if (priorityLow % 5 == 0)
+					{
+						// 樁端輸出能力改變
+						if (gun_count == 1)
+							SetPresentChargingOutputCap(_chargingData[0], _chargingData[0]);
+						else if (gun_count == 2)
+							SetPresentChargingOutputCap(_chargingData[0], _chargingData[1]);
+					}
+
+					// GFD 失敗再通知
+					if (priorityLow == 1)
+					{
+						if(_chargingData[_index]->GroundFaultStatus == GFD_FAIL)
+						{
+							SetIsolationStatus(_index, _chargingData[_index]->GroundFaultStatus, _chargingData[_index]->Evboard_id);
+						}
+
+						if(_chargingData[_index]->Type == _Type_CCS_2 &&
+							_chargingData[_index]->PrechargeStatus == PRECHARGE_READY)
+						{
+							SetEvsePrechargeInfo(_index, PRECHARGE_CHARELAY_PASS, _chargingData[_index]->Evboard_id);
+						}
+					}
+				}
+					break;
+				case S_TERMINATING:
+				{
+					// 設定當前輸出
+					if (gun_count == 1)
+						SetPresentChargingOutputPower(_chargingData[0], _chargingData[0]);
+					else if (gun_count == 2)
+						SetPresentChargingOutputPower(_chargingData[0], _chargingData[1]);
+
+					// 槍鎖還在,則代表是樁端要求的停止
+					if (_chargingData[_index]->GunLocked == START)
+					{
+						byte normalStop = 0x01;
+						byte stopReason[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+
+						if (GetStopChargingReasonByEvse(_index, stopReason))
+						{
+							normalStop = 0x02;
+						}
+
+						EvseStopChargingEvent(normalStop, stopReason, _chargingData[_index]->Evboard_id);
+					}
+					GetOutputReq(_index, _chargingData[_index]->Evboard_id);
+				}
+					break;
+				case S_COMPLETE:
+				{
+					if (priorityLow == 1)
+					{
+						float maxVol, maxCur;
+
+						// 樁端輸出能力
+						if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_NONE)
+						{
+							maxVol = _chargingData[_index]->MaximumChargingVoltage;
+							maxCur = _chargingData[_index]->DeratingChargingCurrent;
+						}
+						else
+						{
+							maxVol = _chargingData[_index]->MaximumChargingVoltage;
+							maxCur = _chargingData[_index]->AvailableChargingCurrent;
+						}
+
+						GetMaxVolAndCurMethod(_index, &maxVol, &maxCur);
+						SetChargingPermission(_index, STOP,
+									_chargingData[_index]->AvailableChargingPower,
+									maxCur,
+									maxVol,
+									_chargingData[_index]->Evboard_id);
+					}
+				}
+					break;
+			}
+		}
+		priorityLow >= 20 ? priorityLow = 1 : priorityLow++;
+		usleep(45000); //EV 小板通訊 (50 ms)
+	}
+	DEBUG_INFO("Module_EvComm : Can-bus port = %d \n", CanFd);
+	return FAIL;
+}

+ 77 - 0
EVSE/Projects/PlugIt360/Apps/Module_EvComm.h

@@ -0,0 +1,77 @@
+#ifndef MODULE_EVCOMM_H_
+#define MODULE_EVCOMM_H_
+
+#include 	<stdbool.h>
+
+int CanFd;
+
+typedef unsigned char 		byte;
+
+extern struct Ev_Board_Cmd
+{
+	int none;							// 0
+	int address_assignment;				// 0x00000200
+	int get_firmware_ver;				// 0x00000400
+	int get_hardware_ver;				// 0x00000500
+	int charging_permission;			// 0x00000600
+	int present_output_power;			// 0x00000700
+	int present_output_cap;				// 0x00000800
+	int get_output_req;					// 0x00000900
+	int get_battery_info;				// 0x00000A00
+	int evse_stop_charging;				// 0x00000C00
+	int get_miscellaneous_info;			// 0x00000D00
+
+	int download_req;					// 0x00000E00
+	int start_block_transfer;			// 0x00000F00
+	int data_transfer;					// 0x00001000
+	int download_finish;				// 0x00001100
+
+	int isolation_status;				// 0x00001200
+	int evse_precharge_info;			// 0x00001500
+}Ev_Cmd;
+
+extern struct Ev_Cmd_Dir
+{
+	unsigned short master_to_slave;
+	unsigned short slave_to_master;
+}Ev_Dir;
+
+struct timeval _id_assign_time;
+
+// Send msg to can-bus
+void SetTargetAddr(byte *target_number, byte index);
+
+void GetFirmwareVersion(byte gun_index, byte toId);
+void GetHardwareVersion(byte gun_index, byte toId);
+void SetChargingPermission(byte gun_index, byte permissionStatus, short aOutputPw, short aOutputVol, short aOutputCur, byte toId);
+void SetPresentOutputPower(short outputVol_b1, short outputCur_b1, short outputVol_b2, short outputCur_b2);
+void SetPresentOutputCapacity(short aOutputPw_b1, short aOutputCur_b1, short aOutputPw_b2, short aOutputCur_b2);
+void GetOutputReq(byte gun_index, byte toId);
+void GetEvBatteryInfo(byte gun_index, byte toId);
+void GetMiscellaneousInfo(byte gun_index, byte toId);
+void SetIsolationStatus(byte gun_index, byte result, byte toId);
+void SetEvsePrechargeInfo(byte gun_index, byte result, byte toId);
+// 發送電樁主動停止充電結果及原因
+void EvseStopChargingEvent(byte stopResult, byte *stopReason, byte toId);
+
+// Receive msg From can-bus.
+
+enum Receieve_PSU_msgf
+{
+	// 車端主動
+	ADDRESS_REQ = 						0x080001FF,
+	NOTIFICATION_EV_STATUS = 			0x08000300,
+	NOTIFICATION_EV_STOP = 				0x08000B00,
+
+	// 車端回應
+	ACK_EV_FW_VERSION = 				0x08000400,
+	ACK_EV_HW_VERSION = 				0x08000500,
+	ACK_GET_OUTPUT_REQ =				0x08000900,
+	ACK_GET_EV_BATTERY_INFO =			0x08000A00,
+	ACK_GET_MISCELLANEOUS_INFO = 		0x08000D00,
+	ACK_EVSE_ISOLATION_STATUS = 		0x08001200,
+	ACK_EVSE_PRECHAGE_INFO = 			0x08001500,
+};
+
+#endif /* MODULE_EVCOMM_H_ */
+

BIN
EVSE/Projects/PlugIt360/Apps/Module_EventLogging


+ 313 - 0
EVSE/Projects/PlugIt360/Apps/Module_EventLogging.c

@@ -0,0 +1,313 @@
+#include 	<sys/time.h>
+#include 	<sys/timeb.h>
+#include    <sys/types.h>
+#include    <sys/stat.h>
+#include 	<sys/types.h>
+#include 	<sys/ioctl.h>
+#include 	<sys/socket.h>
+#include 	<sys/ipc.h>
+#include 	<sys/shm.h>
+#include 	<sys/shm.h>
+#include 	<sys/mman.h>
+#include 	<linux/wireless.h>
+#include 	<arpa/inet.h>
+#include 	<netinet/in.h>
+
+#include 	<unistd.h>
+#include 	<stdarg.h>
+#include    <stdio.h>      /*標準輸入輸出定義*/
+#include    <stdlib.h>     /*標準函數庫定義*/
+#include    <unistd.h>     /*Unix 標準函數定義*/
+#include    <fcntl.h>      /*檔控制定義*/
+#include    <termios.h>    /*PPSIX 終端控制定義*/
+#include    <errno.h>      /*錯誤號定義*/
+#include 	<errno.h>
+#include 	<string.h>
+#include	<time.h>
+#include	<ctype.h>
+#include 	<ifaddrs.h>
+#include	"../../define.h"
+
+#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
+#define PASS				1
+#define FAIL				-1
+
+struct SysConfigAndInfo			*ShmSysConfigAndInfo;
+struct StatusCodeData 			*ShmStatusCodeData;
+
+void PRINTF_FUNC(char *string, ...);
+
+int StoreLogMsg(const char *fmt, ...);
+#define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+
+int StoreLogMsg(const char *fmt, ...)
+{
+	char Buf[4096+256];
+	char buffer[4096];
+	time_t CurrentTime;
+	struct tm *tm;
+	va_list args;
+
+	va_start(args, fmt);
+	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
+	va_end(args);
+
+	memset(Buf,0,sizeof(Buf));
+	CurrentTime = time(NULL);
+	tm=localtime(&CurrentTime);
+	sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
+			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
+			buffer,
+			tm->tm_year+1900,tm->tm_mon+1);
+	system(Buf);
+
+	return rc;
+}
+
+int DiffTimeb(struct timeb ST, struct timeb ET)
+{
+	//return milli-second
+	unsigned int StartTime,StopTime;
+
+	StartTime=(unsigned int)ST.time;
+	StopTime=(unsigned int)ET.time;
+	return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
+}
+
+void PRINTF_FUNC(char *string, ...)
+{
+	if (DEBUG)
+	{
+		va_list args;
+		char buffer[4096];
+
+		va_start(args, string);
+		vsnprintf(buffer, sizeof(buffer), string, args);
+		va_end(args);
+		printf("%s \n", buffer);
+	}
+}
+
+//=================================
+// Common routine
+//=================================
+char* getTimeString(void)
+{
+	char *result=malloc(21);
+	time_t timep;
+	struct tm *p;
+	time(&timep);
+	p=gmtime(&timep);
+
+	sprintf(result, "[%04d-%02d-%02d %02d:%02d:%02d]", (1900+p->tm_year), (1+p->tm_mon), p->tm_mday, p->tm_hour, p->tm_hour, p->tm_sec);
+
+	return result;
+}
+
+//==========================================
+// Init all share memory
+//==========================================
+int InitShareMemory()
+{
+	int result = PASS;
+	int MeterSMId;
+
+	//creat ShmSysConfigAndInfo
+	if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0)
+    {
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
+		#endif
+		result = FAIL;
+	}
+    else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+    {
+    	#ifdef SystemLogMessage
+    	DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
+		#endif
+    	result = FAIL;
+   	 }
+    else
+    {}
+
+   	 //creat ShmStatusCodeData
+   	 if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0)
+    {
+		#ifdef SystemLogMessage
+   		DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
+		#endif
+   		result = FAIL;
+	}
+    else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+    {
+    	#ifdef SystemLogMessage
+    	DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
+		#endif
+    	result = FAIL;
+   	}
+    else
+    {}
+
+    return result;
+}
+
+//================================================
+// Main process
+//================================================
+void AddFaultCodeToBuf(unsigned char *Code)
+{
+	if(ShmSysConfigAndInfo->SysWarningInfo.WarningCount < 10)
+	{
+		memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[ShmSysConfigAndInfo->SysWarningInfo.WarningCount][0], Code, 7);
+		ShmSysConfigAndInfo->SysWarningInfo.WarningCount++;
+	}
+}
+
+void RemoveFaultCodeToBuf(unsigned char *Code)
+{
+	unsigned char find = 0x00;
+	char _code[7];
+	sprintf(_code,"%s", Code);
+
+	for(unsigned char i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++)
+	{
+		if (find == 0x00)
+		{
+			if(memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], _code, 7) != 0)
+			{
+				find = 0x01;
+			}
+		}
+		else
+		{
+			if(i == ShmSysConfigAndInfo->SysWarningInfo.WarningCount - 1)
+			{
+				memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "", 7);
+			}
+			else
+			{
+				memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0],
+						&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + 1][0], 7);
+			}
+		}
+	}
+
+	ShmSysConfigAndInfo->SysWarningInfo.WarningCount--;
+}
+
+int main(void)
+{
+	int ByteCount,BitCount;
+	unsigned char tmp, EventCodeTmp[7];
+
+	if(InitShareMemory() == FAIL)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("InitShareMemory NG\n");
+		#endif
+		if(ShmStatusCodeData!=NULL)
+		{
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
+		}
+		sleep(5);
+		return 0;
+	}
+
+	for(;;)
+	{
+		//check Fault Status
+		for(ByteCount=0;ByteCount<4;ByteCount++)
+		{
+			if(ShmStatusCodeData->FaultCode.FaultEvents.FaultVal[ByteCount] != ShmStatusCodeData->FaultCode.PreviousFaultVal[ByteCount])
+			{
+				tmp=ShmStatusCodeData->FaultCode.FaultEvents.FaultVal[ByteCount]; //prevent be modified during following process
+				for(BitCount=0;BitCount<8;BitCount++)
+				{
+					if(((tmp>>BitCount)&0x01) != ((ShmStatusCodeData->FaultCode.PreviousFaultVal[ByteCount]>>BitCount)&0x01))
+					{
+						memset(EventCodeTmp,0,sizeof(EventCodeTmp));
+						memcpy(EventCodeTmp,FaultStatusCode[ByteCount*8+BitCount],sizeof(EventCodeTmp)-1);
+						if(((tmp>>BitCount)&0x01)==0)//Recovered
+						{
+							//EventCodeTmp[0]=1;
+							DEBUG_INFO("Recovery Fault Code = %s\n", EventCodeTmp);
+							ShmStatusCodeData->FaultCode.PreviousFaultVal[ByteCount] &= ~(1<<BitCount);
+							RemoveFaultCodeToBuf(EventCodeTmp);
+						}
+						else
+						{
+							DEBUG_INFO("Fault Code = %s\n", EventCodeTmp);
+							ShmStatusCodeData->FaultCode.PreviousFaultVal[ByteCount] |= (1<<BitCount);
+							AddFaultCodeToBuf(EventCodeTmp);
+						}
+					}
+				}
+			}
+		}
+
+		//check Alarm Status
+		for(ByteCount=0;ByteCount<11;ByteCount++)
+		{
+			if(ShmStatusCodeData->AlarmCode.AlarmEvents.AlarmVal[ByteCount] != ShmStatusCodeData->AlarmCode.PreviousAlarmVal[ByteCount])
+			{
+				tmp=ShmStatusCodeData->AlarmCode.AlarmEvents.AlarmVal[ByteCount]; //prevent be modified during following process
+				for(BitCount=0;BitCount<8;BitCount++)
+				{
+					if(((tmp>>BitCount)&0x01) != ((ShmStatusCodeData->AlarmCode.PreviousAlarmVal[ByteCount]>>BitCount)&0x01))
+					{
+						memset(EventCodeTmp,0,sizeof(EventCodeTmp));
+						memcpy(EventCodeTmp,AlarmStatusCode[ByteCount*8+BitCount],sizeof(EventCodeTmp)-1);
+						if(((tmp>>BitCount)&0x01)==0)//Recovered
+						{
+							//EventCodeTmp[0]=1;
+							DEBUG_INFO("Recovery Alarm Code = %s\n", EventCodeTmp);
+							ShmStatusCodeData->AlarmCode.PreviousAlarmVal[ByteCount] &= ~(1<<BitCount);
+							RemoveFaultCodeToBuf(EventCodeTmp);
+						}
+						else
+						{
+							DEBUG_INFO("Alarm Code = %s\n", EventCodeTmp);
+							ShmStatusCodeData->AlarmCode.PreviousAlarmVal[ByteCount] |= (1<<BitCount);
+							AddFaultCodeToBuf(EventCodeTmp);
+						}
+					}
+				}
+			}
+		}
+
+		//check Info Status
+		for(ByteCount=0;ByteCount<29;ByteCount++)
+		{
+			if(ShmStatusCodeData->InfoCode.InfoEvents.InfoVal[ByteCount] != ShmStatusCodeData->InfoCode.PreviousInfoVal[ByteCount])
+			{
+				tmp=ShmStatusCodeData->InfoCode.InfoEvents.InfoVal[ByteCount]; //prevent be modified during following process
+				for(BitCount=0;BitCount<8;BitCount++)
+				{
+					if(((tmp>>BitCount)&0x01) != ((ShmStatusCodeData->InfoCode.PreviousInfoVal[ByteCount]>>BitCount)&0x01))
+					{
+						memset(EventCodeTmp,0,sizeof(EventCodeTmp));
+						memcpy(EventCodeTmp,InfoStatusCode[ByteCount*8+BitCount],sizeof(EventCodeTmp)-1);
+						if(((tmp>>BitCount)&0x01)==0)//Recovered
+						{
+							//EventCodeTmp[0]=1;
+							DEBUG_INFO("Recovery Info Code = %s\n", EventCodeTmp);
+							ShmStatusCodeData->InfoCode.PreviousInfoVal[ByteCount] &= ~(1<<BitCount);
+							RemoveFaultCodeToBuf(EventCodeTmp);
+						}
+						else
+						{
+							DEBUG_INFO("Info Code = %s\n", EventCodeTmp);
+							ShmStatusCodeData->InfoCode.PreviousInfoVal[ByteCount] |= (1<<BitCount);
+							AddFaultCodeToBuf(EventCodeTmp);
+						}
+					}
+				}
+			}
+		}
+		usleep(500000);
+	}
+
+	return FAIL;
+}

BIN
EVSE/Projects/PlugIt360/Apps/Module_InternalComm


+ 1498 - 0
EVSE/Projects/PlugIt360/Apps/Module_InternalComm.c

@@ -0,0 +1,1498 @@
+#include 	<sys/time.h>
+#include 	<sys/timeb.h>
+#include    <sys/types.h>
+#include    <sys/stat.h>
+#include 	<sys/types.h>
+#include 	<sys/ioctl.h>
+#include 	<sys/socket.h>
+#include 	<sys/ipc.h>
+#include 	<sys/shm.h>
+#include 	<sys/shm.h>
+#include 	<sys/mman.h>
+#include 	<linux/wireless.h>
+#include 	<arpa/inet.h>
+#include 	<netinet/in.h>
+
+#include 	<unistd.h>
+#include 	<stdarg.h>
+#include    <stdio.h>      /*標準輸入輸出定義*/
+#include    <stdlib.h>     /*標準函數庫定義*/
+#include    <unistd.h>     /*Unix 標準函數定義*/
+#include    <fcntl.h>      /*檔控制定義*/
+#include    <termios.h>    /*PPSIX 終端控制定義*/
+#include    <errno.h>      /*錯誤號定義*/
+#include 	<errno.h>
+#include 	<string.h>
+#include	<time.h>
+#include	<ctype.h>
+#include 	<ifaddrs.h>
+#include 	<math.h>
+#include	"../../define.h"
+#include	"internalComm.h"
+#include 	<stdbool.h>
+
+#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
+#define PASS				1
+#define FAIL				-1
+#define YES					1
+#define NO					0
+#define TEN_MINUTES			600
+
+struct SysConfigAndInfo			*ShmSysConfigAndInfo;
+struct StatusCodeData 			*ShmStatusCodeData;
+struct FanModuleData			*ShmFanModuleData;
+struct RelayModuleData			*ShmRelayModuleData;
+struct CHAdeMOData				*ShmCHAdeMOData;
+struct CcsData					*ShmCcsData;
+
+#define VIN_MAX_VOLTAGE		250	// 大於該值 : OVP
+#define VIN_MIN_VOLTAGE		170	// 小於該值 : UVP
+#define VIN_DROP_VOLTAGE	150	// 小於該值 : ac drop
+
+#define VOUT_MAX_VOLTAGE	750
+#define VOUT_MIN_VOLTAGE	150
+#define IOUT_MAX_CURRENT	50
+
+#define MAX_FAN_SPEED		13500
+#define MIN_FAN_SPEED		2800
+
+// GFD Status
+#define GFD_IDLE			0
+#define GFD_CABLECHK		1
+#define GFD_PRECHARGE		2
+#define GFD_CHARGING		3
+
+// 最小切換 Relay 電壓
+#define SELF_TO_CHANGE_RELAY_STATUS			600
+// 透過電壓確認 Relay 是否搭上的依據電壓
+#define CHECK_RELAY_STATUS					300
+#define CHECK_RELAY_STATUS_GAP				100
+// 安全在停止充電程序中斷開 Relay 的電流
+#define SEFETY_SWITCH_RELAY_CUR				20
+// 確認 Relay Welding 電壓
+#define RELAY_WELDING_DET					300
+
+byte gunCount = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
+// 槍資訊
+struct ChargingInfoData *_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+byte gfdChkFailCount[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+
+bool _isOutputNoneMatch[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+struct timeval _checkOutputNoneMatchTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+
+bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData);
+
+int Uart5Fd;
+char *relayRs485PortName = "/dev/ttyS5";
+unsigned short fanSpeedSmoothValue = 1000;
+
+bool isStopChargingCount = false;
+bool isSystemBooting = false;
+struct timeval _close_ac_contactor;
+
+struct timeval _priority_time;
+
+Ver ver;
+PresentInputVoltage inputVoltage;
+PresentOutputVoltage outputVoltage;
+FanSpeed fanSpeed;
+Temperature temperature;
+AuxPower auxPower;
+Gfd gfd_adc;
+Gfd_config gfd_config;
+Gpio_in gpio_in;
+Gpio_out gpio_out;
+Relay outputRelay;
+Relay regRelay;
+Rtc rtc;
+
+void PRINTF_FUNC(char *string, ...);
+
+int StoreLogMsg(const char *fmt, ...);
+unsigned long GetTimeoutValue(struct timeval _sour_time);
+
+#define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+
+unsigned long GetTimeoutValue(struct timeval _sour_time)
+{
+	struct timeval _end_time;
+	gettimeofday(&_end_time, NULL);
+
+	return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
+}
+
+int StoreLogMsg(const char *fmt, ...)
+{
+	char Buf[4096+256];
+	char buffer[4096];
+	time_t CurrentTime;
+	struct tm *tm;
+	va_list args;
+
+	va_start(args, fmt);
+	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
+	va_end(args);
+
+	memset(Buf,0,sizeof(Buf));
+	CurrentTime = time(NULL);
+	tm=localtime(&CurrentTime);
+	sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
+			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
+			buffer,
+			tm->tm_year+1900,tm->tm_mon+1);
+	system(Buf);
+
+	return rc;
+}
+
+int DiffTimeb(struct timeb ST, struct timeb ET)
+{
+	//return milli-second
+	unsigned int StartTime,StopTime;
+
+	StartTime=(unsigned int)ST.time;
+	StopTime=(unsigned int)ET.time;
+	return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
+}
+
+unsigned short MaxValue(unsigned short value1, unsigned short value2)
+{
+	return value1 >= value2 ? value1 : value2;
+}
+
+void PRINTF_FUNC(char *string, ...)
+{
+	if (DEBUG)
+	{
+		va_list args;
+		char buffer[4096];
+
+		va_start(args, string);
+		vsnprintf(buffer, sizeof(buffer), string, args);
+		va_end(args);
+		printf("%s \n", buffer);
+	}
+}
+
+//==========================================
+// Communication Function
+//==========================================
+void GetFwAndHwVersion_Fan()
+{
+	if(Query_FW_Ver(Uart5Fd, Addr.Fan, &ver) == PASS)
+	{
+		// FanModuleData
+		strcpy((char *) ShmFanModuleData->version, ver.Version_FW);
+		// SystemInfo
+		strcpy((char *) ShmSysConfigAndInfo->SysInfo.FanModuleFwRev, ver.Version_FW);
+		//PRINTF_FUNC("GetFwAndHwVersion_Fan s1 = %s \n", ver.Version_FW);
+	}
+
+	if (Query_HW_Ver(Uart5Fd, Addr.Fan, &ver) == PASS)
+	{
+		// SystemInfo
+		strcpy((char *) ShmSysConfigAndInfo->SysInfo.FanModuleHwRev, ver.Version_FW);
+		//PRINTF_FUNC("GetFwAndHwVersion_Fan s2 = %s \n", ver.Version_HW);
+	}
+}
+
+void GetFwAndHwVersion_Relay()
+{
+	if (Query_FW_Ver(Uart5Fd, Addr.Relay, &ver) == PASS)
+	{
+		// FanModuleData
+		strcpy((char *) ShmRelayModuleData->version, ver.Version_FW);
+		// SystemInfo
+		strcpy((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev, ver.Version_FW);
+		//PRINTF_FUNC("GetFwAndHwVersion_Relay s1 = %s \n", ver.Version_FW);
+	}
+
+	if (Query_HW_Ver(Uart5Fd, Addr.Relay, &ver) == PASS)
+	{
+		// SystemInfo
+		strcpy((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleHwRev, ver.Version_FW);
+		//PRINTF_FUNC("GetFwAndHwVersion_Relay s2 = %s \n", ver.Version_HW);
+	}
+}
+
+void SetRtcData_Relay()
+{
+	struct timeb csuTime;
+	struct tm *tmCSU;
+
+	ftime(&csuTime);
+	tmCSU = localtime(&csuTime.time);
+	//	PRINTF_FUNC("Time : %04d-%02d-%02d %02d:%02d:%02d \n", tmCSU->tm_year + 1900,
+	//			tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
+	//			tmCSU->tm_sec);
+
+	rtc.RtcData[0] = '0' + (tmCSU->tm_year + 1900) / 1000 % 10;
+	rtc.RtcData[1] = '0' + (tmCSU->tm_year + 1900) / 100 % 10;
+	rtc.RtcData[2] = '0' + (tmCSU->tm_year + 1900) / 10 % 10;
+	rtc.RtcData[3] = '0' + (tmCSU->tm_year + 1900) / 1 % 10;
+
+	rtc.RtcData[4] = '0' + (tmCSU->tm_mon + 1) / 10 % 10;
+	rtc.RtcData[5] = '0' + (tmCSU->tm_mon + 1) / 1 % 10;
+
+	rtc.RtcData[6] = '0' + (tmCSU->tm_mday) / 10 % 10;
+	rtc.RtcData[7] = '0' + (tmCSU->tm_mday) / 1 % 10;
+
+	rtc.RtcData[8] = '0' + (tmCSU->tm_hour) / 10 % 10;
+	rtc.RtcData[9] = '0' + (tmCSU->tm_hour) / 1 % 10;
+
+	rtc.RtcData[10] = '0' + (tmCSU->tm_min) / 10 % 10;
+	rtc.RtcData[11] = '0' + (tmCSU->tm_min) / 1 % 10;
+
+	rtc.RtcData[12] = '0' + (tmCSU->tm_sec) / 10 % 10;
+	rtc.RtcData[13] = '0' + (tmCSU->tm_sec) / 1 % 10;
+
+	if (Config_Rtc_Data(Uart5Fd, Addr.Relay, &rtc) == PASS)
+	{
+		//PRINTF_FUNC("SetRtc (RB) sucessfully. \n");
+	}
+}
+
+void SetRtcData_Fan()
+{
+	struct timeb csuTime;
+	struct tm *tmCSU;
+
+	ftime(&csuTime);
+	tmCSU = localtime(&csuTime.time);
+	//	PRINTF_FUNC("Time : %04d-%02d-%02d %02d:%02d:%02d \n", tmCSU->tm_year + 1900,
+	//			tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
+	//			tmCSU->tm_sec);
+
+	rtc.RtcData[0] = '0' + (tmCSU->tm_year + 1900) / 1000 % 10;
+	rtc.RtcData[1] = '0' + (tmCSU->tm_year + 1900) / 100 % 10;
+	rtc.RtcData[2] = '0' + (tmCSU->tm_year + 1900) / 10 % 10;
+	rtc.RtcData[3] = '0' + (tmCSU->tm_year + 1900) / 1 % 10;
+
+	rtc.RtcData[4] = '0' + (tmCSU->tm_mon + 1) / 10 % 10;
+	rtc.RtcData[5] = '0' + (tmCSU->tm_mon + 1) / 1 % 10;
+
+	rtc.RtcData[6] = '0' + (tmCSU->tm_mday) / 10 % 10;
+	rtc.RtcData[7] = '0' + (tmCSU->tm_mday) / 1 % 10;
+
+	rtc.RtcData[8] = '0' + (tmCSU->tm_hour) / 10 % 10;
+	rtc.RtcData[9] = '0' + (tmCSU->tm_hour) / 1 % 10;
+
+	rtc.RtcData[10] = '0' + (tmCSU->tm_min) / 10 % 10;
+	rtc.RtcData[11] = '0' + (tmCSU->tm_min) / 1 % 10;
+
+	rtc.RtcData[12] = '0' + (tmCSU->tm_sec) / 10 % 10;
+	rtc.RtcData[13] = '0' + (tmCSU->tm_sec) / 1 % 10;
+
+	if (Config_Rtc_Data(Uart5Fd, Addr.Fan, &rtc) == PASS)
+	{
+		//PRINTF_FUNC("SetRtc (FB) sucessfully. \n");
+	}
+}
+
+void SetModelName_Fan()
+{
+	if (Config_Model_Name(Uart5Fd, Addr.Fan, ShmSysConfigAndInfo->SysConfig.ModelName) == PASS)
+	{
+		PRINTF_FUNC("Set Model name PASS = %s \n", ShmSysConfigAndInfo->SysConfig.ModelName);
+	}
+}
+
+// AC 三相輸入電壓
+void GetPresentInputVol()
+{
+	if (Query_Present_InputVoltage(Uart5Fd, Addr.Relay, &inputVoltage) == PASS)
+	{
+		// resolution : 0.1
+		//PRINTF_FUNC("InputVoltageR = %f \n", inputVoltage.L1N_L12);
+		//PRINTF_FUNC("InputVoltageS = %f \n", inputVoltage.L2N_L23);
+		//PRINTF_FUNC("InputVoltageT = %f \n", inputVoltage.L3N_L31);
+
+		ShmRelayModuleData->InputL1Volt = inputVoltage.L1N_L12;
+		ShmRelayModuleData->InputL2Volt = inputVoltage.L2N_L23;
+		ShmRelayModuleData->InputL3Volt = inputVoltage.L3N_L31;
+
+		//********************************************************************************************************//
+		// VIN < 170
+		if (inputVoltage.L1N_L12 < VIN_MIN_VOLTAGE)
+		{
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = 0x01;
+		}
+		if (inputVoltage.L2N_L23 < VIN_MIN_VOLTAGE)
+		{
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = 0x01;
+		}
+		if (inputVoltage.L3N_L31 < VIN_MIN_VOLTAGE)
+		{
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = 0x01;
+		}
+
+		//********************************************************************************************************//
+		// VIN > 250
+		if (inputVoltage.L1N_L12 > VIN_MAX_VOLTAGE)
+		{
+			//ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = 0x01;
+		}
+		if (inputVoltage.L2N_L23 > VIN_MAX_VOLTAGE)
+		{
+			//ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = 0x01;
+		}
+		if (inputVoltage.L3N_L31 > VIN_MAX_VOLTAGE)
+		{
+			//ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = 0x01;
+		}
+		//********************************************************************************************************//
+		// VIN < 150
+		if (inputVoltage.L1N_L12 < VIN_DROP_VOLTAGE)
+		{
+			//ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputDrop = 0x01;
+		}
+		if (inputVoltage.L2N_L23 < VIN_DROP_VOLTAGE)
+		{
+			//ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputDrop = 0x01;
+		}
+		if (inputVoltage.L3N_L31 < VIN_DROP_VOLTAGE)
+		{
+			//ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputDrop = 0x01;
+		}
+
+		//********************************************************************************************************//
+		// 150 <= VIN < 160
+//		if (inputVoltage.L1N_L12 >= VIN_MIN_VOLTAGE && inputVoltage.L1N_L12 <= VIN_LOW_VOLTAGE)
+//		{
+//			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = 0x00;
+//			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = 0x00;
+//			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputDrop = 0x00;
+//		}
+//		if (inputVoltage.L2N_L23 >= VIN_MIN_VOLTAGE && inputVoltage.L2N_L23 <= VIN_LOW_VOLTAGE)
+//		{
+//			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = 0x00;
+//			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = 0x00;
+//			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputDrop = 0x00;
+//		}
+//		if (inputVoltage.L3N_L31 >= VIN_MIN_VOLTAGE && inputVoltage.L3N_L31 <= VIN_LOW_VOLTAGE)
+//		{
+//			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = 0x00;
+//			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = 0x00;
+//			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputDrop = 0x00;
+//		}
+	}
+}
+
+// 左右槍的 Relay 前後的輸出電壓
+void GetPersentOutputVol()
+{
+	if (Query_Present_OutputVoltage(Uart5Fd, Addr.Relay, &outputVoltage) == PASS)
+	{
+//		PRINTF_FUNC("Conn1 fuse 1 = %f \n", outputVoltage.behindFuse_Voltage_C1);
+//		PRINTF_FUNC("Conn1 relay 1 = %f \n", outputVoltage.behindRelay_Voltage_C1);
+//		PRINTF_FUNC("Conn2 fuse 2 = %f \n", outputVoltage.behindFuse_Voltage_C2);
+//		PRINTF_FUNC("Conn2 relay 2 = %f \n", outputVoltage.behindRelay_Voltage_C2);
+
+		//PRINTF_FUNC("outputVoltage.behindFuse_Voltage_C1 = %f \n", outputVoltage.behindFuse_Voltage_C1);
+		//PRINTF_FUNC("outputVoltage.behindFuse_Voltage_C2 = %f \n", outputVoltage.behindFuse_Voltage_C2);
+
+		ShmRelayModuleData->Gun1FuseOutputVolt = outputVoltage.behindFuse_Voltage_C1;
+		ShmRelayModuleData->Gun1RelayOutputVolt = outputVoltage.behindRelay_Voltage_C1;
+		ShmRelayModuleData->Gun2FuseOutputVolt = outputVoltage.behindFuse_Voltage_C2;
+		ShmRelayModuleData->Gun2RelayOutputVolt = outputVoltage.behindRelay_Voltage_C2;
+
+		for (int index = 0; index < gunCount; index++)
+		{
+			if (index == 0)
+			{
+				if (_chargingData[index]->Evboard_id == 0x01)
+				{
+					_chargingData[index]->FuseChargingVoltage = ShmRelayModuleData->Gun1FuseOutputVolt;
+					_chargingData[index]->FireChargingVoltage = ShmRelayModuleData->Gun1RelayOutputVolt;
+				}
+				else if (_chargingData[index]->Evboard_id == 0x02)
+				{
+					_chargingData[index]->FuseChargingVoltage = ShmRelayModuleData->Gun2FuseOutputVolt;
+					_chargingData[index]->FireChargingVoltage = ShmRelayModuleData->Gun2RelayOutputVolt;
+				}
+			}
+			else if (index == 1)
+			{
+				_chargingData[index]->FuseChargingVoltage = ShmRelayModuleData->Gun2FuseOutputVolt;
+				_chargingData[index]->FireChargingVoltage = ShmRelayModuleData->Gun2RelayOutputVolt;
+			}
+
+			unsigned short Ovp = 0;
+			unsigned short Ocp = 0;
+			//Ovp = MIN [VOUT_MAX_VOLTAGE, EV_BATTERY_VOLTAGE] 	// 最大輸出電壓與電池電壓最大值
+			//Ocp = MIN [IOUT_MAX_CURRENT, EV_CURRENT_REQ]		// 最大輸出電流與需求電流最小值
+			if (_chargingData[index]->Type == _Type_Chademo)
+			{
+				Ovp = MaxValue(_chargingData[index]->MaximumChargingVoltage, _chargingData[index]->EvBatteryMaxVoltage);
+				Ocp = MaxValue(_chargingData[index]->PresentChargingCurrent, ShmCHAdeMOData->ev[_chargingData[index]->type_index].ChargingCurrentRequest);
+				if (_chargingData[index]->PresentChargingVoltage >= Ovp)
+				{
+					//ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOVP = 0x01;
+				}
+				if (_chargingData[index]->PresentChargingCurrent >= Ocp)
+				{
+					//ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOCP = 0x01;
+				}
+			}
+			else if (_chargingData[index]->Type == _Type_CCS_2)
+			{
+
+			}
+		}
+	}
+}
+
+// 風扇速度
+void GetFanSpeed()
+{
+	//PRINTF_FUNC("Get fan board speed \n");
+	if (Query_Fan_Speed(Uart5Fd, Addr.Fan, &fanSpeed) == PASS)
+	{
+		ShmFanModuleData->PresentFan1Speed = fanSpeed.speed[0];
+		ShmFanModuleData->PresentFan2Speed = fanSpeed.speed[1];
+		ShmFanModuleData->PresentFan3Speed = fanSpeed.speed[2];
+		ShmFanModuleData->PresentFan4Speed = fanSpeed.speed[3];
+//		PRINTF_FUNC("SystemFanRotaSpeed_1 = %d \n", fanSpeed.speed[0]);
+//		PRINTF_FUNC("SystemFanRotaSpeed_2 = %d \n", fanSpeed.speed[1]);
+//		PRINTF_FUNC("SystemFanRotaSpeed_3 = %d \n", fanSpeed.speed[2]);
+//		PRINTF_FUNC("SystemFanRotaSpeed_4 = %d \n", fanSpeed.speed[3]);
+		// Config_Fan_Speed(Uart5Fd, Addr.Fan, &fanSpeed[0]);
+		//SysInfoData (SystemFanRotaSpeed)
+	}
+}
+
+// 讀取 Relay 狀態
+void GetRelayOutputStatus()
+{
+	if (Query_Relay_Output(Uart5Fd, Addr.Relay, &regRelay) == PASS)
+	{
+		regRelay.relay_event.bits.AC_Contactor = ShmSysConfigAndInfo->SysInfo.AcContactorStatus;
+	}
+}
+
+// 確認 K1 K2 relay 的狀態
+void CheckK1K2RelayOutput(byte index)
+{
+	if (index == 0)
+	{
+		if (_chargingData[index]->Evboard_id == 0x01)
+		{
+			if (regRelay.relay_event.bits.Gun1_N == YES && regRelay.relay_event.bits.Gun1_P == YES)
+				_chargingData[index]->RelayK1K2Status = YES;
+			else
+				_chargingData[index]->RelayK1K2Status = NO;
+
+			if(_chargingData[index]->Type == _Type_CCS_2)
+			{
+				if (regRelay.relay_event.bits.Gun1_N == YES	&& regRelay.relay_event.bits.CCS_Precharge == YES)
+					_chargingData[index]->RelayKPK2Status = YES;
+				else
+					_chargingData[index]->RelayKPK2Status = NO;
+			}
+		}
+		else if (_chargingData[index]->Evboard_id == 0x02)
+		{
+			if (regRelay.relay_event.bits.Gun2_N == YES && regRelay.relay_event.bits.Gun2_P == YES)
+				_chargingData[index]->RelayK1K2Status = YES;
+			else
+				_chargingData[index]->RelayK1K2Status = NO;
+
+			if(_chargingData[index]->Type == _Type_CCS_2)
+			{
+				if (regRelay.relay_event.bits.Gun2_N == YES	&& regRelay.relay_event.bits.CCS_Precharge == YES)
+					_chargingData[index]->RelayKPK2Status = YES;
+				else
+					_chargingData[index]->RelayKPK2Status = NO;
+			}
+
+		}
+	}
+	else if (index == 1)
+	{
+		if (regRelay.relay_event.bits.Gun2_N == YES && regRelay.relay_event.bits.Gun2_P == YES)
+			_chargingData[index]->RelayK1K2Status = YES;
+		else
+			_chargingData[index]->RelayK1K2Status = NO;
+
+		if(_chargingData[index]->Type == _Type_CCS_2)
+		{
+			if (regRelay.relay_event.bits.Gun2_N == YES && regRelay.relay_event.bits.CCS_Precharge == YES)
+				_chargingData[index]->RelayKPK2Status = YES;
+			else
+				_chargingData[index]->RelayKPK2Status = NO;
+		}
+	}
+
+	if (regRelay.relay_event.bits.Gun1_Parallel_N == YES && regRelay.relay_event.bits.Gun1_Parallel_P == YES)
+		ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus = YES;
+	else
+		ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus = NO;
+}
+
+void GetGfdAdc()
+{
+	// define : 每 0.2 ~ 1 秒一次
+	// occur : <= 75k 歐姆 @ 150 - 750 Vdc
+	// warning : >= 100 歐姆 && <= 500 歐姆 @ 150-750 Vdc
+	if (Query_Gfd_Adc(Uart5Fd, Addr.Relay, &gfd_adc) == PASS)
+	{
+		for (int i = 0; i < gunCount; i++)
+		{
+			if (i == 0)
+			{
+				_chargingData[i]->GroundFaultStatus = gfd_adc.result_conn1;
+				if (_chargingData[i]->GroundFaultStatus == GFD_FAIL)
+				{
+					DEBUG_ERROR("GFD Fail. index = %d, R = %d, Vol = %d \n",
+							i, gfd_adc.Resister_conn1, gfd_adc.voltage_conn1);
+				}
+			}
+			else if (i == 1)
+			{
+				_chargingData[i]->GroundFaultStatus = gfd_adc.result_conn2;
+				if (_chargingData[i]->GroundFaultStatus == GFD_FAIL)
+				{
+					DEBUG_ERROR("GFD Fail. index = %d, R = %d, Vol = %d \n",
+							i, gfd_adc.Resister_conn2, gfd_adc.voltage_conn2);
+				}
+			}
+		}
+
+		//if (gfd_adc.result_conn1 != 0)
+		{
+//			PRINTF_FUNC("******************Resister_conn1 = %d, voltage_conn1 = %d, result_conn1 = %d, step = %d \n",
+//				gfd_adc.Resister_conn1,
+//				gfd_adc.voltage_conn1,
+//				gfd_adc.result_conn1,
+//				gfd_adc.rb_step_1);
+		}
+	}
+}
+
+void GetGpioInput()
+{
+	if (Query_Gpio_Input(Uart5Fd, Addr.Aux, &gpio_in) == PASS)
+	{
+		// AC Contactor Status
+		if (gpio_in.AC_MainBreaker == 1)
+		{
+			// AC Main Breaker ON
+			PRINTF_FUNC("RB AC Main Breaker. \n");
+		}
+
+		if (gpio_in.SPD == 1)
+		{
+			// SPD (雷擊保護) ON
+			PRINTF_FUNC("RB SPD. \n");
+		}
+
+		if (gpio_in.Door_Open == 1)
+		{
+			// Door Open
+			PRINTF_FUNC("RB Door Open. \n");
+		}
+
+		if (gpio_in.GFD[0] == 1)
+		{
+			// GFD_1 Trigger
+		}
+
+		if (gpio_in.GFD[1] == 1)
+		{
+			// GFD_2 Trigger
+		}
+
+		if (gpio_in.AC_Drop == 1)
+		{
+			// AC Drop
+			PRINTF_FUNC("RB AC Drop. \n");
+		}
+
+		if (gpio_in.Emergency_IO == 1)
+		{
+			// Emergency IO ON
+			PRINTF_FUNC("RB Emergency IO ON. \n");
+		}
+
+		if (gpio_in.Button_Emergency_Press == 1)
+		{
+			// Emergency button Press
+		}
+
+		if (gpio_in.Button_On_Press == 1)
+		{
+			// On button Press
+		}
+
+		if (gpio_in.Button_Off_Press == 1)
+		{
+			// Off button Press
+		}
+
+		if (gpio_in.Key_1_Press == 1)
+		{
+			// key 1 press
+		}
+
+		if (gpio_in.Key_2_Press == 1)
+		{
+			// key 2 press
+		}
+
+		if (gpio_in.Key_3_Press == 1)
+		{
+			// key 3 press
+		}
+
+		if (gpio_in.Key_4_Press == 1)
+		{
+			// key 4 press
+		}
+	}
+}
+
+// 5V 12V 24V 48V
+void GetAuxPower()
+{
+	if (Query_Aux_PowerVoltage(Uart5Fd, Addr.Fan, &auxPower) == PASS)
+	{
+		ShmSysConfigAndInfo->SysInfo.AuxPower48V = auxPower.voltage[0];
+		ShmSysConfigAndInfo->SysInfo.AuxPower24V = auxPower.voltage[1];
+		//ShmSysConfigAndInfo->SysInfo.AuxPower12V = auxPower.voltage[4];
+		//ShmSysConfigAndInfo->SysInfo.AuxPower5V = auxPower.voltage[6];
+		// aux power voltage
+		//PRINTF_FUNC("aux1 = %x, \n", auxPower.voltage[0]);
+		//PRINTF_FUNC("aux2 = %x, \n", auxPower.voltage[1]);
+	}
+}
+
+void SetFanModuleSpeed()
+{
+	// 調整風扇速度要漸進式 : 500 rpm/p
+	if (ShmFanModuleData->PresentFan1Speed != ShmFanModuleData->SetFan1Speed ||
+			ShmFanModuleData->PresentFan2Speed != ShmFanModuleData->SetFan2Speed ||
+			ShmFanModuleData->PresentFan3Speed != ShmFanModuleData->SetFan3Speed ||
+			ShmFanModuleData->PresentFan4Speed != ShmFanModuleData->SetFan4Speed)
+	{
+		FanSpeed _fanSpeed;
+
+		unsigned short speed = ShmFanModuleData->PresentFan1Speed + fanSpeedSmoothValue;
+		if (speed >= ShmFanModuleData->SetFan1Speed)
+			speed = ShmFanModuleData->SetFan1Speed;
+		_fanSpeed.speed[0] = speed;
+
+		speed = ShmFanModuleData->PresentFan2Speed + fanSpeedSmoothValue;
+		if (speed >= ShmFanModuleData->SetFan2Speed)
+			speed = ShmFanModuleData->SetFan2Speed;
+		_fanSpeed.speed[1] = speed;
+
+		speed = ShmFanModuleData->PresentFan3Speed + fanSpeedSmoothValue;
+		if (speed >= ShmFanModuleData->SetFan3Speed)
+			speed = ShmFanModuleData->SetFan3Speed;
+		_fanSpeed.speed[2] = speed;
+
+		speed = ShmFanModuleData->PresentFan4Speed + fanSpeedSmoothValue;
+		if (speed >= ShmFanModuleData->SetFan4Speed)
+			speed = ShmFanModuleData->SetFan4Speed;
+		_fanSpeed.speed[3] = speed;
+
+		if (Config_Fan_Speed(Uart5Fd, Addr.Fan, &_fanSpeed) == PASS)
+		{
+			//PRINTF_FUNC("successfully Fan\n");
+		}
+	}
+}
+
+void SetRelayModuleFanSpeed()
+{
+	// 調整風扇速度要漸進式 : 100 rpm/p
+	if (ShmFanModuleData->PresentFan1Speed != ShmFanModuleData->SetFan1Speed)
+	{
+		FanSpeed _fanSpeed;
+		unsigned short speed = 0;
+
+		if (ShmFanModuleData->SetFan1Speed > ShmFanModuleData->PresentFan1Speed)
+		{
+			speed = ShmFanModuleData->PresentFan1Speed + fanSpeedSmoothValue;
+			if (speed >= ShmFanModuleData->SetFan1Speed)
+				speed = ShmFanModuleData->SetFan1Speed;
+		}
+		else
+		{
+			speed = ShmFanModuleData->PresentFan1Speed - fanSpeedSmoothValue;
+			if (speed <= 0)
+				speed = ShmFanModuleData->SetFan1Speed;
+		}
+
+		_fanSpeed.speed[0] = speed & 0xff;
+		_fanSpeed.speed[1] = (speed >> 8) & 0xff;
+		ShmFanModuleData->PresentFan1Speed = speed;
+
+		Config_Fan_Speed(Uart5Fd, Addr.Relay, &_fanSpeed);
+	}
+}
+
+void GetRelayModuleFanSpeed()
+{
+	PRINTF_FUNC("Get fan board speed \n");
+	if (Query_Fan_Speed(Uart5Fd, Addr.Relay, &fanSpeed) == PASS)
+	{
+		ShmFanModuleData->PresentFan1Speed = fanSpeed.speed[0] + (fanSpeed.speed[1] >> 8);
+		PRINTF_FUNC("SystemFanRotaSpeed_1 = %d \n", fanSpeed.speed[0]);
+	}
+}
+
+//==========================================
+// Common Function
+//==========================================
+void SetK1K2RelayStatus(byte index)
+{
+	if (_chargingData[index]->SystemStatus < S_PREPARING_FOR_EVSE)
+	{
+		if (_chargingData[index]->Evboard_id == 0x01)
+		{
+			if(regRelay.relay_event.bits.Gun1_P == YES)
+				outputRelay.relay_event.bits.Gun1_P = NO;
+			else if (regRelay.relay_event.bits.Gun1_N == YES)
+				outputRelay.relay_event.bits.Gun1_N = NO;
+
+			if (_chargingData[index]->Type == _Type_CCS_2)
+			{
+				if(regRelay.relay_event.bits.CCS_Precharge == YES)
+					outputRelay.relay_event.bits.CCS_Precharge = NO;
+			}
+		}
+		else if (_chargingData[index]->Evboard_id == 0x02)
+		{
+			if(regRelay.relay_event.bits.Gun2_P == YES)
+				outputRelay.relay_event.bits.Gun2_P = NO;
+			else if (regRelay.relay_event.bits.Gun2_N == YES)
+				outputRelay.relay_event.bits.Gun2_N = NO;
+
+			if (_chargingData[index]->Type == _Type_CCS_2)
+			{
+				if(regRelay.relay_event.bits.CCS_Precharge == YES)
+					outputRelay.relay_event.bits.CCS_Precharge = NO;
+			}
+		}
+	}
+	else if ((_chargingData[index]->SystemStatus >= S_PREPARING_FOR_EVSE && _chargingData[index]->SystemStatus <= S_CHARGING))
+	{
+		if (_chargingData[index]->Evboard_id == 0x01)
+		{
+			if(regRelay.relay_event.bits.Gun1_N == NO)
+				outputRelay.relay_event.bits.Gun1_N = YES;
+			else if (regRelay.relay_event.bits.Gun1_P == NO)
+				outputRelay.relay_event.bits.Gun1_P = YES;
+		}
+		else if (_chargingData[index]->Evboard_id == 0x02)
+		{
+			if(regRelay.relay_event.bits.Gun2_N == NO)
+				outputRelay.relay_event.bits.Gun2_N = YES;
+			else if (regRelay.relay_event.bits.Gun2_P == NO)
+				outputRelay.relay_event.bits.Gun2_P = YES;
+		}
+	}
+	else if (_chargingData[index]->SystemStatus == S_COMPLETE)
+	{
+		if (_chargingData[index]->PresentChargingCurrent <= SEFETY_SWITCH_RELAY_CUR)
+		{
+			if (_chargingData[index]->Evboard_id == 0x01)
+			{
+				if(regRelay.relay_event.bits.Gun1_P == YES)
+					outputRelay.relay_event.bits.Gun1_P = NO;
+				else if (regRelay.relay_event.bits.Gun1_N == YES)
+					outputRelay.relay_event.bits.Gun1_N = NO;
+			}
+			else if (_chargingData[index]->Evboard_id == 0x02)
+			{
+				if(regRelay.relay_event.bits.Gun2_P == YES)
+					outputRelay.relay_event.bits.Gun2_P = NO;
+				else if (regRelay.relay_event.bits.Gun2_N == YES)
+					outputRelay.relay_event.bits.Gun2_N = NO;
+			}
+		}
+	}
+	else if (_chargingData[index]->SystemStatus == S_CCS_PRECHARGE_ST0)
+	{
+		if (_chargingData[index]->Evboard_id == 0x01)
+		{
+			if (_chargingData[index]->Type == _Type_CCS_2)
+			{
+				if (regRelay.relay_event.bits.CCS_Precharge == NO)
+					outputRelay.relay_event.bits.CCS_Precharge = YES;
+				else if (regRelay.relay_event.bits.CCS_Precharge == YES)
+					outputRelay.relay_event.bits.Gun1_P = NO;
+			}
+		}
+		else if (_chargingData[index]->Evboard_id == 0x02)
+		{
+			if (_chargingData[index]->Type == _Type_CCS_2)
+			{
+				if (regRelay.relay_event.bits.CCS_Precharge == NO)
+					outputRelay.relay_event.bits.CCS_Precharge = YES;
+				else if (regRelay.relay_event.bits.CCS_Precharge == YES)
+					outputRelay.relay_event.bits.Gun2_P = NO;
+			}
+		}
+	}
+	else if (_chargingData[index]->SystemStatus == S_CCS_PRECHARGE_ST1)
+	{
+		if (_chargingData[index]->Evboard_id == 0x01)
+		{
+			if (_chargingData[index]->Type == _Type_CCS_2)
+			{
+				if (regRelay.relay_event.bits.Gun1_P == NO)
+					outputRelay.relay_event.bits.Gun1_P = YES;
+				else if(regRelay.relay_event.bits.Gun1_P == YES)
+					outputRelay.relay_event.bits.CCS_Precharge = NO;
+			}
+		}
+		else if (_chargingData[index]->Evboard_id == 0x02)
+		{
+			if (_chargingData[index]->Type == _Type_CCS_2)
+			{
+				if (regRelay.relay_event.bits.Gun2_P == NO)
+					outputRelay.relay_event.bits.Gun2_P = YES;
+				else if(regRelay.relay_event.bits.Gun2_P == YES)
+					outputRelay.relay_event.bits.CCS_Precharge = NO;
+			}
+		}
+	}
+}
+
+void SetParalleRelayStatus()
+{
+	if (gunCount >= 2 && ONE_CONNECTOR_USE == NO)
+	{
+		if (_chargingData[0]->SystemStatus == S_BOOTING || _chargingData[1]->SystemStatus == S_BOOTING)
+		{
+			// 初始化~ 不搭橋接
+			if (regRelay.relay_event.bits.Gun1_Parallel_P == YES)
+				outputRelay.relay_event.bits.Gun1_Parallel_P = NO;
+			else if (regRelay.relay_event.bits.Gun1_Parallel_N == YES)
+				outputRelay.relay_event.bits.Gun1_Parallel_N = NO;
+		}
+		else
+		{
+			// 單槍充電中 - 搭上橋接
+			if((_chargingData[0]->IsReadyToCharging == YES && _chargingData[1]->IsReadyToCharging == NO) ||
+					(_chargingData[0]->IsReadyToCharging == NO && _chargingData[1]->IsReadyToCharging == YES))
+			{
+				if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_RELAY)
+				{
+					if (regRelay.relay_event.bits.Gun1_Parallel_P == YES)
+						outputRelay.relay_event.bits.Gun1_Parallel_P = NO;
+					else if (regRelay.relay_event.bits.Gun1_Parallel_N == YES)
+						outputRelay.relay_event.bits.Gun1_Parallel_N = NO;
+				}
+				else
+				{
+					if (regRelay.relay_event.bits.Gun1_Parallel_N == NO)
+						outputRelay.relay_event.bits.Gun1_Parallel_N = YES;
+					else if (regRelay.relay_event.bits.Gun1_Parallel_P == NO)
+						outputRelay.relay_event.bits.Gun1_Parallel_P = YES;
+				}
+			}
+			else
+			{
+				// 雙槍充電中~ 不搭橋接
+				if (regRelay.relay_event.bits.Gun1_Parallel_P == YES)
+					outputRelay.relay_event.bits.Gun1_Parallel_P = NO;
+				else if (regRelay.relay_event.bits.Gun1_Parallel_N == YES)
+					outputRelay.relay_event.bits.Gun1_Parallel_N = NO;
+			}
+		}
+	}
+}
+
+//==========================================
+// Init all share memory
+//==========================================
+int InitShareMemory()
+{
+	int result = PASS;
+	int MeterSMId;
+
+	//creat ShmSysConfigAndInfo
+	if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
+		#endif
+		result = FAIL;
+	}
+	else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("[shmat ShmSysConfigAndInfo NG\n");
+		#endif
+		result = FAIL;
+	 }
+	 //creat ShmStatusCodeData
+	if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
+		#endif
+		result = FAIL;
+	}
+	else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
+		#endif
+		result = FAIL;
+	}
+
+	//creat ShmFanModuleData
+	if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData),  0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmget ShmFanModuleData NG\n");
+		#endif
+		result = FAIL;
+	}
+	else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmat ShmFanModuleData NG\n");
+		#endif
+		result = FAIL;
+	 }
+	 memset(ShmFanModuleData,0,sizeof(struct FanModuleData));
+	 //creat ShmRelayModuleData
+	if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData),  0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmget ShmRelayModuleData NG\n");
+		#endif
+		result = FAIL;
+	}
+	else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmat ShmRelayModuleData NG\n");
+		#endif
+		result = FAIL;
+	}
+
+	if(CHAdeMO_QUANTITY > 0)
+	{
+		if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData),	IPC_CREAT | 0777)) < 0)
+		{
+			#ifdef SystemLogMessage
+			DEBUG_ERROR("[shmget ShmCHAdeMOData NG \n");
+			#endif
+			return FAIL;
+		}
+		else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0)) == (void *) -1) {
+			#ifdef SystemLogMessage
+			DEBUG_ERROR("shmat ShmCHAdeMOData NG \n");
+			#endif
+			return FAIL;
+		}
+	}
+
+	if(CCS_QUANTITY > 0)
+	{
+		if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData),	IPC_CREAT | 0777)) < 0)
+		{
+			#ifdef SystemLogMessage
+			DEBUG_ERROR("shmget ShmCcsData NG \n");
+			#endif
+			return FAIL;
+		}
+		else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+		{
+			#ifdef SystemLogMessage
+		   	DEBUG_ERROR("shmat ShmCcsData NG \n");
+			#endif
+			return FAIL;
+		}
+	}
+
+
+	return result;
+}
+
+int InitComPort()
+{
+	int fd;
+	struct termios tios;
+
+	fd = open(relayRs485PortName, O_RDWR);
+	if(fd <= 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("Module_InternalComm. InitComPort NG\n");
+		#endif
+		if(ShmStatusCodeData!=NULL)
+		{
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
+		}
+		sleep(5);
+		return -1;
+	}
+	ioctl (fd, TCGETS, &tios);
+	tios.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
+	tios.c_lflag = 0;
+	tios.c_iflag = 0;
+	tios.c_oflag = 0;
+	tios.c_cc[VMIN]=0;
+	tios.c_cc[VTIME]=(byte)0;		// timeout 0.5 second
+	tios.c_lflag=0;
+	tcflush(fd, TCIFLUSH);
+	ioctl (fd, TCSETS, &tios);
+
+	return fd;
+}
+
+//================================================
+// Main process
+//================================================
+bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
+{
+	for (byte index = 0; index < CHAdeMO_QUANTITY; index++) {
+		if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index
+				== target) {
+			chargingData[target] =
+					&ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
+			return true;
+		}
+	}
+
+	for (byte index = 0; index < CCS_QUANTITY; index++) {
+		if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index
+				== target) {
+			chargingData[target] =
+					&ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
+			return true;
+		}
+	}
+
+	for (byte index = 0; index < GB_QUANTITY; index++) {
+		if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index
+				== target) {
+			chargingData[target] =
+					&ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
+			return true;
+		}
+	}
+
+	return false;
+}
+
+void Initialization()
+{
+	bool isPass = false;
+
+	for (byte index = 0; index < ARRAY_SIZE(outputRelay.relay_event.relay_status); index++)
+	{
+		outputRelay.relay_event.relay_status[index] = 0x00;
+	}
+
+	while(!isPass)
+	{
+		isPass = true;
+		for (byte _index = 0; _index < gunCount; _index++)
+		{
+			if (!FindChargingInfoData(_index, &_chargingData[0]))
+			{
+				DEBUG_ERROR("EvComm (main) : FindChargingInfoData false \n");
+				isPass = false;
+				break;
+			}
+		}
+	}
+}
+
+bool IsNoneMatchRelayStatus()
+{
+	bool result = false;
+
+//	PRINTF_FUNC("Real Relay, AC = %x, g1_p = %x, g1_n = %x, g2_p = %x, g2_n = %x, pre = %x, bri_p = %x, bri_n = %x \n",
+//			regRelay.relay_event.bits.AC_Contactor,
+//			regRelay.relay_event.bits.Gun1_P,
+//			regRelay.relay_event.bits.Gun1_N,
+//			regRelay.relay_event.bits.Gun2_P,
+//			regRelay.relay_event.bits.Gun2_N,
+//			regRelay.relay_event.bits.CCS_Precharge,
+//			regRelay.relay_event.bits.Gun1_Parallel_P,
+//			regRelay.relay_event.bits.Gun1_Parallel_N);
+
+	if ((regRelay.relay_event.bits.AC_Contactor != outputRelay.relay_event.bits.AC_Contactor) ||
+		(regRelay.relay_event.bits.CCS_Precharge != outputRelay.relay_event.bits.CCS_Precharge) ||
+		(regRelay.relay_event.bits.Gun1_P != outputRelay.relay_event.bits.Gun1_P) ||
+		(regRelay.relay_event.bits.Gun1_N != outputRelay.relay_event.bits.Gun1_N) ||
+		(regRelay.relay_event.bits.Gun2_P != outputRelay.relay_event.bits.Gun2_P) ||
+		(regRelay.relay_event.bits.Gun2_N != outputRelay.relay_event.bits.Gun2_N) ||
+		(regRelay.relay_event.bits.Gun1_Parallel_P != outputRelay.relay_event.bits.Gun1_Parallel_P) ||
+		(regRelay.relay_event.bits.Gun1_Parallel_N != outputRelay.relay_event.bits.Gun1_Parallel_N))
+	{
+		result = true;
+	}
+
+	return result;
+}
+
+void MatchRelayStatus()
+{
+	// 因為 AC Contactor 沒有 Feedback,所以暫時先這樣處理
+	//regRelay.relay_event.bits.AC_Contactor = outputRelay.relay_event.bits.AC_Contactor;
+	ShmSysConfigAndInfo->SysInfo.AcContactorStatus  = regRelay.relay_event.bits.AC_Contactor = outputRelay.relay_event.bits.AC_Contactor;
+	regRelay.relay_event.bits.CCS_Precharge = outputRelay.relay_event.bits.CCS_Precharge;
+	regRelay.relay_event.bits.Gun1_P = outputRelay.relay_event.bits.Gun1_P;
+	regRelay.relay_event.bits.Gun1_N = outputRelay.relay_event.bits.Gun1_N;
+	regRelay.relay_event.bits.Gun2_P = outputRelay.relay_event.bits.Gun2_P;
+	regRelay.relay_event.bits.Gun2_N = outputRelay.relay_event.bits.Gun2_N;
+	regRelay.relay_event.bits.Gun1_Parallel_P = outputRelay.relay_event.bits.Gun1_Parallel_P;
+	regRelay.relay_event.bits.Gun1_Parallel_N = outputRelay.relay_event.bits.Gun1_Parallel_N;
+}
+
+void CheckRelayStatusByADC()
+{
+	if (ShmRelayModuleData->Gun1FuseOutputVolt > 0 && ShmRelayModuleData->Gun1RelayOutputVolt > 0 &&
+			(ShmRelayModuleData->Gun1FuseOutputVolt == ShmRelayModuleData->Gun1RelayOutputVolt))
+	{
+		// Relay 前後電壓一致
+		_chargingData[0]->RelayK1K2Status = 0x01;
+	}
+	else
+		_chargingData[0]->RelayK1K2Status = 0x00;
+
+	if (ShmRelayModuleData->Gun2FuseOutputVolt > 0 && ShmRelayModuleData->Gun2RelayOutputVolt > 0 &&
+				(ShmRelayModuleData->Gun2FuseOutputVolt == ShmRelayModuleData->Gun2RelayOutputVolt))
+	{
+		// Relay 前後電壓一致
+		_chargingData[1]->RelayK1K2Status = 0x01;
+	}
+	else
+		_chargingData[1]->RelayK1K2Status = 0x00;
+}
+
+void SetGfdConfig(byte index, byte resister)
+{
+	gfd_config.index = index;
+	gfd_config.state = resister;
+
+	//PRINTF_FUNC("************************GFD Vol = %d, GFD Res = %d \n", gfd_config.reqVol, gfd_config.resister);
+	if (Config_Gfd_Value(Uart5Fd, Addr.Relay, &gfd_config) == PASS)
+	{
+//		PRINTF_FUNC("Set reqVol = %f, resister = %d \n",
+//				gfd_config.reqVol,
+//				gfd_config.resister);
+	}
+}
+
+void CableCheckDetected(byte index)
+{
+	// Cable Check
+	// 當火線上的電壓 = 車端要求的電壓電流
+	// _chargingData[targetGun]->EvBatterytargetVoltage
+	// 才可以開始偵測 1s
+	// Warning : Rgfd <= 150 歐/V 假設電壓為 500V 則~ Rgfd <= 75000 歐
+	// Pre-Warning : 150 歐/V < Rgfd <= 500 歐/V 假設電壓為 500V 則 75000 歐 < Rgfd <= 250000
+	// SO Normal : Rgfd > 500 歐/V 假設電壓為 500 V 則 Rgfd > 250000 歐
+	if ((_chargingData[index]->SystemStatus >= S_PREPARING_FOR_EVSE && _chargingData[index]->SystemStatus <= S_CHARGING) ||
+			(_chargingData[index]->SystemStatus >= S_CCS_PRECHARGE_ST0 && _chargingData[index]->SystemStatus <= S_CCS_PRECHARGE_ST1))
+	{
+		if (_chargingData[index]->SystemStatus == S_PREPARING_FOR_EVSE)
+		{
+			SetGfdConfig(index, GFD_CABLECHK);
+		}
+		else if (_chargingData[index]->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
+				_chargingData[index]->SystemStatus <= S_CCS_PRECHARGE_ST1)
+		{
+			SetGfdConfig(index, GFD_PRECHARGE);
+		}
+		else if (_chargingData[index]->SystemStatus <= S_CHARGING)
+		{
+			SetGfdConfig(index, GFD_CHARGING);
+		}
+	}
+	else if(_chargingData[index]->SystemStatus == S_COMPLETE || _chargingData[index]->SystemStatus == S_PREPARNING
+			|| _chargingData[index]->SystemStatus == S_IDLE)
+	{
+		SetGfdConfig(index, GFD_IDLE);
+	}
+}
+
+void CheckOutputPowerOverCarReq(byte index)
+{
+	float fireV = _chargingData[index]->FireChargingVoltage;
+	float carV = _chargingData[index]->EvBatterytargetVoltage;
+
+	if (_chargingData[index]->EvBatterytargetVoltage > 1500 &&
+			(_chargingData[index]->Type == _Type_Chademo || _chargingData[index]->Type == _Type_CCS_2 || _chargingData[index]->Type == _Type_GB))
+	{
+		if (fireV >= (carV + (carV * 0.1)))
+		{
+			PRINTF_FUNC("[Module_InternalComm]CheckOutputPowerOverCarReq NG : fire = %f, battery = %f \n",
+					_chargingData[index]->FireChargingVoltage, _chargingData[index]->EvBatterytargetVoltage);
+			DEBUG_ERROR("[Module_InternalComm]CheckOutputPowerOverCarReq NG : fire = %f, battery = %f \n",
+					_chargingData[index]->FireChargingVoltage, _chargingData[index]->EvBatterytargetVoltage);
+			_chargingData[index]->StopChargeFlag = YES;
+		}
+	}
+}
+
+void CheckOutputVolNoneMatchFire(byte index)
+{
+	if (_chargingData[index]->EvBatterytargetVoltage > 1500 &&
+			(_chargingData[index]->Type == _Type_Chademo || _chargingData[index]->Type == _Type_CCS_2 || _chargingData[index]->Type == _Type_GB))
+	{
+		if ((_chargingData[index]->PresentChargingVoltage < _chargingData[index]->FireChargingVoltage - 300) ||
+				(_chargingData[index]->PresentChargingVoltage > _chargingData[index]->FireChargingVoltage + 300))
+		{
+			if (!_isOutputNoneMatch[index])
+			{
+				_isOutputNoneMatch[index] = YES;
+				gettimeofday(&_checkOutputNoneMatchTimer[index], NULL);
+			}
+			else
+			{
+				if ((GetTimeoutValue(_checkOutputNoneMatchTimer[index]) / 1000) >= 5000)
+				{
+					PRINTF_FUNC("[Module_InternalComm]CheckOutputVolNoneMatchFire NG : pre = %f, fire = %f \n",
+					_chargingData[index]->PresentChargingVoltage, _chargingData[index]->FireChargingVoltage);
+					DEBUG_ERROR("[Module_InternalComm]CheckOutputVolNoneMatchFire NG : pre = %f, fire = %f \n",
+					_chargingData[index]->PresentChargingVoltage, _chargingData[index]->FireChargingVoltage);
+					_chargingData[index]->StopChargeFlag = YES;
+				}
+			}
+		}
+	}
+}
+
+int main(void)
+{
+	if(InitShareMemory() == FAIL)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("InitShareMemory NG\n");
+		#endif
+		if(ShmStatusCodeData!=NULL)
+		{
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
+		}
+		sleep(5);
+		return 0;
+	}
+	// Open Uart5 for RB
+	Uart5Fd = InitComPort();
+	Initialization();
+	sleep(1);
+
+	if(Uart5Fd < 0)
+	{
+		printf ("open port error. \n");
+		return 0;
+	}
+
+	outputRelay.relay_event.bits.AC_Contactor = 0x00;
+	//outputRelay.relay_event.bits.CCS_Precharge = 0x00;
+	//outputRelay.relay_event.bits.Gun1_Parallel_P = 0x01;
+	//outputRelay.relay_event.bits.Gun1_Parallel_N = 0x01;
+	//outputRelay.relay_event.bits.Gun1_P = 0x01;
+	//outputRelay.relay_event.bits.Gun1_N = 0x01;
+	//outputRelay.relay_event.bits.Gun2_N = 0x01;
+	//outputRelay.relay_event.bits.Gun2_P = 0x01;
+	if(Config_Relay_Output(Uart5Fd, Addr.Relay, &outputRelay) != PASS)
+		PRINTF_FUNC("Config_Relay_Output fail \n");
+
+	bool printRelayStatus = false;
+	//return 0;
+	for(;;)
+	{
+		bool isCharging = false;
+		// 程序開始之前~ 必須先確定 FW 版本與硬體版本,確認後!!~ 該模組才算是真正的 Initial Comp.
+		if (ShmRelayModuleData->SelfTest_Comp == NO)
+		{
+			GetFwAndHwVersion_Relay();
+			SetRtcData_Relay();
+			sleep(1);
+		}
+
+		if (ShmFanModuleData->SelfTest_Comp == NO)
+		{
+			GetFwAndHwVersion_Fan();
+			SetModelName_Fan();
+			SetRtcData_Fan();
+			sleep(1);
+			gettimeofday(&_priority_time, NULL);
+		}
+
+		if (ShmRelayModuleData->SelfTest_Comp == YES)
+		{
+			// ==============優先權最高 10 ms ==============
+			// 輸出電壓
+			GetPersentOutputVol();
+
+			// 三相輸入電壓
+			GetPresentInputVol();
+
+			// 讀取當前 relay 狀態
+			GetRelayOutputStatus();
+
+			for (int i = 0; i < gunCount; i++)
+			{
+				// Cable check (Set)
+				CableCheckDetected(i);
+
+				// check k1 k2 relay 狀態
+				CheckK1K2RelayOutput(i);
+
+				// 依據當前各槍的狀態選擇 搭上/放開 Relay
+				SetK1K2RelayStatus(i);
+
+				if (_chargingData[i]->SystemStatus == S_IDLE)
+					gfdChkFailCount[i] = 0;
+
+				if (_chargingData[i]->SystemStatus == S_BOOTING	||
+					(_chargingData[i]->SystemStatus >= S_PREPARNING && _chargingData[i]->SystemStatus <= S_COMPLETE) ||
+					(_chargingData[i]->SystemStatus >= S_CCS_PRECHARGE_ST0 && _chargingData[i]->SystemStatus <= S_CCS_PRECHARGE_ST1) ||
+					(ShmSysConfigAndInfo->SysInfo.PageIndex >= _LCM_AUTHORIZING && ShmSysConfigAndInfo->SysInfo.PageIndex <= _LCM_WAIT_FOR_PLUG))
+				{
+					_chargingData[i]->IsReadyToCharging = YES;
+					isCharging = true;
+
+					if (_chargingData[i]->SystemStatus == S_CHARGING)
+					{
+						CheckOutputPowerOverCarReq(i);
+						CheckOutputVolNoneMatchFire(i);
+					}
+					else
+					{
+						_isOutputNoneMatch[i] = NO;
+					}
+				}
+				else
+					_chargingData[i]->IsReadyToCharging = NO;
+			}
+			// Cable check (Get)
+			GetGfdAdc();
+
+			// 橋接 relay
+			SetParalleRelayStatus();
+
+			// 搭上 AC Contactor
+			if (isCharging)
+				outputRelay.relay_event.bits.AC_Contactor = YES;
+			else
+				outputRelay.relay_event.bits.AC_Contactor = NO;
+
+//			if (isCharging)
+//			{
+//				isStopChargingCount = false;
+//				outputRelay.relay_event.bits.AC_Contactor = YES;
+//			}
+//			else
+//			{
+//				if (!isStopChargingCount)
+//				{
+//					gettimeofday(&_close_ac_contactor, NULL);
+//					isStopChargingCount = true;
+//				}
+//				else
+//				{
+//					if (!isSystemBooting ||
+//						(outputRelay.relay_event.bits.AC_Contactor == YES && GetTimeoutValue(_close_ac_contactor) / 1000 >= (TEN_MINUTES * 1000)))
+//						outputRelay.relay_event.bits.AC_Contactor = NO;
+//				}
+//			}
+
+			// 搭上/鬆開 Relay
+			// 放開 Relay 之前要先確認輸出的電壓電流是否已經降到某個值
+			if(IsNoneMatchRelayStatus())
+			{
+				if (!printRelayStatus)
+				{
+					PRINTF_FUNC("Match Relay Target, AC = %x, g1_p = %x, g1_n = %x, g2_p = %x, g2_n = %x, pre = %x, bri_p = %x, bri_n = %x \n",
+							outputRelay.relay_event.bits.AC_Contactor,
+							outputRelay.relay_event.bits.Gun1_P,
+							outputRelay.relay_event.bits.Gun1_N,
+							outputRelay.relay_event.bits.Gun2_P,
+							outputRelay.relay_event.bits.Gun2_N,
+							outputRelay.relay_event.bits.CCS_Precharge,
+							outputRelay.relay_event.bits.Gun1_Parallel_P,
+							outputRelay.relay_event.bits.Gun1_Parallel_N);
+				}
+				printRelayStatus = false;
+				if (Config_Relay_Output(Uart5Fd, Addr.Relay, &outputRelay))
+				{}
+			}
+			else
+			{
+				if (!printRelayStatus)
+				{
+					PRINTF_FUNC("Match Relay, AC = %x, g1_p = %x, g1_n = %x, g2_p = %x, g2_n = %x, pre = %x, bri_p = %x, bri_n = %x \n",
+							regRelay.relay_event.bits.AC_Contactor,
+							regRelay.relay_event.bits.Gun1_P,
+							regRelay.relay_event.bits.Gun1_N,
+							regRelay.relay_event.bits.Gun2_P,
+							regRelay.relay_event.bits.Gun2_N,
+							regRelay.relay_event.bits.CCS_Precharge,
+							regRelay.relay_event.bits.Gun1_Parallel_P,
+							regRelay.relay_event.bits.Gun1_Parallel_N);
+				}
+				printRelayStatus = true;
+			}
+		}
+
+		if (ShmFanModuleData->SelfTest_Comp == YES)
+		{
+			if (GetTimeoutValue(_priority_time) / 1000 >= 1000)
+			{
+				GetFanSpeed();
+				gettimeofday(&_priority_time, NULL);
+//				printf("ShmFanModuleData->PresentFan1Speed = %d \n", ShmFanModuleData->PresentFan1Speed);
+//				printf("ShmFanModuleData->PresentFan2Speed = %d \n", ShmFanModuleData->PresentFan2Speed);
+//				printf("ShmFanModuleData->PresentFan3Speed = %d \n", ShmFanModuleData->PresentFan3Speed);
+//				printf("ShmFanModuleData->PresentFan4Speed = %d \n", ShmFanModuleData->PresentFan4Speed);
+				if (isCharging)
+				{
+					if (ShmFanModuleData->PresentFan1Speed < MAX_FAN_SPEED ||
+						ShmFanModuleData->PresentFan2Speed < MAX_FAN_SPEED ||
+						ShmFanModuleData->PresentFan3Speed < MAX_FAN_SPEED ||
+						ShmFanModuleData->PresentFan4Speed < MAX_FAN_SPEED)
+					{
+						ShmFanModuleData->SetFan1Speed = MAX_FAN_SPEED;
+						ShmFanModuleData->SetFan2Speed = MAX_FAN_SPEED;
+						ShmFanModuleData->SetFan3Speed = MAX_FAN_SPEED;
+						ShmFanModuleData->SetFan4Speed = MAX_FAN_SPEED;
+					}
+				}
+				else
+				{
+					if (ShmFanModuleData->PresentFan1Speed > MIN_FAN_SPEED ||
+						ShmFanModuleData->PresentFan2Speed < MAX_FAN_SPEED ||
+						ShmFanModuleData->PresentFan3Speed < MAX_FAN_SPEED ||
+						ShmFanModuleData->PresentFan4Speed < MAX_FAN_SPEED)
+					{
+						ShmFanModuleData->SetFan1Speed = MIN_FAN_SPEED;
+						ShmFanModuleData->SetFan2Speed = MIN_FAN_SPEED;
+						ShmFanModuleData->SetFan3Speed = MIN_FAN_SPEED;
+						ShmFanModuleData->SetFan4Speed = MIN_FAN_SPEED;
+					}
+				}
+
+				if (ShmFanModuleData->TestFanSpeed > 0)
+				{
+					ShmFanModuleData->SetFan1Speed = ShmFanModuleData->TestFanSpeed;
+					ShmFanModuleData->SetFan2Speed = ShmFanModuleData->TestFanSpeed;
+					ShmFanModuleData->SetFan3Speed = ShmFanModuleData->TestFanSpeed;
+					ShmFanModuleData->SetFan4Speed = ShmFanModuleData->TestFanSpeed;
+				}
+				//PRINTF_FUNC("set fan = %d \n", ShmFanModuleData->SetFan1Speed);
+				SetFanModuleSpeed();
+			}
+		}
+
+		usleep(10000);
+	}
+
+	return FAIL;
+}

+ 151 - 0
EVSE/Projects/PlugIt360/Apps/Module_LcmContro.h

@@ -0,0 +1,151 @@
+#include 	<sys/time.h>
+#include 	<sys/timeb.h>
+#include    <sys/types.h>
+#include    <sys/stat.h>
+#include 	<sys/types.h>
+#include 	<sys/ioctl.h>
+#include 	<sys/socket.h>
+#include 	<sys/ipc.h>
+#include 	<sys/shm.h>
+#include 	<sys/shm.h>
+#include 	<sys/mman.h>
+#include 	<linux/wireless.h>
+#include 	<arpa/inet.h>
+#include 	<netinet/in.h>
+
+#include 	<unistd.h>
+#include 	<stdarg.h>
+#include    <stdio.h>      /*標準輸入輸出定義*/
+#include    <stdlib.h>     /*標準函數庫定義*/
+#include    <unistd.h>     /*Unix 標準函數定義*/
+#include    <fcntl.h>      /*檔控制定義*/
+#include    <termios.h>    /*PPSIX 終端控制定義*/
+#include    <errno.h>      /*錯誤號定義*/
+#include 	<errno.h>
+#include 	<string.h>
+#include	<time.h>
+#include	<ctype.h>
+#include 	<ifaddrs.h>
+#include 	<stdbool.h>
+#include	"../../define.h"
+
+#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
+#define PASS				1
+#define FAIL				-1
+#define YES					1
+#define NO					0
+
+typedef unsigned char 			byte;
+
+struct SysConfigAndInfo			*ShmSysConfigAndInfo;
+struct StatusCodeData 			*ShmStatusCodeData;
+struct FanModuleData			*ShmFanModuleData;
+
+#define CMD_TITLE_1				0x5A
+#define CMD_TITLE_2				0xA5
+#define CMD_READ				0x80
+#define CMD_WRITE				0x81
+#define CMD_MULTI_WRITE			0x82
+#define CMD_MULTI_READ			0x83
+
+#define CMD_BACKLIGHT			0x01
+#define CMD_REGISTER			0x03
+
+int _port;
+//char* pPortName = "/dev/ttyO2";
+char* pPortName = "/dev/ttyS3";
+char* moduleName = "DMT80480T070_09WT";
+byte _totalCount = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
+struct ChargingInfoData *_chargingInfoData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+
+// 當前選擇的槍號
+short _currentPage = _LCM_NONE;
+byte _gunIndex = 0;
+byte _idlePageRotate = 1;
+bool _backend_conn_status = false;
+bool _wifi_conn_status = false;
+
+// LCM - HW
+byte _everyPageRollChange = 0;
+short __conn_status = 0x0030;
+short __ethernet_status = 0x0036;
+short __wifi_status = 0x003C;
+
+short __sel_gun_btn = 0x0040;
+short __ret_home_btn = 0x0042;
+short __stop_method_btn = 0x0044;
+
+short __qr_code = 0x0050;
+
+short __plug_in_arrow = 0x0060;
+
+short __conn_line = 0x0066;
+
+short __gun_type_index = 0x0070;
+short __qr_code_pre = 0x0080;
+
+short __side_top = 0x0090;
+short __side_down = 0x0092;
+
+short __conn_line_chag = 0x0096;
+short __batt_map = 0x0100;
+short __soc_value_charging = 0x0102;
+short __remain_time_map = 0x0106;
+short __power_map = 0x0108;
+short __energy_map = 0x010A;
+short __remain_time_tx = 0x0110;
+short __output_eng_tx = 0x0120;
+short __total_out_eng_tx = 0x0130;
+short __conn_line_comp = 0x0140;
+
+// ICON ID
+byte _disappear = 0;
+byte _disconnect = 1;
+byte _connect = 2;
+byte _warning = 3;
+byte _arrow_dark = 4;
+byte _arrow_light = 5;
+byte _ethernet_disconnect = 6;
+byte _ethernet_connect = 7;
+byte _wifi_disconnect = 8;
+byte _wifi_connect = 9;
+byte _logo = 10;
+byte _conn_map1 = 11;
+byte _conn_map2 = 12;
+byte _sel_gun_btn = 13;
+byte _back_home_btn = 14;
+byte _stop_charging_btn = 15;
+byte _stop_charging_btn_scan = 16;
+byte _chademo_dark = 17;
+byte _ccs_dark = 18;
+byte _actype_dark = 19;
+byte _chademo_light = 20;
+byte _ccs_light = 21;
+byte _actype_light = 22;
+byte _side_rfid_1 = 23;
+byte _side_qr_1 = 24;
+byte _side_app_1 = 25;
+byte _side_rfid_2 = 26;
+byte _side_qr_2 = 27;
+byte _side_app_2 = 28;
+byte _charging_map1 = 29;
+byte _charging_map2 = 30;
+byte _battery_cap_20 = 31;
+byte _battery_cap_40 = 32;
+byte _battery_cap_60 = 33;
+byte _battery_cap_80 = 34;
+byte _battery_cap_100 = 35;
+byte _battery_map = 36;
+byte _power_map = 37;
+byte _time_map = 38;
+byte _complete_map = 39;
+byte _battery_soc_20 = 40;
+byte _battery_soc_40 = 41;
+byte _battery_soc_60 = 42;
+byte _battery_soc_80 = 43;
+byte _battery_soc_100 = 44;
+byte _battery_eng_map = 45;
+byte _money_map = 46;
+byte _elapse_time_map = 47;
+
+

BIN
EVSE/Projects/PlugIt360/Apps/Module_LcmControl


+ 904 - 0
EVSE/Projects/PlugIt360/Apps/Module_LcmControl.c

@@ -0,0 +1,904 @@
+#include "Module_LcmContro.h"
+
+void PRINTF_FUNC(char *string, ...);
+
+int StoreLogMsg(const char *fmt, ...);
+#define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+
+char* getTimeString(void);
+
+//=================================
+// Common routine
+//=================================
+int StoreLogMsg(const char *fmt, ...)
+{
+	char Buf[4096+256];
+	char buffer[4096];
+	time_t CurrentTime;
+	struct tm *tm;
+	va_list args;
+
+	va_start(args, fmt);
+	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
+	va_end(args);
+
+	memset(Buf,0,sizeof(Buf));
+	CurrentTime = time(NULL);
+	tm=localtime(&CurrentTime);
+	sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
+			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
+			buffer,
+			tm->tm_year+1900,tm->tm_mon+1);
+	system(Buf);
+
+	return rc;
+}
+
+char* getTimeString(void)
+{
+	char *result=malloc(21);
+	time_t timep;
+	struct tm *p;
+	time(&timep);
+	p=gmtime(&timep);
+
+	sprintf(result, "[%04d-%02d-%02d %02d:%02d:%02d]", (1900+p->tm_year), (1+p->tm_mon), p->tm_mday, p->tm_hour, p->tm_hour, p->tm_sec);
+
+	return result;
+}
+
+void PRINTF_FUNC(char *string, ...)
+{
+	if (DEBUG)
+	{
+		va_list args;
+		char buffer[4096];
+
+		va_start(args, string);
+		vsnprintf(buffer, sizeof(buffer), string, args);
+		va_end(args);
+		printf("%s \n", buffer);
+	}
+}
+
+//==========================================
+// Init all share memory
+//==========================================
+int InitShareMemory()
+{
+	int result = PASS;
+	int MeterSMId;
+
+	//creat ShmSysConfigAndInfo
+	if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0)
+    {
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
+		#endif
+		result = FAIL;
+	}
+    else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+    {
+    	#ifdef SystemLogMessage
+    	DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
+		#endif
+    	result = FAIL;
+   	 }
+    else
+    {}
+
+   	 //creat ShmStatusCodeData
+   	 if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0)
+    {
+		#ifdef SystemLogMessage
+   		DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
+		#endif
+   		result = FAIL;
+	}
+    else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+    {
+    	#ifdef SystemLogMessage
+    	DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
+		#endif
+    	result = FAIL;
+   	}
+    else
+    {}
+
+    return result;
+}
+
+//==========================================
+// Open and Close RS232 and R/W
+//==========================================
+int CreateCommunicationLcmPort()
+{
+	int fd;
+	struct termios tios;
+
+	fd = open(pPortName, O_RDWR);
+	if (fd <= 0) {
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("open /dev/ttyS3 NG \n");
+		#endif
+		return -1;
+	}
+	ioctl(fd, TCGETS, &tios);
+	tios.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
+	tios.c_lflag = 0;
+	tios.c_iflag = 0;
+	tios.c_oflag = 0;
+	tios.c_cc[VMIN] = 0;
+	tios.c_cc[VTIME] = (unsigned char) 5;
+	tios.c_lflag = 0;
+	tcflush(fd, TCIFLUSH);
+	ioctl(fd, TCSETS, &tios);
+
+	return fd;
+}
+
+void CloseCommunicationLcmPort()
+{
+	close(_port);
+}
+
+void WriteCmdToLcm(byte *cmd, byte cmdLen)
+{
+	int len = write(_port, cmd, cmdLen);
+	if(len >= sizeof(cmd))
+	{
+		//PRINTF_FUNC("Write cmd to LCM successfully. \n");
+	}
+}
+
+void ReadMsgFromLcm(byte *msg, byte readLen)
+{
+	read(_port, msg, readLen);
+
+	if(*msg == CMD_TITLE_1 && *(msg + 1) == CMD_TITLE_2)
+	{
+		if(*(msg + 3) == CMD_WRITE)
+		{
+			switch (*(msg + 4))
+			{
+				case CMD_REGISTER:
+				{
+					// 頁面
+					_currentPage = (unsigned short) (*(msg + 6) << 8) + (unsigned short) *(msg + 7);
+				}
+				break;
+			}
+		}
+		else if (*(msg + 3) == CMD_MULTI_READ)
+		{
+//			switch ((unsigned short) (*(msg + 4) << 8) + (unsigned short) *(msg + 5))
+//			{
+//				case BUTTON_GUN_INDEX:
+//				{
+//					// 當前選的槍號
+//					_curGunIndex = (*(msg + 8));
+//				}
+//				break;
+//			}
+		}
+	}
+
+//	for (byte idx = 0; idx < len; idx++)
+//		PRINTF_FUNC("[system_command]-RX: %X\n", *(msg + idx));
+}
+
+//================================================
+// Function
+//================================================
+void ChangeToOtherPage(short newPage)
+{
+	byte cmd[7];
+	memset(cmd, 0x00, sizeof(cmd));
+
+	cmd[0] = CMD_TITLE_1;
+	cmd[1] = CMD_TITLE_2;
+	cmd[2] = 0x02 + sizeof(newPage);
+	cmd[3] = CMD_READ;
+	cmd[4] = CMD_REGISTER;
+	cmd[5] = newPage >> 8;
+	cmd[6] = newPage & 0x00FF;
+
+	WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
+	usleep(100000);
+}
+
+void ChangeBackLight(bool islight)
+{
+	byte value = 0x01;
+
+	if (islight)
+	{
+		value = 0x20;
+	}
+	byte cmd[7];
+	memset(cmd, 0x00, sizeof(cmd));
+
+	cmd[0] = CMD_TITLE_1;
+	cmd[1] = CMD_TITLE_2;
+	cmd[2] = 0x03;
+	cmd[3] = CMD_READ;
+	cmd[4] = CMD_BACKLIGHT;
+	cmd[5] = value;
+
+	WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
+	usleep(100000);
+}
+
+void GetCurrentPage()
+{
+	byte cmd[6];
+	memset(cmd, 0x00, sizeof(cmd));
+	byte msg[8];
+	memset(msg, 0x00, sizeof(msg));
+
+	cmd[0] = CMD_TITLE_1;
+	cmd[1] = CMD_TITLE_2;
+	cmd[2] = 0x03;				// 底下總長度
+	cmd[3] = CMD_WRITE;
+	cmd[4] = CMD_REGISTER;
+	cmd[5] = 0x02;
+
+	WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
+	usleep(100000);
+	ReadMsgFromLcm(msg, ARRAY_SIZE(msg));
+}
+
+void DisplayValueToLcm(short address, byte *data, byte len)
+{
+	byte cmd[256];
+	memset(cmd, 0x00, sizeof(cmd));
+
+	cmd[0] = CMD_TITLE_1;
+	cmd[1] = CMD_TITLE_2;
+	cmd[2] = 0x03 + len;
+	cmd[3] = CMD_MULTI_WRITE;
+	cmd[4] = address >> 8;
+	cmd[5] = address & 0x00FF;
+
+	for(byte count = 0; count < len; count++)
+	{
+		cmd[6 + count] = *(data + count);
+	}
+
+	WriteCmdToLcm(cmd, cmd[2] + 3);
+}
+
+void ChangeDisplay2Value(short address, short value)
+{
+	byte data[2];
+	data[0] = value >> 8;
+	data[1] = value & 0x00FF;
+
+	DisplayValueToLcm(address, data, sizeof(data));
+}
+
+void GetBtnStatus(short address, byte len)
+{
+	byte cmd[8];
+	memset(cmd, 0x00, sizeof(cmd));
+	byte msg[8];
+	memset(msg, 0x00, sizeof(msg));
+
+	cmd[0] = CMD_TITLE_1;
+	cmd[1] = CMD_TITLE_2;
+	cmd[2] = 0x03 + len;
+	cmd[3] = CMD_MULTI_READ;
+	cmd[4] = address >> 8;
+	cmd[5] = address & 0x00FF;
+	cmd[6] = 0x00 + len;
+
+	WriteCmdToLcm(cmd, cmd[2] + 3);
+	usleep(100000);
+	ReadMsgFromLcm(msg, (len * 2) + sizeof(msg));
+}
+
+//================================================
+// Warning process
+//================================================
+void string2ByteArray(unsigned char *input, byte *output)
+{
+    int loop;
+    int i;
+
+    loop = 0;
+    i = 0;
+
+    while(input[loop] != '\0')
+    {
+        output[i++] = input[loop++];
+    }
+    output[loop] = '\0';
+}
+
+void ChangeWarningFunc()
+{
+	byte cmd[7];
+	byte i = 0;
+	//PRINTF_FUNC("ChangeWarningFunc \n");
+	// 最多一次五筆
+	//PRINTF_FUNC("LCM PageIndex = %d \n", ShmSysConfigAndInfo->SysWarningInfo.PageIndex);
+	//PRINTF_FUNC("WarningCount = %d \n", ShmSysConfigAndInfo->SysWarningInfo.WarningCount);
+	for(i = 0; (i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5) < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++)
+	{
+		memset(cmd, 0x00, sizeof(cmd));
+		if(i >= 5)
+		{
+			break;
+		}
+		//error code
+		string2ByteArray(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], cmd);
+		DisplayValueToLcm(0x0010 + (i * 6), cmd, sizeof(cmd));
+		//警告標示
+		memset(cmd, 0x00, sizeof(cmd));
+
+		cmd[0] = 0x00;
+		cmd[1] = 0x01;
+		DisplayValueToLcm(0x0002 + (i * 2), cmd, 2);
+	}
+
+	memset(cmd, 0x00, sizeof(cmd));
+	for(; i < 5; i++)
+	{
+		DisplayValueToLcm(0x0010 + (i * 6), cmd, sizeof(cmd));
+		DisplayValueToLcm(0x0002 + (i * 2), cmd, 2);
+	}
+}
+
+//================================================
+// QR Code process
+//================================================
+void ChangeQrCode_Idle(char *input)
+{
+	int len = strlen(input);
+	byte cmd[len];
+
+	int loop = 0;
+	int i = 0;
+
+	while(input[loop] != '\0')
+	{
+		cmd[i++] = input[loop++];
+	}
+
+	DisplayValueToLcm(__qr_code, cmd, len);
+}
+
+void ChangeQrCode_Charge(char *input)
+{
+	int len = strlen(input);
+	byte cmd[len];
+
+	int loop = 0;
+	int i = 0;
+
+	while(input[loop] != '\0')
+	{
+		cmd[i++] = input[loop++];
+	}
+
+	DisplayValueToLcm(__qr_code_pre, cmd, len);
+}
+
+//================================================
+// Change current page
+//================================================
+void ChangeCurPage()
+{
+	//PRINTF_FUNC("cur = %d, new = %d \n", _currentPage, ShmSysConfigAndInfo->SysInfo.PageIndex);
+	if (_currentPage != ShmSysConfigAndInfo->SysInfo.PageIndex)
+	{
+		_currentPage = ShmSysConfigAndInfo->SysInfo.PageIndex;
+		ChangeToOtherPage(_currentPage);
+		_everyPageRollChange = 0;
+	}
+}
+
+//================================================
+// Main process
+//================================================
+byte demoCount = 0;
+void DemoFunction()
+{
+	if (demoCount == 0)
+	{
+		ShmSysConfigAndInfo->SysWarningInfo.WarningCount = 6;
+		memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[0][0], "000001", 7);
+		memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[1][0], "000002", 7);
+		memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[2][0], "000003", 7);
+		memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[3][0], "000004", 7);
+		memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[4][0], "000005", 7);
+		memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[5][0], "000006", 7);
+	}
+	else
+	{
+		if (demoCount == 20) {
+			ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_IDLE;
+		} else if (demoCount == 80) {
+			ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_AUTHORIZING;
+		} else if (demoCount == 100) {
+			ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_AUTHORIZ_COMP;
+		} else if (demoCount == 120) {
+			ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_AUTHORIZ_FAIL;
+		} else if (demoCount == 140) {
+			ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_PRE_CHARGE;
+		} else if (demoCount == 180) {
+			ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_CHARGING;
+		}
+	}
+
+	if (demoCount < 180)
+		demoCount++;
+}
+
+//================================================
+// Main process
+//================================================
+bool FindChargingInfoData(byte target, struct ChargingInfoData **_chargingData)
+{
+	for (byte index = 0; index < CHAdeMO_QUANTITY; index++)
+	{
+		if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)
+		{
+			_chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
+			return true;
+		}
+	}
+
+	for (byte index = 0; index < CCS_QUANTITY; index++)
+	{
+		if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)
+		{
+			_chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
+			return true;
+		}
+	}
+
+	for (byte index = 0; index < GB_QUANTITY; index++)
+	{
+		if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)
+		{
+			_chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
+			return true;
+		}
+	}
+
+	return false;
+}
+
+void ChangeBattMapAndValue(short page, int soc)
+{
+//	srand(time(NULL));
+//	int min = 10;
+//	int max = 90;
+//	soc = rand() % (max - min + 1) + min;
+
+	if (page == _LCM_CHARGING)
+	{
+		if (soc < 20)
+			ChangeDisplay2Value(__batt_map, _battery_cap_20);
+		else if (soc >= 20 && soc < 40)
+			ChangeDisplay2Value(__batt_map, _battery_cap_40);
+		else if (soc >= 40 && soc < 60)
+			ChangeDisplay2Value(__batt_map, _battery_cap_60);
+		else if (soc >= 60 && soc < 80)
+			ChangeDisplay2Value(__batt_map, _battery_cap_80);
+		else if (soc >= 80 && soc <= 100)
+			ChangeDisplay2Value(__batt_map, _battery_cap_100);
+	}
+	else if (page == _LCM_COMPLETE)
+	{
+		if (soc < 20)
+			ChangeDisplay2Value(__batt_map, _battery_soc_20);
+		else if (soc >= 20 && soc < 40)
+			ChangeDisplay2Value(__batt_map, _battery_soc_40);
+		else if (soc >= 40 && soc < 60)
+			ChangeDisplay2Value(__batt_map, _battery_soc_60);
+		else if (soc >= 60 && soc < 80)
+			ChangeDisplay2Value(__batt_map, _battery_soc_80);
+		else if (soc >= 80 && soc <= 100)
+			ChangeDisplay2Value(__batt_map, _battery_soc_100);
+	}
+
+	byte cmd[4];
+	byte value[4];
+
+	memset(cmd, 0x00, sizeof(cmd));
+	sprintf((char *)value, "%d%%", soc);
+	string2ByteArray(value, cmd);
+	DisplayValueToLcm(__soc_value_charging, cmd, sizeof(cmd));
+}
+
+void ChangeRemainTime(int sec)
+{
+	int h, m, s;
+	byte cmd[10];
+	byte value[10];
+
+	memset(cmd, 0x00, sizeof(cmd));
+
+//	srand(time(NULL));
+//	int min = 0;
+//	int max = 65536;
+//	sec = rand() % (max - min + 1) + min;
+
+	h = (sec / 3600);
+	m = (sec - (3600 * h)) / 60;
+	s = (sec - (3600 * h) - (m * 60));
+	sprintf((char *)value, "%02d:%02d:%02d", h, m, s);
+	string2ByteArray(value, cmd);
+	DisplayValueToLcm(__remain_time_tx, cmd, sizeof(cmd));
+}
+
+void ChangeChargingEnergyValue(float energy)
+{
+	byte cmd[10];
+	byte value[10];
+
+	memset(cmd, 0x00, sizeof(cmd));
+
+	sprintf((char *) value, "%.1f kWh", energy);
+	string2ByteArray(value, cmd);
+	DisplayValueToLcm(__total_out_eng_tx, cmd, sizeof(cmd));
+}
+
+void ChangeChargingPowerValue(float pow)
+{
+	byte cmd[10];
+	byte value[10];
+
+	memset(cmd, 0x00, sizeof(cmd));
+
+//	float min = 0.0;
+//	float max = 50;
+//	pow = (max - min) * rand() / (RAND_MAX + 1.0) + min;
+
+	sprintf((char *) value, "%.1f kW", pow);
+	string2ByteArray(value, cmd);
+	DisplayValueToLcm(__output_eng_tx, cmd, sizeof(cmd));
+}
+
+void ChangeStopMap(byte value)
+{
+
+}
+
+void RefreshPageAnimation(byte value)
+{
+	switch(_currentPage)
+	{
+		case _LCM_IDLE:
+		{
+			if (value == 0)
+			{
+				ChangeToOtherPage(_currentPage);
+			}
+			else if (value == 15)
+			{
+				ChangeToOtherPage(_currentPage + 1);
+			}
+			else if (value == 30)
+			{
+				ChangeToOtherPage(_currentPage + 2);
+			}
+
+			_everyPageRollChange > 45 ? _everyPageRollChange = 0 : _everyPageRollChange++;
+		}
+			break;
+		case _LCM_WAIT_FOR_PLUG:
+		{
+			if(_everyPageRollChange == 0)
+				ChangeDisplay2Value(__plug_in_arrow, _arrow_dark);
+			else if(_everyPageRollChange == 15)
+				ChangeDisplay2Value(__plug_in_arrow, _arrow_light);
+
+			_everyPageRollChange > 30 ? _everyPageRollChange = 0 : _everyPageRollChange++;
+		}
+			break;
+		case _LCM_PRE_CHARGE:
+		case _LCM_CHARGING:
+		case _LCM_COMPLETE:
+		{
+			if (_currentPage == _LCM_PRE_CHARGE)
+			{
+				if (_everyPageRollChange == 0 || _everyPageRollChange == 22)
+					ChangeDisplay2Value(__conn_line, _conn_map1);
+				else if (_everyPageRollChange == 11 || _everyPageRollChange == 33)
+					ChangeDisplay2Value(__conn_line, _conn_map2);
+			}
+			else if (_currentPage == _LCM_CHARGING)
+			{
+				if (_everyPageRollChange == 0 || _everyPageRollChange == 22)
+					ChangeDisplay2Value(__conn_line_chag, _charging_map1);
+				else if (_everyPageRollChange == 11 || _everyPageRollChange == 33)
+					ChangeDisplay2Value(__conn_line_chag, _charging_map2);
+			}
+			else if (_currentPage == _LCM_COMPLETE)
+			{
+				if (_everyPageRollChange == 0)
+					ChangeDisplay2Value(__conn_line_comp, _complete_map);
+			}
+
+			if (_totalCount == 2 && _currentPage != _LCM_PRE_CHARGE)
+			{
+				byte index = 0;
+				for (index = 0; index < _totalCount; index++) {
+					if (ShmSysConfigAndInfo->SysInfo.CurGunSelected != index)
+					{
+						break;
+					}
+				}
+
+				ChangeDisplay2Value(__sel_gun_btn, _sel_gun_btn);
+				if (_chargingInfoData[index]->SystemStatus == S_IDLE ||
+						_chargingInfoData[index]->SystemStatus == S_RESERVATION)
+				{
+					if(value == 0)
+					{
+						ChangeDisplay2Value(__side_top, _side_rfid_1);
+						ChangeDisplay2Value(__side_down, _side_rfid_2);
+					}
+					else if (value == 15)
+					{
+						ChangeDisplay2Value(__side_top, _side_qr_1);
+						ChangeDisplay2Value(__side_down, _side_qr_2);
+					}
+					else if (value == 30)
+					{
+						ChangeDisplay2Value(__side_top, _side_app_1);
+						ChangeDisplay2Value(__side_down, _side_app_2);
+					}
+				}
+				else
+				{
+					ChangeDisplay2Value(__side_top, _disappear);
+					ChangeDisplay2Value(__side_down, _disappear);
+					ChangeDisplay2Value(__qr_code_pre, _disappear);
+				}
+			}
+			else
+			{
+				ChangeDisplay2Value(__sel_gun_btn, _disappear);
+				ChangeDisplay2Value(__side_top, _disappear);
+				ChangeDisplay2Value(__side_down, _disappear);
+				ChangeDisplay2Value(__qr_code_pre, _disappear);
+			}
+
+			_everyPageRollChange >= 45 ? _everyPageRollChange = 0 : _everyPageRollChange++;
+		}
+			break;
+	}
+}
+
+void RefreshConnStatus()
+{
+	// Wifi priority is higher than Ethernet
+	if (ShmSysConfigAndInfo->SysConfig.AthInterface.WifiNetworkConn == YES)
+	{
+		_wifi_conn_status = true;
+		ChangeDisplay2Value(__wifi_status, _wifi_connect);
+		ChangeDisplay2Value(__ethernet_status, _disappear);
+	}
+	else
+	{
+		_wifi_conn_status = false;
+		ChangeDisplay2Value(__wifi_status, _disappear);
+	}
+
+	if (!_wifi_conn_status)
+	{
+		if (ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn == YES)
+		{
+			ChangeDisplay2Value(__ethernet_status, _ethernet_connect);
+		}
+		else
+		{
+			ChangeDisplay2Value(__ethernet_status, _ethernet_disconnect);
+		}
+	}
+
+	// 連線到後台
+	if (ShmSysConfigAndInfo->SysInfo.OcppConnStatus == YES)
+		ChangeDisplay2Value(__conn_status, _connect);
+	else
+		ChangeDisplay2Value(__conn_status, _disconnect);
+}
+
+void ProcessPageInfo()
+{
+	switch(_currentPage)
+	{
+		case _LCM_IDLE:
+		{
+			// QR Code 處理
+			ChangeQrCode_Idle("http://google.com.tw");
+		}
+			break;
+		case _LCM_PRE_CHARGE:
+		case _LCM_CHARGING:
+		case _LCM_COMPLETE:
+		{
+			// gun type and charging info
+			for(byte i = 0; i < _totalCount; i++)
+			{
+				switch(_chargingInfoData[i]->Type)
+				{
+					case _Type_Chademo:
+					{
+						if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == i)
+						{
+							ChangeDisplay2Value(__gun_type_index + (i * 2), _chademo_light);
+						}
+						else
+						{
+							ChangeDisplay2Value(__gun_type_index + (i * 2), _chademo_dark);
+						}
+					}
+						break;
+					case _Type_CCS_2:
+					{
+						if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == i)
+						{
+							ChangeDisplay2Value(__gun_type_index + (i * 2), _ccs_light);
+						}
+						else
+						{
+							ChangeDisplay2Value(__gun_type_index + (i * 2), _ccs_dark);
+						}
+					}
+						break;
+				}
+
+				if (_currentPage == _LCM_CHARGING)
+				{
+					if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == i)
+					{
+						ChangeBattMapAndValue(_LCM_CHARGING, _chargingInfoData[i]->EvBatterySoc);
+						if (_chargingInfoData[i]->RemainChargingDuration >= 0)
+							ChangeRemainTime(_chargingInfoData[i]->RemainChargingDuration);
+						if (_chargingInfoData[i]->PresentChargingPower >= 0)
+							ChangeChargingPowerValue(_chargingInfoData[i]->PresentChargingPower);
+						if (_chargingInfoData[i]->PresentChargedEnergy >= 0)
+							ChangeChargingEnergyValue(_chargingInfoData[i]->PresentChargedEnergy);
+
+						if (strcmp((char *)_chargingInfoData[i]->StartUserId, "") == 0)
+							ChangeDisplay2Value(__stop_method_btn, _stop_charging_btn);
+						else
+							ChangeDisplay2Value(__stop_method_btn, _stop_charging_btn_scan);
+					}
+				}
+				else if (_currentPage == _LCM_COMPLETE)
+				{
+					if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == i)
+					{
+						ChangeBattMapAndValue(_LCM_COMPLETE, _chargingInfoData[i]->EvBatterySoc);
+						if (_chargingInfoData[i]->RemainChargingDuration >= 0)
+							ChangeRemainTime(_chargingInfoData[i]->RemainChargingDuration);
+						if (_chargingInfoData[i]->PresentChargingPower >= 0)
+							ChangeChargingPowerValue(_chargingInfoData[i]->PresentChargingPower);
+						if (_chargingInfoData[i]->PresentChargedEnergy >= 0)
+							ChangeChargingEnergyValue(_chargingInfoData[i]->PresentChargedEnergy);
+					}
+				}
+			}
+
+			// gun btn and QR code
+			if (_totalCount == 2 && _currentPage != _LCM_PRE_CHARGE)
+			{
+				byte index = 0;
+				for(index = 0; index < _totalCount; index++)
+				{
+					if(ShmSysConfigAndInfo->SysInfo.CurGunSelected != index)
+					{
+						break;
+					}
+				}
+
+				if (_chargingInfoData[index]->SystemStatus == S_IDLE ||
+						_chargingInfoData[index]->SystemStatus == S_RESERVATION ||
+						_chargingInfoData[index]->SystemStatus == S_BOOTING)
+				{
+					// QR Code 處理
+					ChangeQrCode_Charge("http://google.com.tw");
+				}
+			}
+		}
+			break;
+	}
+}
+
+void Initialization()
+{
+	strcpy((char *)ShmSysConfigAndInfo->SysInfo.LcmHwRev, moduleName);
+
+	bool isPass = false;
+	byte count = 5;
+	while(!isPass && count > 0)
+	{
+		isPass = true;
+		for (byte _index = 0; _index < _totalCount; _index++)
+		{
+			if (!FindChargingInfoData(_index, &_chargingInfoData[0]))
+			{
+				DEBUG_ERROR("EvComm (main) : FindChargingInfoData false \n");
+				isPass = false;
+				count--;
+				break;
+			}
+		}
+	}
+
+	if (count == 0)
+		PRINTF_FUNC("LCM Initialization Gun Fail.............\n");
+}
+
+int main(void)
+{
+	if(InitShareMemory() == FAIL)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("InitShareMemory NG\n");
+		#endif
+		if (ShmStatusCodeData != NULL)
+		{
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory =	1;
+		}
+		sleep(5);
+		return 0;
+	}
+
+	_port = CreateCommunicationLcmPort();
+	byte changeWarningPriority = 0;
+	byte curWarningCount = 255;
+	//ChangeBackLight(true);
+	Initialization();
+
+//	ChangeToOtherPage(_LCM_FIX);
+//	return 0;
+	while(_port != -1)
+	{
+		//DemoFunction();
+
+		// Warning 處理
+		if(curWarningCount != ShmSysConfigAndInfo->SysWarningInfo.WarningCount)
+		{
+			changeWarningPriority = 0;
+			ShmSysConfigAndInfo->SysWarningInfo.PageIndex = 0;
+			curWarningCount = ShmSysConfigAndInfo->SysWarningInfo.WarningCount;
+			ChangeWarningFunc();
+		}
+		else if (ShmSysConfigAndInfo->SysWarningInfo.WarningCount > 5 && changeWarningPriority == 0)
+		{
+			// 當有兩頁 Warning 則每隔三秒改變一次
+			if(ShmSysConfigAndInfo->SysWarningInfo.PageIndex == 0)
+				ShmSysConfigAndInfo->SysWarningInfo.PageIndex = 1;
+			else
+				ShmSysConfigAndInfo->SysWarningInfo.PageIndex = 0;
+
+			ChangeWarningFunc();
+		}
+
+		// 頁面資訊處理
+		ProcessPageInfo();
+
+		// 網路 - wifi - 連線訊號處理
+		RefreshConnStatus();
+
+		// 換頁處理
+		ChangeCurPage();
+
+		RefreshPageAnimation(_everyPageRollChange);
+
+		changeWarningPriority >= 30 ? changeWarningPriority = 0 : changeWarningPriority++;
+		usleep(100000);
+	}
+
+	CloseCommunicationLcmPort();
+	return FAIL;
+}

BIN
EVSE/Projects/PlugIt360/Apps/Module_PrimaryComm


+ 419 - 0
EVSE/Projects/PlugIt360/Apps/Module_PrimaryComm.c

@@ -0,0 +1,419 @@
+#include 	<sys/time.h>
+#include 	<sys/timeb.h>
+#include    <sys/types.h>
+#include    <sys/stat.h>
+#include 	<sys/types.h>
+#include 	<sys/ioctl.h>
+#include 	<sys/socket.h>
+#include 	<sys/ipc.h>
+#include 	<sys/shm.h>
+#include 	<sys/shm.h>
+#include 	<sys/mman.h>
+#include 	<linux/wireless.h>
+#include 	<arpa/inet.h>
+#include 	<netinet/in.h>
+
+#include 	<unistd.h>
+#include 	<stdarg.h>
+#include    <stdio.h>      /*標準輸入輸出定義*/
+#include    <stdlib.h>     /*標準函數庫定義*/
+#include    <unistd.h>     /*Unix 標準函數定義*/
+#include    <fcntl.h>      /*檔控制定義*/
+#include    <termios.h>    /*PPSIX 終端控制定義*/
+#include    <errno.h>      /*錯誤號定義*/
+#include 	<errno.h>
+#include 	<string.h>
+#include	<time.h>
+#include	<ctype.h>
+#include 	<ifaddrs.h>
+#include 	<math.h>
+#include	"../../define.h"
+#include	"PrimaryComm.h"
+#include 	<stdbool.h>
+
+#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
+#define PASS				1
+#define FAIL				-1
+#define YES					1
+#define NO					0
+
+typedef unsigned char 		byte;
+
+struct SysConfigAndInfo			*ShmSysConfigAndInfo;
+struct StatusCodeData 			*ShmStatusCodeData;
+struct PrimaryMcuData			*ShmPrimaryMcuData;
+
+void trim(char *s);
+int mystrcmp(char *p1,char *p2);
+void substr(char *dest, const char* src, unsigned int start, unsigned int cnt);
+void split(char **arr, char *str, const char *del);
+
+int Uart1Fd;
+char *priPortName = "/dev/ttyS1";
+Ver ver;
+Gpio_in gpio_in;
+Rtc rtc;
+
+void PRINTF_FUNC(char *string, ...);
+
+int StoreLogMsg(const char *fmt, ...);
+#define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+
+int StoreLogMsg(const char *fmt, ...)
+{
+	char Buf[4096+256];
+	char buffer[4096];
+	time_t CurrentTime;
+	struct tm *tm;
+	va_list args;
+
+	va_start(args, fmt);
+	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
+	va_end(args);
+
+	memset(Buf,0,sizeof(Buf));
+	CurrentTime = time(NULL);
+	tm=localtime(&CurrentTime);
+	sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
+			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
+			buffer,
+			tm->tm_year+1900,tm->tm_mon+1);
+	system(Buf);
+
+	return rc;
+}
+
+int DiffTimeb(struct timeb ST, struct timeb ET)
+{
+	//return milli-second
+	unsigned int StartTime,StopTime;
+
+	StartTime=(unsigned int)ST.time;
+	StopTime=(unsigned int)ET.time;
+	return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
+}
+
+void PRINTF_FUNC(char *string, ...)
+{
+	if (DEBUG)
+	{
+		va_list args;
+		char buffer[4096];
+
+		va_start(args, string);
+		vsnprintf(buffer, sizeof(buffer), string, args);
+		va_end(args);
+		printf("%s \n", buffer);
+	}
+}
+//=================================
+// Common routine
+//=================================
+char* getTimeString(void)
+{
+	char *result=malloc(21);
+	time_t timep;
+	struct tm *p;
+	time(&timep);
+	p=gmtime(&timep);
+
+	sprintf(result, "[%04d-%02d-%02d %02d:%02d:%02d]", (1900+p->tm_year), (1+p->tm_mon), p->tm_mday, p->tm_hour, p->tm_hour, p->tm_sec);
+
+	return result;
+}
+
+void trim(char *s)
+{
+    int i=0, j, k, l=0;
+
+    while((s[i]==' ')||(s[i]=='\t')||(s[i]=='\n'))
+        i++;
+
+    j = strlen(s)-1;
+    while((s[j]==' ')||(s[j]=='\t')||(s[j]=='\n'))
+        j--;
+
+    if(i==0 && j==strlen(s)-1) { }
+    else if(i==0) s[j+1] = '\0';
+    else {
+        for(k=i; k<=j; k++) s[l++] = s[k];
+        s[l] = '\0';
+    }
+}
+
+int mystrcmp(char *p1,char *p2)
+{
+    while(*p1==*p2)
+    {
+        if(*p1=='\0' || *p2=='\0')
+            break;
+        p1++;
+        p2++;
+    }
+    if(*p1=='\0' && *p2=='\0')
+        return(PASS);
+    else
+        return(FAIL);
+}
+
+void substr(char *dest, const char* src, unsigned int start, unsigned int cnt)
+{
+	strncpy(dest, src + start, cnt);
+	dest[cnt] = 0;
+}
+
+void split(char **arr, char *str, const char *del)
+{
+	char *s = strtok(str, del);
+
+	while(s != NULL)
+	{
+		*arr++ = s;
+		s = strtok(NULL, del);
+	}
+}
+
+//==========================================
+// Init all share memory
+//==========================================
+int InitShareMemory()
+{
+	int result = PASS;
+	int MeterSMId;
+
+	//creat ShmSysConfigAndInfo
+	if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0)
+    {
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
+		#endif
+		result = FAIL;
+	}
+    else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+    {
+    	#ifdef SystemLogMessage
+    	DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
+		#endif
+    	result = FAIL;
+   	 }
+
+   	 //creat ShmStatusCodeData
+   	 if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0)
+    {
+		#ifdef SystemLogMessage
+   		DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
+		#endif
+   		result = FAIL;
+	}
+    else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+    {
+    	#ifdef SystemLogMessage
+    	DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
+		#endif
+    	result = FAIL;
+   	}
+
+	//creat ShmStatusCodeData
+	if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), 0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmget ShmPrimaryMcuData NG\n");
+		#endif
+		result = FAIL;
+	}
+	else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef ShmPrimaryMcuData
+		DEBUG_ERROR("shmat ShmPrimaryMcuData NG\n");
+		#endif
+		result = FAIL;
+	}
+
+    return result;
+}
+
+//================================================
+// Function
+//================================================
+void GetFwAndHwVersion()
+{
+	if(Query_FW_Ver(Uart1Fd, Addr.IoExtend, &ver) == PASS)
+	{
+		PRINTF_FUNC("s1 = %s \n", ver.Version_FW);
+		strcpy((char *)ShmPrimaryMcuData->version, ver.Version_FW);
+		strcpy((char *) ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, ver.Version_FW);
+	}
+
+	if (Query_HW_Ver(Uart1Fd, Addr.IoExtend, &ver) == PASS)
+		PRINTF_FUNC("s2 = %s \n", ver.Version_HW);
+}
+
+void GetInputGpioStatus()
+{
+	//PRINTF_FUNC("GetInputGpioStatus \n");
+	if (Query_Gpio_Input(Uart1Fd, Addr.IoExtend, &gpio_in) == PASS)
+	{
+		ShmSysConfigAndInfo->SysInfo.AcContactorStatus = ShmPrimaryMcuData->InputDet.bits.AcContactorDetec = gpio_in.AC_Connector;
+		ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec = gpio_in.AC_MainBreaker;
+		ShmPrimaryMcuData->InputDet.bits.SpdDetec = gpio_in.SPD;
+		ShmPrimaryMcuData->InputDet.bits.DoorOpen = gpio_in.Door_Open;
+
+		ShmPrimaryMcuData->InputDet.bits.Button1 = gpio_in.Button[0];
+		ShmPrimaryMcuData->InputDet.bits.Button2 = gpio_in.Button[1];
+		ShmPrimaryMcuData->InputDet.bits.EmergencyButton = gpio_in.Emergency_Btn;
+
+		//PRINTF_FUNC("left = %d \n", ShmPrimaryMcuData->InputDet.bits.Button1);
+		//PRINTF_FUNC("right = %d \n", ShmPrimaryMcuData->InputDet.bits.Button2);
+		//PRINTF_FUNC("ShmSysConfigAndInfo->SysInfo.AcContactorStatus = %d \n", ShmSysConfigAndInfo->SysInfo.AcContactorStatus);
+		if (ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec == YES)
+			DEBUG_ERROR("AC Mainbreaker occur. \n");
+	}
+}
+
+void SetOutputGpio()
+{
+	Gpio_out gpio;
+	gpio.Button_LED[0] = 0x01;
+	gpio.Button_LED[1] = 0x01;
+
+	gpio.System_LED[0] = 0x00;
+	gpio.System_LED[1] = 0x00;
+	gpio.System_LED[2] = 0x00;
+	gpio.System_LED[3] = 0x00;
+
+	gpio.AC_Connector = 0x00;
+	gpio.AC_Breaker = 0x00;
+
+	if (Config_Gpio_Output(Uart1Fd, Addr.IoExtend, &gpio) == PASS)
+		PRINTF_FUNC("SetOutputGpio sucessfully. \n");
+	else
+		PRINTF_FUNC("SetOutputGpio fail. \n");
+}
+
+void SetRtcData()
+{
+	struct timeb csuTime;
+	struct tm *tmCSU;
+
+	ftime(&csuTime);
+	tmCSU = localtime(&csuTime.time);
+//	PRINTF_FUNC("Time : %04d-%02d-%02d %02d:%02d:%02d \n", tmCSU->tm_year + 1900,
+//			tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
+//			tmCSU->tm_sec);
+
+	rtc.RtcData[0] = '0' + (tmCSU->tm_year + 1900) / 1000 % 10;
+	rtc.RtcData[1] = '0' + (tmCSU->tm_year + 1900) / 100 % 10;
+	rtc.RtcData[2] = '0' + (tmCSU->tm_year + 1900) / 10 % 10;
+	rtc.RtcData[3] = '0' + (tmCSU->tm_year + 1900) / 1 % 10;
+
+	rtc.RtcData[4] = '0' + (tmCSU->tm_mon + 1) / 10 % 10;
+	rtc.RtcData[5] = '0' + (tmCSU->tm_mon + 1) / 1 % 10;
+
+	rtc.RtcData[6] = '0' + (tmCSU->tm_mday) / 10 % 10;
+	rtc.RtcData[7] = '0' + (tmCSU->tm_mday) / 1 % 10;
+
+	rtc.RtcData[8] = '0' + (tmCSU->tm_hour) / 10 % 10;
+	rtc.RtcData[9] = '0' + (tmCSU->tm_hour) / 1 % 10;
+
+	rtc.RtcData[10] = '0' + (tmCSU->tm_min) / 10 % 10;
+	rtc.RtcData[11] = '0' + (tmCSU->tm_min) / 1 % 10;
+
+	rtc.RtcData[12] = '0' + (tmCSU->tm_sec) / 10 % 10;
+	rtc.RtcData[13] = '0' + (tmCSU->tm_sec) / 1 % 10;
+
+	if (Config_Rtc_Data(Uart1Fd, Addr.IoExtend, &rtc) == PASS)
+		PRINTF_FUNC("SetRtc sucessfully. \n");
+	else
+		PRINTF_FUNC("SetRtc fail. \n");
+}
+
+//================================================
+// Main process
+//================================================
+int InitComPort()
+{
+	int fd;
+	struct termios tios;
+
+	fd = open(priPortName, O_RDWR);
+	if(fd<=0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("open 407 Communication port NG \n");
+		#endif
+		return -1;
+	}
+	ioctl (fd, TCGETS, &tios);
+	tios.c_cflag = B115200| CS8 | CLOCAL | CREAD;
+	tios.c_lflag = 0;
+	tios.c_iflag = 0;
+	tios.c_oflag = 0;
+	tios.c_cc[VMIN]=0;
+	tios.c_cc[VTIME]=(unsigned char)1;
+	tios.c_lflag=0;
+	tcflush(fd, TCIFLUSH);
+	ioctl (fd, TCSETS, &tios);
+
+	return fd;
+}
+
+int main(void)
+{
+	if(InitShareMemory() == FAIL)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("InitShareMemory NG\n");
+		#endif
+		if(ShmStatusCodeData!=NULL)
+		{
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
+		}
+		sleep(5);
+		return 0;
+	}
+	Uart1Fd = InitComPort();
+	PRINTF_FUNC("407 Port id = %d \n", Uart1Fd);
+
+	if(Uart1Fd < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("InitComPort (Uart1 : AM3352 - STM32) NG");
+		#endif
+
+		if (ShmStatusCodeData != NULL)
+		{
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
+		}
+		sleep(5);
+		return 0;
+	}
+
+	SetOutputGpio();
+	SetRtcData();
+	for(;;)
+	{
+		// 程序開始之前~ 必須先確定 FW 版本與硬體版本,確認後!!~ 該模組才算是真正的 Initial Comp.
+		// 模組更新 FW 後,需重新做
+		if(ShmPrimaryMcuData->SelfTest_Comp != PASS)
+		{
+			PRINTF_FUNC("(407) Get Fw and Hw Ver. \n");
+			GetFwAndHwVersion();
+			usleep(1000000);
+			ShmPrimaryMcuData->SelfTest_Comp = PASS;
+		}
+		else
+		{
+			GetInputGpioStatus();
+		}
+
+		usleep(100000);
+	}
+
+	return FAIL;
+}
+
+
+
+

BIN
EVSE/Projects/PlugIt360/Apps/Module_PsuComm


+ 1244 - 0
EVSE/Projects/PlugIt360/Apps/Module_PsuComm.c

@@ -0,0 +1,1244 @@
+
+#include 	"Module_PsuComm.h"
+
+#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
+#define PASS				1
+#define FAIL				-1
+#define YES					1
+#define NO					0
+#define DERATING			10
+
+#define SELF_TEST			0
+
+struct SysConfigAndInfo			*ShmSysConfigAndInfo;
+struct StatusCodeData 			*ShmStatusCodeData;
+struct PsuData 					*ShmPsuData;
+
+void trim(char *s);
+int mystrcmp(char *p1,char *p2);
+void substr(char *dest, const char* src, unsigned int start, unsigned int cnt);
+void split(char **arr, char *str, const char *del);
+
+bool libInitialize = false;
+byte gun_count = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
+byte getAvailableCapOffset = 5;
+byte deratingKeepCount = 0;
+
+float carReqVol = 0;
+float carReqCur = 0;
+float evseOutVol = 0;
+float evseOutCur = 0;
+
+int cmdDelayTime = 20000;
+
+void PRINTF_FUNC(char *string, ...);
+
+int StoreLogMsg(const char *fmt, ...);
+#define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+
+unsigned long GetTimeoutValue(struct timeval _sour_time);
+
+unsigned long GetTimeoutValue(struct timeval _sour_time)
+{
+	struct timeval _end_time;
+	gettimeofday(&_end_time, NULL);
+
+	return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
+}
+
+int StoreLogMsg(const char *fmt, ...)
+{
+	char Buf[4096+256];
+	char buffer[4096];
+	time_t CurrentTime;
+	struct tm *tm;
+	va_list args;
+
+	va_start(args, fmt);
+	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
+	va_end(args);
+
+	memset(Buf,0,sizeof(Buf));
+	CurrentTime = time(NULL);
+	tm=localtime(&CurrentTime);
+	sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
+			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
+			buffer,
+			tm->tm_year+1900,tm->tm_mon+1);
+	system(Buf);
+
+	return rc;
+}
+
+int DiffTimeb(struct timeb ST, struct timeb ET)
+{
+	//return milli-second
+	unsigned int StartTime,StopTime;
+
+	StartTime=(unsigned int)ST.time;
+	StopTime=(unsigned int)ET.time;
+	return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
+}
+
+void PRINTF_FUNC(char *string, ...)
+{
+	if (DEBUG)
+	{
+		va_list args;
+		char buffer[4096];
+
+		va_start(args, string);
+		vsnprintf(buffer, sizeof(buffer), string, args);
+		va_end(args);
+		printf("%s \n", buffer);
+	}
+}
+//=================================
+// Common routine
+//=================================
+char* getTimeString(void)
+{
+	char *result=malloc(21);
+	time_t timep;
+	struct tm *p;
+	time(&timep);
+	p=gmtime(&timep);
+
+	sprintf(result, "[%04d-%02d-%02d %02d:%02d:%02d]", (1900+p->tm_year), (1+p->tm_mon), p->tm_mday, p->tm_hour, p->tm_hour, p->tm_sec);
+
+	return result;
+}
+
+void trim(char *s)
+{
+    int i=0, j, k, l=0;
+
+    while((s[i]==' ')||(s[i]=='\t')||(s[i]=='\n'))
+        i++;
+
+    j = strlen(s)-1;
+    while((s[j]==' ')||(s[j]=='\t')||(s[j]=='\n'))
+        j--;
+
+    if(i==0 && j==strlen(s)-1) { }
+    else if(i==0) s[j+1] = '\0';
+    else {
+        for(k=i; k<=j; k++) s[l++] = s[k];
+        s[l] = '\0';
+    }
+}
+
+int mystrcmp(char *p1,char *p2)
+{
+    while(*p1==*p2)
+    {
+        if(*p1=='\0' || *p2=='\0')
+            break;
+        p1++;
+        p2++;
+    }
+    if(*p1=='\0' && *p2=='\0')
+        return(PASS);
+    else
+        return(FAIL);
+}
+
+void substr(char *dest, const char* src, unsigned int start, unsigned int cnt)
+{
+	strncpy(dest, src + start, cnt);
+	dest[cnt] = 0;
+}
+
+void split(char **arr, char *str, const char *del)
+{
+	char *s = strtok(str, del);
+
+	while(s != NULL)
+	{
+		*arr++ = s;
+		s = strtok(NULL, del);
+	}
+}
+
+//=================================
+// ReAssigned PSU Function
+//=================================
+void ReAssignedResource()
+{
+	int index = 0;
+	struct PsuModuleData PsuModule[ShmPsuData->SystemPresentPsuQuantity];
+
+	for (byte i = 0; i < 4; i++)
+	{
+		for(byte psuCount = 0; psuCount < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; psuCount++)
+		{
+			memcpy(&PsuModule[index], &ShmPsuData->PsuGroup[i].PsuModule[psuCount], sizeof(struct PsuModuleData));
+			index++;
+		}
+		ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity = 0;
+	}
+
+	for(int i = 0; i < ShmPsuData->SystemPresentPsuQuantity; i++)
+	{
+		byte group = PsuModule[i].FireWireIndex;
+
+		memcpy(&ShmPsuData->PsuGroup[group].PsuModule[ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity],
+				&PsuModule[i], sizeof(struct PsuModuleData));
+
+		PRINTF_FUNC("ReAssignedResource : PhysicalID = %d, Address = %d, group = %d \n",
+				ShmPsuData->PsuGroup[group].PsuModule[ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity].PhysicalID,
+				ShmPsuData->PsuGroup[group].PsuModule[ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity].Address,
+				group);
+//		printf("ReAssignedResource : PhysicalID = %d, Address = %d, group = %d \n",
+//				ShmPsuData->PsuGroup[group].PsuModule[ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity].PhysicalID,
+//				ShmPsuData->PsuGroup[group].PsuModule[ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity].Address,
+//				group);
+
+		PsuAddressAssignment(ShmPsuData->PsuGroup[group].PsuModule[ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity].PhysicalID,
+				group);
+		ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity++;
+	}
+}
+
+//=================================
+// Save data to share memory Function
+//=================================
+bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
+{
+	for (byte index = 0; index < CHAdeMO_QUANTITY; index++)
+	{
+		if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)
+		{
+			chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
+			return true;
+		}
+	}
+
+	for (byte index = 0; index < CCS_QUANTITY; index++)
+	{
+		if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)
+		{
+			chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
+			return true;
+		}
+	}
+
+	for (byte index = 0; index < GB_QUANTITY; index++)
+	{
+		if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)
+		{
+			chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
+			return true;
+		}
+	}
+
+	return false;
+}
+
+//=================================
+// Alarm code mapping to share memory Function
+//=================================
+// 檢查 Byte 中某個 Bit 的值
+// _byte : 欲改變的 byte
+// _bit : 該 byte 的第幾個 bit
+unsigned char mask_table[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
+unsigned char DetectBitValue(unsigned char _byte, unsigned char _bit)
+{
+	return ( _byte & mask_table[_bit] ) != 0x00;
+}
+
+void AbnormalStopAnalysis(byte gun_index, int errCode)
+{
+	for (char i = 0; i < 3; i++)
+	{
+		unsigned char byteIndex = (errCode >> (8 * i)) & 0xff;
+
+		for (char bitIndex = 0; bitIndex < 8; bitIndex++)
+		{
+			if(DetectBitValue(byteIndex , bitIndex) == 1)
+			{
+				switch(byteIndex)
+				{
+					case 0:
+					{
+						if (bitIndex == 0)
+							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuOutputShortCircuit = YES;
+						else if (bitIndex == 5)
+							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcSideShutDown = YES;
+					}
+						break;
+				case 1:
+					{
+						if (bitIndex == 1)
+							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm = YES;
+						else if (bitIndex == 2)
+							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuProtectionAlarm = YES;
+						else if (bitIndex == 3)
+							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFanFailureAlarm = YES;
+						else if (bitIndex == 4)
+							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuCriticalPointOTP = YES;
+						else if (bitIndex == 5)
+							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcSideShutDown = YES;
+					}
+					break;
+				case 2:
+					{
+						if (bitIndex == 1)
+							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDuplicateID = YES;
+						if (bitIndex == 2)
+							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuThreePhaseOnputImbalance = YES;
+						else if (bitIndex == 3)
+							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuThreePhaseInputInadequate = YES;
+						else if (bitIndex == 4)
+							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuThreePhaseInputInadequate = YES;
+						else if (bitIndex == 5)
+							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuInputUVP = YES;
+						else if (bitIndex == 6)
+							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuInputOVP = YES;
+					}
+					break;
+				}
+			}
+			else
+			{
+				switch (byteIndex) {
+				case 0: {
+					if (bitIndex == 0)
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuOutputShortCircuit = NO;
+					else if (bitIndex == 5)
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcSideShutDown = NO;
+				}
+					break;
+				case 1: {
+					if (bitIndex == 1)
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm = NO;
+					else if (bitIndex == 2)
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuProtectionAlarm = NO;
+					else if (bitIndex == 3)
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFanFailureAlarm = NO;
+					else if (bitIndex == 4)
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuCriticalPointOTP = NO;
+					else if (bitIndex == 5)
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcSideShutDown = NO;
+				}
+					break;
+				case 2: {
+					if (bitIndex == 1)
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDuplicateID = NO;
+					if (bitIndex == 2)
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuThreePhaseOnputImbalance = NO;
+					else if (bitIndex == 3)
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuThreePhaseInputInadequate = NO;
+					else if (bitIndex == 4)
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuThreePhaseInputInadequate = NO;
+					else if (bitIndex == 5)
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuInputUVP = NO;
+					else if (bitIndex == 6)
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuInputOVP = NO;
+				}
+					break;
+				}
+			}
+		}
+	}
+}
+
+//=================================
+// Callback Function
+//=================================
+void GetPsuRequestCallback(byte phy_id, char *serial_number)
+{
+	if (ShmSysConfigAndInfo->SysInfo.AcContactorStatus == NO)
+		return;
+
+	// ********************** 每次送電後,需判斷要把所有的模塊分配到哪個 Group **********************
+	byte group = 0;
+	if(ShmSysConfigAndInfo->SysInfo.BootingStatus == BOOTTING || gun_count == 1)
+	{
+		// 初始化狀態,則直接先分配到同個群
+		group = 0;
+	}
+	else
+	{
+		group = ShmSysConfigAndInfo->SysInfo.CurGunSelected;
+	}
+
+	bool isNewPsu = true;
+	for (byte index = 0; index < ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity; index++)
+	{
+		if (ShmPsuData->PsuGroup[group].PsuModule[index].PhysicalID == phy_id &&
+			strncmp((char *)ShmPsuData->PsuGroup[group].PsuModule[index].SerialNumber, serial_number, 7) == 0)
+		{
+			isNewPsu = false;
+		}
+	}
+
+	if (isNewPsu)
+	{
+		ShmPsuData->SystemPresentPsuQuantity++;
+		PRINTF_FUNC("get psu********Membar = %d, group = %d \n", ShmPsuData->SystemPresentPsuQuantity, group);
+
+		if (ShmPsuData->Work_Step >= _TEST_LINE_STEP && ShmPsuData->Work_Step <= _TEST_COMPLETE)
+		{
+			// 已經進入火線上的驗證動作
+			//ShmPsuData->NeedBackTest = YES;
+		}
+		else if (ShmPsuData->Work_Step == _WORK_CHARGING)
+		{
+			// 一旦進入火線,分配一個不會用到的給該模塊
+			group++;
+		}
+
+		ShmPsuData->PsuGroup[group].PsuModule[ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity].Address = ShmPsuData->SystemPresentPsuQuantity;
+		ShmPsuData->PsuGroup[group].PsuModule[ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity].PhysicalID = phy_id;
+		ShmPsuData->PsuGroup[group].PsuModule[ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity].AssignID = (group >> 6) + ShmPsuData->SystemPresentPsuQuantity;
+		strcpy((char *)ShmPsuData->PsuGroup[group].PsuModule[ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity].SerialNumber, serial_number);
+		ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity++;
+
+		byte isFind = false;
+		for (byte index = 0; index < conn_1_count; index++)
+		{
+			PRINTF_FUNC("connector_1[%d] = %d, phy_id = %d \n", index, connector_1[index], phy_id);
+			if (connector_1[index] == phy_id)
+			{
+				isFind = true;
+				ShmPsuData->PsuGroup[group].PsuModule[ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity].FireWireIndex = 0;
+				break;
+			}
+		}
+
+		if (!isFind)
+		{
+			for (byte index = 0; index < conn_2_count; index++)
+			{
+				PRINTF_FUNC("connector_2[%d] = %d, phy_id = %d \n", index, connector_2[index], phy_id);
+				if (connector_2[index] == phy_id)
+				{
+					isFind = true;
+					ShmPsuData->PsuGroup[group].PsuModule[ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity].FireWireIndex = 1;
+					break;
+				}
+			}
+		}
+
+		//PsuAddressAssignment(phy_id, serial_number, ShmPsuData->SystemPresentPsuQuantity, group);
+		PsuAddressAssignment(phy_id, group);
+
+		if (ShmPsuData->Work_Step != _WORK_CHARGING)
+		{
+			ShmPsuData->GroupCount = group + 1;
+		}
+	}
+}
+
+void SaveStatusCallback(byte group, byte address, char cri_temp1, int alarm)
+{
+	//EVSE
+	for (byte index = 0; index < ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity; index++)
+	{
+		if (ShmPsuData->PsuGroup[group].PsuModule[index].PhysicalID == address)
+	    {
+			ShmPsuData->PsuGroup[group].PsuModule[index].CriticalTemp1 = cri_temp1;
+	    	ShmPsuData->PsuGroup[group].PsuModule[index].AlarmCode = alarm;
+	    	AbnormalStopAnalysis(group, alarm);
+	    	break;
+	    }
+	}
+}
+
+//模組三向輸入電壓
+void SavePresentInputVoltageCallback(byte address, unsigned short vol1, unsigned short vol2, unsigned short vol3)
+{
+	//EVSE
+	//search group
+    for (byte groupIndex = 0; groupIndex < ShmPsuData->GroupCount; groupIndex++)
+    { 
+    	for (byte index = 0; index < ShmPsuData->PsuGroup[groupIndex].GroupPresentPsuQuantity; index++)
+    	{
+    	    //search id
+    		if (ShmPsuData->PsuGroup[groupIndex].PsuModule[index].PhysicalID == address)
+    		{
+    		    //update module msg
+    			ShmPsuData->PsuGroup[groupIndex].PsuModule[index].InputVoltageL1 = vol1;
+    			ShmPsuData->PsuGroup[groupIndex].PsuModule[index].InputVoltageL2 = vol2;
+    			ShmPsuData->PsuGroup[groupIndex].PsuModule[index].InputVoltageL3 = vol3;
+    			break;
+    		}
+    	}
+    }
+}
+
+// 模塊輸出的電壓電流
+void SavePresentOutputCallback(byte address, unsigned short out_vol, unsigned short out_cur)
+{
+	unsigned short outputVol = 0;
+	unsigned short outputCur = 0;
+	unsigned short group = 0;
+	bool isChange = false;
+
+	// PSU
+	for (byte groupIndex = 0; groupIndex < ShmPsuData->GroupCount; groupIndex++)
+    {
+    	for (int index = 0; index < ShmPsuData->PsuGroup[groupIndex].GroupPresentPsuQuantity; index++)
+    	{
+    		if (ShmPsuData->PsuGroup[groupIndex].PsuModule[index].PhysicalID == address)
+    		{
+    		    //如果英飛源模組不是 ver1.09 版使用模組輸出電壓
+    		    /*
+    			if(InfyPwrModelVerIs109 == 0)
+    			{
+    			    ShmPsuData->PsuGroup[groupIndex].PsuModule[index].PresentOutputVoltage = out_vol;
+    			}
+    			*/
+    			ShmPsuData->PsuGroup[groupIndex].PsuModule[index].PresentOutputVoltage = out_vol;
+    			ShmPsuData->PsuGroup[groupIndex].PsuModule[index].PresentOutputCurrent = out_cur;   			
+    			
+    		    for (int loop = 0; loop < ShmPsuData->PsuGroup[groupIndex].GroupPresentPsuQuantity; loop++)
+    		    {
+    		        //update voltage
+   		            if (ShmPsuData->PsuGroup[groupIndex].PsuModule[loop].PresentOutputVoltage > outputVol)
+   		            {
+    			        outputVol = ShmPsuData->PsuGroup[groupIndex].PsuModule[loop].PresentOutputVoltage;
+    			    }
+    			    //update total current
+    			    outputCur += ShmPsuData->PsuGroup[groupIndex].PsuModule[index].PresentOutputCurrent;
+    			    group = groupIndex;
+    			    isChange = true;
+    		    }
+    		}
+
+            /*
+    		if (ShmPsuData->PsuGroup[group].PsuModule[index].PresentOutputVoltage > outputVol)
+    			outputVol = ShmPsuData->PsuGroup[group].PsuModule[index].PresentOutputVoltage;
+
+    		outputCur += ShmPsuData->PsuGroup[group].PsuModule[index].PresentOutputCurrent;
+    		*/
+    	}
+    }
+
+	if (isChange)
+	{
+		// PSU Group
+		// 電壓
+		ShmPsuData->PsuGroup[group].GroupPresentOutputVoltage = outputVol;
+		// 電流
+		ShmPsuData->PsuGroup[group].GroupPresentOutputCurrent = outputCur;
+
+		//EVSE - 槍端的輸出電壓
+		chargingInfo[group]->PresentChargingVoltage = ShmPsuData->PsuGroup[group].GroupPresentOutputVoltage;
+		//EVSE - 槍端的輸出電流
+		chargingInfo[group]->PresentChargingCurrent = ShmPsuData->PsuGroup[group].GroupPresentOutputCurrent;
+	}
+
+	//printf("GroupPresentOutputVoltage = %d \n", ShmPsuData->PsuGroup[group].GroupPresentOutputVoltage);
+	//printf("GroupPresentOutputCurrent = %d \n", ShmPsuData->PsuGroup[group].GroupPresentOutputCurrent);
+}
+
+//PSU able_power = KW (單位 0.1) exp. 300 = 30kw
+//PSU able_cur = A (單位 0.1) exp. 400 = 40A
+void SaveAvailableCapCallback(byte address, unsigned short maxv, unsigned short minv, unsigned short able_cur, unsigned short able_power)
+{
+	unsigned int power = 0;
+	unsigned int current = 0;
+	unsigned int power_derating = 0;
+	unsigned int current_derating = 0;
+	unsigned int group = 0;
+	bool isChange = false;
+	//bool sameGroup = false;
+
+    //search group
+	//printf("GroupCount = %d \n", ShmPsuData->GroupCount);
+    for (byte groupIndex = 0; groupIndex < ShmPsuData->GroupCount; groupIndex++)
+    {        
+    	//printf("GroupPresentPsuQuantity = %d \n", ShmPsuData->PsuGroup[groupIndex].GroupPresentPsuQuantity);
+    	for (int index = 0; index < ShmPsuData->PsuGroup[groupIndex].GroupPresentPsuQuantity; index++)
+    	{
+    	    //search group-id
+    		//printf("PhysicalID = %d, address = %d \n", ShmPsuData->PsuGroup[groupIndex].PsuModule[index].PhysicalID, address);
+    		if (ShmPsuData->PsuGroup[groupIndex].PsuModule[index].PhysicalID == address)
+    		{
+    		    //先更新該模組資訊    
+    			ShmPsuData->PsuGroup[groupIndex].PsuModule[index].AvailablePower = able_power;
+
+    			//電壓在 150V 時使用額定電流
+    			if(ShmPsuData->PsuGroup[groupIndex].PsuModule[index].PresentOutputVoltage < 1500)
+    			{
+    			    ShmPsuData->PsuGroup[groupIndex].PsuModule[index].AvailableCurrent = able_cur;
+    			}
+    			//如果英飛源模組不是 ver1.09 版 或 (如果英飛源模組是 ver1.09 版但回應可輸出電流有誤則使用額定報文可輸出電流)
+    			/*
+    			if(InfyPwrModelVerIs109 == 0 ||
+    			    (InfyPwrModelVerIs109 == 1 && ShmPsuData->PsuGroup[groupIndex].PsuModule[index].AvailableCurrent == 0))
+    			{
+    			        ShmPsuData->PsuGroup[groupIndex].PsuModule[index].AvailableCurrent = able_cur;
+    			}
+    			*/
+    		    //該對應的模組群重新計算總合		    
+    		    for (int loop = 0; loop < ShmPsuData->PsuGroup[groupIndex].GroupPresentPsuQuantity; loop++)
+    		    {
+    		    	// 降載
+//    		    	if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_GET_NEW_CAP &&
+//    		    			ShmSysConfigAndInfo->SysInfo.ReAssignedFlag < _REASSIGNED_COMP)
+//    		    	{
+//    		    		if (ShmPsuData->PsuGroup[group].PsuModule[index].FireWireIndex == group)
+//    		    		{
+//    		    			power_derating += ShmPsuData->PsuGroup[group].PsuModule[index].AvailablePower;
+//    		    			current_derating += ShmPsuData->PsuGroup[group].PsuModule[index].AvailableCurrent;
+//    		    		}
+//    		    	}
+
+    		        power += ShmPsuData->PsuGroup[groupIndex].PsuModule[loop].AvailablePower;
+    			    current += ShmPsuData->PsuGroup[groupIndex].PsuModule[loop].AvailableCurrent;
+    			    group = groupIndex;
+    			    isChange = true;
+    		    }
+    		}
+    	}
+    }
+    
+    if (current_derating == 0)
+    {
+    	current_derating = current;
+    }
+
+    if (power_derating == 0)
+    {
+    	power_derating = power;
+    }
+
+	if (isChange)
+	{
+		// PSU Group
+		// Available Power
+		ShmPsuData->PsuGroup[group].GroupAvailablePower = power;
+		// Available Current
+		ShmPsuData->PsuGroup[group].GroupAvailableCurrent = current;
+
+		chargingInfo[group]->MaximumChargingVoltage = maxv;
+		chargingInfo[group]->AvailableChargingCurrent =	ShmPsuData->PsuGroup[group].GroupAvailableCurrent;
+		chargingInfo[group]->AvailableChargingPower = ShmPsuData->PsuGroup[group].GroupAvailablePower;
+		chargingInfo[group]->DeratingChargingCurrent = current_derating;
+		chargingInfo[group]->DeratingChargingPower = power_derating;
+
+		PRINTF_FUNC("group = %d, AvailableChargingCurrent = %f, GroupAvailablePower = %f, DeratingChargingCurrent = %f, DeratingChargingPower = %f \n",
+							group, chargingInfo[group]->AvailableChargingCurrent, chargingInfo[group]->AvailableChargingPower,
+							chargingInfo[group]->DeratingChargingCurrent, chargingInfo[group]->DeratingChargingPower);
+	}
+}
+
+void GetBarCodeCallback(byte address, char *serial_number , unsigned short module_ver)
+{
+	//EVSE
+	for (byte groupIndex = 0; groupIndex < ShmPsuData->GroupCount; groupIndex++)
+	{
+    	for (byte index = 0; index < ShmPsuData->PsuGroup[groupIndex].GroupPresentPsuQuantity; index++)
+    	{
+    		if (ShmPsuData->PsuGroup[groupIndex].PsuModule[index].PhysicalID == address)
+    		{
+    		    ShmPsuData->PsuGroup[groupIndex].PsuModule[index].FwVersion[0] = (module_ver >> 8) & 0xFF;
+    			ShmPsuData->PsuGroup[groupIndex].PsuModule[index].FwVersion[1] = (module_ver) & 0xFF;
+    		    //strcpy((char *)ShmPsuData->PsuGroup[groupIndex].PsuModule[ShmPsuData->PsuGroup[groupIndex].GroupPresentPsuQuantity].SerialNumber, serial_number);
+    		}
+    	}
+	}
+}
+
+void GetMiscInfoCallback(byte address, unsigned short CmdType , unsigned int value)
+{
+	//EVSE
+	for (byte groupIndex = 0; groupIndex < ShmPsuData->GroupCount; groupIndex++)
+    {
+    	for (byte index = 0; index < ShmPsuData->PsuGroup[groupIndex].GroupPresentPsuQuantity; index++)
+    	{
+    		if (ShmPsuData->PsuGroup[groupIndex].PsuModule[index].PhysicalID == address)
+    		{
+    		    if(CmdType == MISC_REQCMD_DC_BOARD_TMP){
+    		        //數值未處理
+    		        ShmPsuData->PsuGroup[groupIndex].PsuModule[index].CriticalTemp2 = (byte)value;
+    		    }else if(CmdType == MISC_REQCMD_PFC_BOARD_TMP){
+    		        //數值未處理
+    		        ShmPsuData->PsuGroup[groupIndex].PsuModule[index].CriticalTemp3 = (byte)value;
+    		    }else if(CmdType == MISC_REQCMD_FAN_SPEED){
+    		        //數值未處理
+    		        ShmPsuData->PsuGroup[groupIndex].PsuModule[index].FanSpeed_1 = (unsigned short)value;
+    		    }
+    		}
+    	}
+	}
+
+	//暫定如果有回 misc 就認定英飛源為 1.9 版
+	//InfyPwrModelVerIs109 = 1;
+	//printf("Get Misc : %d \n",InfyPwrModelVerIs109);
+}
+
+void SaveHardwareVersion(byte group, byte address, int hw_ver)
+{
+	//EVSE
+	for (byte index = 0; index < ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity; index++)
+	{
+		if (ShmPsuData->PsuGroup[group].PsuModule[index].Address == address)
+		{
+			ShmPsuData->PsuGroup[group].PsuModule[index].FwVersion[0] = (hw_ver >> 24) & 0xFF;
+			ShmPsuData->PsuGroup[group].PsuModule[index].FwVersion[1] = (hw_ver >> 16) & 0xFF;
+			ShmPsuData->PsuGroup[group].PsuModule[index].FwVersion[2] = (hw_ver >> 8) & 0xFF;
+			ShmPsuData->PsuGroup[group].PsuModule[index].FwVersion[3] = hw_ver & 0xFF;
+			break;
+		}
+	}
+}
+
+
+//Vext      模組二極體後電壓
+//Iavail    模組目前因環境因素的真實能輸出電流
+void SavePresentModeleVextIavailCallback(byte address, unsigned short Vext, unsigned short Iavail)
+{
+	//EVSE
+	//search group
+    for (byte groupIndex = 0; groupIndex < ShmPsuData->GroupCount; groupIndex++)
+    {
+    	for (byte index = 0; index < ShmPsuData->PsuGroup[groupIndex].GroupPresentPsuQuantity; index++)
+    	{
+    	    //search id
+    		if (ShmPsuData->PsuGroup[groupIndex].PsuModule[index].PhysicalID == address)
+    		{
+    		    //update module msg
+    		    //ShmPsuData->PsuGroup[groupIndex].PsuModule[index].PresentOutputVoltage = Vext;
+    		    //
+    		    if(ShmPsuData->PsuGroup[groupIndex].PsuModule[index].PresentOutputVoltage >= 1500)
+    		    {
+    			    ShmPsuData->PsuGroup[groupIndex].PsuModule[index].AvailableCurrent = Iavail;
+    			}
+    			//printf("Vext = %d I = %d \n", Vext,Iavail);
+    			break;
+    		}
+    	}
+    }
+}
+
+void GetOutputPowerSwitchStatusCallback(byte address, unsigned char value)
+{
+    for (byte groupIndex = 0; groupIndex < ShmPsuData->GroupCount; groupIndex++)
+    {
+    	for (byte index = 0; index < ShmPsuData->PsuGroup[groupIndex].GroupPresentPsuQuantity; index++)
+    	{
+    		if (ShmPsuData->PsuGroup[groupIndex].PsuModule[index].PhysicalID == address)
+    		{
+    			//printf("PowerSwitch = %d, group = %d, address = %d \n", value, group, address);
+    			if(value){
+    			    ShmPsuData->PsuGroup[groupIndex].PsuModule[index].OutputPowerSwitch = 0x00;
+    			}else{
+    			    ShmPsuData->PsuGroup[groupIndex].PsuModule[index].OutputPowerSwitch = 0x01;
+    			}
+    			
+    			break;
+    		}
+    	}
+    }
+}
+
+//==========================================
+// Init all share memory
+//==========================================
+int InitShareMemory()
+{
+	int result = PASS;
+	int MeterSMId;
+
+	//creat ShmSysConfigAndInfo
+	if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0)
+    {
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmget ShmSysConfigAndInfo NG %d \n");
+		#endif
+		result = FAIL;
+	}
+    else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+    {
+    	#ifdef SystemLogMessage
+    	DEBUG_ERROR("shmat ShmSysConfigAndInfo NG \n");
+		#endif
+    	result = FAIL;
+   	 }
+    else
+    {}
+
+   	//creat ShmStatusCodeData
+   	if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0)
+    {
+		#ifdef SystemLogMessage
+   		DEBUG_ERROR("shmget ShmStatusCodeData NG \n");
+		#endif
+   		result = FAIL;
+	}
+    else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+    {
+    	#ifdef SystemLogMessage
+    	DEBUG_ERROR("shmat ShmStatusCodeData NG \n");
+		#endif
+    	result = FAIL;
+   	}
+    else
+    {}
+
+   	//creat ShmPsuData
+	if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData),  0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmget ShmPsuData NG \n");
+		#endif
+		result = FAIL;
+	}
+	else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmat ShmPsuData NG \n");
+		#endif
+		result = FAIL;
+	 }
+	memset(ShmPsuData,0,sizeof(struct PsuData));
+
+    return result;
+}
+
+//================================================
+// Main process
+//================================================
+void InitialPsuData()
+{
+	ShmPsuData->SystemPresentPsuQuantity = 0;
+
+	for (byte _groupCount = 0; _groupCount < ARRAY_SIZE(ShmPsuData->PsuGroup);	_groupCount++)
+	{
+		ShmPsuData->PsuGroup[_groupCount].GroupPresentPsuQuantity = 0;
+		ShmPsuData->PsuGroup[_groupCount].GroupAvailablePower = 0;
+		ShmPsuData->PsuGroup[_groupCount].GroupAvailableCurrent = 0;
+	}
+	
+	ShmPsuData->Work_Step = _INIT_PSU_STATUS;
+}
+
+void Initialization()
+{
+	bool isPass = false;
+	while(!isPass)
+	{
+		isPass = true;
+		for (byte _index = 0; _index < _gunCount; _index++)
+		{
+			if (!FindChargingInfoData(_index, &chargingInfo[0]))
+			{
+				DEBUG_ERROR("EvComm (main) : FindChargingInfoData false \n");
+				isPass = false;
+				break;
+			}
+		}
+	}
+	conn_1_count = sizeof(connector_1)/sizeof(connector_1[0]);
+	conn_2_count = sizeof(connector_2)/sizeof(connector_2[0]);
+}
+
+int main(void)
+{
+	PRINTF_FUNC("Psu Task boot .... \n");
+	if(InitShareMemory() == FAIL)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("InitShareMemory NG\n");
+		#endif
+		if(ShmStatusCodeData != NULL)
+		{
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
+		}
+		sleep(5);
+		return 0;
+	}
+
+	PRINTF_FUNC("InitShareMemory OK\n");
+
+	// register callback function
+	GetPsuAddressReq(&GetPsuRequestCallback);
+	RefreshSerialNumber(&GetBarCodeCallback);
+	RefreshVextAndIavail(&SavePresentModeleVextIavailCallback);
+	RefreshMiscInfo(&GetMiscInfoCallback);
+
+	RefreshStatus(&SaveStatusCallback);
+	RefreshInputVol(&SavePresentInputVoltageCallback);
+	RefreshGetOutput(&SavePresentOutputCallback);
+	RefreshAvailableCap(&SaveAvailableCapCallback);
+	RefreshOutputPowerSwitch(&GetOutputPowerSwitchStatusCallback);
+
+	// initial object
+	InitialPsuData();
+	Initialization();
+	libInitialize = InitialCommunication();
+
+    byte priorityLow = 1;
+    byte isInitialComp = NO;
+	//main loop
+	while (libInitialize)
+	{
+		// 斷電狀態
+		if (ShmSysConfigAndInfo->SysInfo.AcContactorStatus == NO)
+		{
+			//一但 AC Off PSU 斷電全部的 PSU Group ID 會全部清 0
+			if (!isInitialComp)
+			{
+				InitialPsuData();
+				ShmPsuData->Work_Step = ASSIGN_START;
+				isInitialComp = YES;
+			}
+			sleep(1);
+			continue;
+		}
+		else
+			isInitialComp = NO;
+
+		// update psu fw req
+//		if(psu update req ?)
+//		{
+//
+//			continue;
+//		}
+
+		// 自檢失敗
+		if (ShmPsuData->Work_Step == _NO_WORKING)
+		{
+			PRINTF_FUNC("== PSU == self test fail. \n");
+			sleep(5);
+		}
+
+		switch(ShmPsuData->Work_Step)
+		{
+			case ASSIGN_START:
+			{
+				PRINTF_FUNC("== PSU == ASSIGN_COMP \n");
+				sleep(5);
+				gettimeofday(&_id_assign_time, NULL);
+				ShmPsuData->Work_Step = ASSIGN_COMP;
+			}
+				break;
+			case ASSIGN_COMP:
+			{
+				if (priorityLow == 1)
+				{
+					//如果還未取得模組數量
+					if(ShmPsuData->SystemPresentPsuQuantity == 0)
+					{
+						EnableDipAddrMode();
+						usleep(cmdDelayTime);
+				        //發送取得目前全部模組數量 (英飛源開機須等待讓模組互相通訊)
+				        RequestModuleTotalMumbert();
+				        usleep(cmdDelayTime);
+					}
+					//己取得模組數量 (目前還未分配群組所以都使用預設 0)
+					else
+					{
+				    	for (byte psuIndex = 0;	psuIndex < ShmPsuData->PsuGroup[0].GroupPresentPsuQuantity;	psuIndex++)
+				    	{
+				            //get status
+				    		GetStatus(0, NONE_CARE_ADDRESS);
+				    		usleep(cmdDelayTime);
+				            //get barcode & ver
+				    		GetSerialNumber(0, NONE_CARE_ADDRESS);
+				    		usleep(cmdDelayTime);
+
+				    		GetMiscInfo(0, NONE_CARE_ADDRESS, MISC_REQCMD_DC_BOARD_TMP);
+				    		usleep(cmdDelayTime);
+				    		GetMiscInfo(0, NONE_CARE_ADDRESS, MISC_REQCMD_PFC_BOARD_TMP);
+				    		usleep(cmdDelayTime);
+				    		GetMiscInfo(0, NONE_CARE_ADDRESS, MISC_REQCMD_PFC_BOARD_TMP);
+				    		usleep(cmdDelayTime);
+				    	}
+					}
+					//printf("Get Misc2 : %d \n",InfyPwrModelVerIs109);
+				}
+
+				priorityLow >= 20 ? priorityLow = 1 : priorityLow++;
+				// 等待 10 秒
+				if (GetTimeoutValue(_id_assign_time) >= 10000000)
+				{
+					ShmPsuData->Work_Step = ENABLE_POW;
+					PRINTF_FUNC("INFYPWR Num = %d \n", ShmPsuData->SystemPresentPsuQuantity);
+					PRINTF_FUNC("== PSU == ENABLE_POW \n");
+				}
+			}
+				break;
+			case ENABLE_POW:
+			{
+				if (ShmSysConfigAndInfo->SysInfo.BootingStatus == BOOTTING)
+				{
+					// 電樁在 Booting 的狀態 - 自檢
+					PRINTF_FUNC("== PSU == _TEST_LINE_STEP \n");
+					ShmPsuData->Work_Step = _TEST_LINE_STEP;
+				}
+				else
+				{
+					PRINTF_FUNC("== PSU == _WORK_CHARGING \n");
+					ShmPsuData->Work_Step = _WORK_CHARGING;
+					gettimeofday(&_workModePriority_time, NULL);
+				}
+			}
+				break;
+			case _TEST_LINE_STEP:
+			{
+				PRINTF_FUNC("cur total psu count = %d \n", ShmPsuData->SystemPresentPsuQuantity);
+				if (ShmPsuData->PsuGroup[0].GroupPresentPsuQuantity <= 0)
+				{
+					sleep(1);
+					// 顯示錯誤
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = YES;
+					continue;
+				}
+
+				ShmPsuData->Work_Step = _TEST_POWER_STEP;
+			}
+				break;
+			case _TEST_POWER_STEP:
+			{
+				if(!_chkTotalCapStart)
+				{
+					_chkTotalCapStart = true;
+					gettimeofday(&_chk_cap_time, NULL);
+				}
+
+				// 初始化、關閉所有的模塊
+				//EnableOutputPower(0, NONE_CARE_ADDRESS, SWITCH_OFF);
+				for (byte groupIndex = 0; groupIndex < ShmPsuData->GroupCount; groupIndex++)
+				{
+					GetStatus(groupIndex, NONE_CARE_ADDRESS);
+					usleep(cmdDelayTime);
+				}
+
+				for (byte psuCount = 0; psuCount < ShmPsuData->SystemPresentPsuQuantity; psuCount++)
+				{
+					GetAvailableCap(psuCount, NONE_CARE_ADDRESS,  0);
+				}
+
+				usleep(cmdDelayTime);
+				if (GetTimeoutValue(_chk_cap_time) >= 2000000)
+				{
+					PRINTF_FUNC("AvailableChargingCurrent = %f, AvailableChargingPower = %f \n",
+							chargingInfo[0]->AvailableChargingCurrent, chargingInfo[0]->AvailableChargingPower);
+					for (byte index = 0; index < ShmPsuData->PsuGroup[0].GroupPresentPsuQuantity; index++)
+					{
+						PRINTF_FUNC("index = %d, fire index = %d, phy addr = %d \n",
+								index, recordPsuData[index]._fire_index, recordPsuData[index]._phy_addr);
+					}
+
+					PRINTF_FUNC("== PSU == TEST_COMPLETE \n");
+					ShmPsuData->Work_Step = _TEST_COMPLETE;
+				}
+			}
+				break;
+			case _TEST_COMPLETE:
+			{
+			    priorityLow = 1;
+				sleep(1);
+			}
+				break;
+			case _WORK_CHARGING:
+			{
+				int time = GetTimeoutValue(_workModePriority_time) / 1000;
+				//printf("GroupCount = %d \n", ShmPsuData->GroupCount);
+				//printf("cur total psu count = %d \n", ShmPsuData->SystemPresentPsuQuantity);
+
+				// 智能分配 : 檢查該槍是否有模塊有用,有則無須重新分配直接進入充電
+				if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_PREPARE)
+				{
+					if (ShmPsuData->PsuGroup[ShmSysConfigAndInfo->SysInfo.CurGunSelected].GroupPresentPsuQuantity > 0)
+					{
+						PRINTF_FUNC("=============Smart Charging : _REASSIGNED_NONE============= Step 0 \n");
+						ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
+					}
+					else
+					{
+						PRINTF_FUNC("=============Smart Charging : _REASSIGNED_GET_NEW_CAP============= Step 2 \n");
+						ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_GET_NEW_CAP;
+					}
+				}
+
+				if (time > 1000)
+				{
+					for (byte psuCount = 0; psuCount < ShmPsuData->GroupCount; psuCount++)
+					{
+						GetAvailableCap(psuCount, NONE_CARE_ADDRESS,  0);
+					}
+					usleep(cmdDelayTime);
+				}
+
+				for (byte groupIndex = 0; groupIndex < ShmPsuData->GroupCount; groupIndex++)
+				{
+					if (time > 1000)
+					{
+						GetStatus(groupIndex, NONE_CARE_ADDRESS);
+						usleep(cmdDelayTime);
+					    /*
+    					GetMiscInfo(SET_GROUP_CMD, 0, MISC_REQCMD_DC_BOARD_TMP);
+    					usleep(cmdDelayTime);
+    					GetMiscInfo(SET_GROUP_CMD, 0, MISC_REQCMD_PFC_BOARD_TMP);
+    					usleep(cmdDelayTime);
+    					GetMiscInfo(SET_GROUP_CMD, 0, MISC_REQCMD_PFC_BOARD_TMP);
+    					usleep(cmdDelayTime);
+    					*/
+//						if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_GET_NEW_CAP)
+//						{
+//							if (groupIndex != ShmSysConfigAndInfo->SysInfo.CurGunSelected)
+//							{
+//								if (chargingInfo[groupIndex]->SystemStatus >= S_CHARGING &&	chargingInfo[groupIndex]->SystemStatus <= S_COMPLETE)
+//								{
+//									if (chargingInfo[groupIndex]->DeratingChargingCurrent < chargingInfo[groupIndex]->AvailableChargingCurrent)
+//									{
+//										// 車端需求電流降低至降載的電流
+//										PRINTF_FUNC("Smart Charging : index = %d, EvBatterytargetCurrent = %f, DeratingChargingCurrent = %f \n",
+//										groupIndex, chargingInfo[groupIndex]->EvBatterytargetCurrent, chargingInfo[groupIndex]->DeratingChargingCurrent);
+//
+//										if ((chargingInfo[groupIndex]->EvBatterytargetCurrent <= chargingInfo[groupIndex]->DeratingChargingCurrent) ||
+//											deratingKeepCount >= DERATING)
+//										{
+//											// 車端降載完成
+//											PRINTF_FUNC("=============Smart Charging : _REASSIGNED_MAIN============= Step 3 \n");
+//											ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_MAIN;
+//										}
+//										else
+//										{
+//											deratingKeepCount++;
+//										}
+//									}
+//								}
+//							}
+//						}
+//						else
+//							deratingKeepCount = 0;
+//
+//						if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_MAIN)
+//						{
+//							PRINTF_FUNC("=============Smart Charging : _REASSIGNED_ADJUST============= Step 4 \n");
+//							//重新分配模組
+//							ReAssignedResource();
+//							gettimeofday(&_derating_time, NULL);
+//							ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_ADJUST;
+//						}
+
+						gettimeofday(&_workModePriority_time, NULL);
+					}
+
+					GetPresentOutput(groupIndex, NONE_CARE_ADDRESS);
+					usleep(cmdDelayTime);
+					//GetVextAndIavail(SET_MODULE_CMD, 0);
+
+					if (chargingInfo[groupIndex]->EvBatterytargetVoltage > 0 &&
+							carReqVol != chargingInfo[groupIndex]->EvBatterytargetVoltage)
+					{
+						carReqVol = chargingInfo[groupIndex]->EvBatterytargetVoltage;
+						DEBUG_INFO("ev need vol = %f \n", chargingInfo[groupIndex]->EvBatterytargetVoltage);
+					}
+
+					if (chargingInfo[groupIndex]->EvBatterytargetCurrent > 0 &&
+							carReqCur != chargingInfo[groupIndex]->EvBatterytargetCurrent)
+					{
+						carReqCur = chargingInfo[groupIndex]->EvBatterytargetCurrent;
+						DEBUG_INFO("ev need cur = %f \n", chargingInfo[groupIndex]->EvBatterytargetCurrent);
+					}
+
+					if (chargingInfo[groupIndex]->FireChargingVoltage > 0 &&
+							evseOutVol != chargingInfo[groupIndex]->FireChargingVoltage)
+					{
+						evseOutVol = chargingInfo[groupIndex]->FireChargingVoltage;
+						PRINTF_FUNC("groupIndex = %d, evse output vol = %f \n", groupIndex,	chargingInfo[groupIndex]->FireChargingVoltage);
+					}
+
+					if (chargingInfo[groupIndex]->PresentChargingCurrent > 0 &&
+							evseOutCur != chargingInfo[groupIndex]->PresentChargingCurrent)
+					{
+						evseOutCur = chargingInfo[groupIndex]->PresentChargingCurrent;
+						PRINTF_FUNC("groupIndex = %d, evse output cur = %f \n", groupIndex, chargingInfo[groupIndex]->PresentChargingCurrent);
+					}
+
+					// 針對各槍當前狀態,傳送需要回傳的資料指令
+					if (((chargingInfo[groupIndex]->SystemStatus >= S_PREPARING_FOR_EVSE && chargingInfo[groupIndex]->SystemStatus <= S_CHARGING) && chargingInfo[groupIndex]->RelayK1K2Status) ||
+							chargingInfo[groupIndex]->SystemStatus == S_REASSIGN ||
+							(chargingInfo[groupIndex]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[groupIndex]->SystemStatus <= S_CCS_PRECHARGE_ST1))
+					{
+						if (ShmPsuData->PsuGroup[groupIndex].GroupAvailableCurrent > 0)
+						{
+//							if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_ADJUST &&
+//									ShmSysConfigAndInfo->SysInfo.ReAssignedFlag < _REASSIGNED_COMP )
+//							{
+//								// 如果車端要求的電流超過降載,則以降載電流為主
+//								if (chargingInfo[groupIndex]->EvBatterytargetCurrent >= chargingInfo[groupIndex]->DeratingChargingCurrent)
+//								{
+//									chargingInfo[groupIndex]->EvBatterytargetCurrent = chargingInfo[groupIndex]->DeratingChargingCurrent;
+//								}
+//
+//								if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_ADJUST)
+//								{
+//									deratingTime = GetTimeoutValue(_derating_time) / 1000;
+//									if (deratingTime > 3000)
+//									{
+//										deratingTime = 0;
+//										PRINTF_FUNC("=============Smart Charging : _REASSIGNED_RELAY============= Step 5 \n");
+//										ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_RELAY;
+//									}
+//
+//									for(int i = 0; i < ShmPsuData->PsuGroup[groupIndex].GroupPresentPsuQuantity; i++)
+//									{
+//										PRINTF_FUNC("*********_REASSIGNED_ADJUST : groupIndex = %d, outputCur = %d, outputVol = %d \n",
+//											groupIndex,
+//										ShmPsuData->PsuGroup[groupIndex].PsuModule[i].PresentOutputCurrent,
+//										ShmPsuData->PsuGroup[groupIndex].PsuModule[i].PresentOutputVoltage);
+//									}
+//								}
+//
+//								// 該充電槍的目標電壓與目標電流
+//								SetPresentOutput(groupIndex, NONE_CARE_ADDRESS,
+//										chargingInfo[groupIndex]->EvBatterytargetVoltage,
+//										chargingInfo[groupIndex]->EvBatterytargetCurrent,
+//										chargingInfo[groupIndex]->DeratingChargingCurrent);
+//								usleep(cmdDelayTime);
+//							}
+//							else
+							{
+								// 該充電槍的目標電壓與目標電流
+								SetPresentOutput(groupIndex, NONE_CARE_ADDRESS,
+										chargingInfo[groupIndex]->EvBatterytargetVoltage,
+										chargingInfo[groupIndex]->EvBatterytargetCurrent,
+										chargingInfo[groupIndex]->AvailableChargingCurrent);
+								usleep(cmdDelayTime);
+							}
+						}
+
+						if (chargingInfo[groupIndex]->EvBatterytargetVoltage == 0)
+						{
+							EnableOutputPower(groupIndex, NONE_CARE_ADDRESS, SWITCH_OFF);
+							usleep(cmdDelayTime);
+							EnableGreenLedFlash(groupIndex , NONE_CARE_ADDRESS , SWITCH_OFF);
+							usleep(cmdDelayTime);
+						}
+						else
+						{
+							EnableOutputPower(groupIndex, NONE_CARE_ADDRESS, SWITCH_ON);
+							usleep(cmdDelayTime);
+							EnableGreenLedFlash(groupIndex , NONE_CARE_ADDRESS, SWITCH_ON);
+							usleep(cmdDelayTime);
+						}
+					}
+					else if (chargingInfo[groupIndex]->SystemStatus >= S_TERMINATING &&
+							chargingInfo[groupIndex]->SystemStatus <= S_COMPLETE)
+					{
+						SetPresentOutput(groupIndex, NONE_CARE_ADDRESS, ZERO_VOL, ZERO_CUR, chargingInfo[groupIndex]->AvailableChargingCurrent);
+						usleep(cmdDelayTime);
+						EnableGreenLedFlash(groupIndex , NONE_CARE_ADDRESS , SWITCH_OFF);
+						usleep(cmdDelayTime);
+						EnableOutputPower(groupIndex, NONE_CARE_ADDRESS, SWITCH_OFF);
+						usleep(cmdDelayTime);
+					}
+				}
+				priorityLow >= 200 ? priorityLow = 1 : priorityLow++;
+				break;
+			}
+		}
+	}
+	return FAIL;
+}

+ 91 - 0
EVSE/Projects/PlugIt360/Apps/Module_PsuComm.h

@@ -0,0 +1,91 @@
+#include 	<sys/time.h>
+#include 	<sys/timeb.h>
+#include    <sys/types.h>
+#include    <sys/stat.h>
+#include 	<sys/types.h>
+#include 	<sys/ioctl.h>
+#include 	<sys/socket.h>
+#include 	<sys/ipc.h>
+#include 	<sys/shm.h>
+#include 	<sys/shm.h>
+#include 	<sys/mman.h>
+#include 	<linux/wireless.h>
+#include 	<linux/can.h>
+#include 	<linux/can/raw.h>
+#include 	<arpa/inet.h>
+#include 	<netinet/in.h>
+
+#include 	<unistd.h>
+#include 	<stdarg.h>
+#include   <stdio.h>      /*標準輸入輸出定義*/
+#include   <stdlib.h>     /*標準函數庫定義*/
+#include   <unistd.h>     /*Unix 標準函數定義*/
+#include   <fcntl.h>      /*檔控制定義*/
+#include   <termios.h>    /*PPSIX 終端控制定義*/
+#include   <errno.h>      /*錯誤號定義*/
+#include 	<errno.h>
+#include 	<string.h>
+#include	<time.h>
+#include	<ctype.h>
+#include 	<ifaddrs.h>
+#include	<math.h>
+#include	"../../define.h"
+#include 	<stdbool.h>
+
+
+typedef unsigned char 		byte;
+typedef unsigned short 		word;
+typedef unsigned int 		unit;
+
+#define SELF_TEST_VOL				1600
+#define SELF_TEST_CUR				10
+#define ZERO_VOL					0
+#define ZERO_CUR					0
+#define NONE_CARE_ADDRESS			0
+#define SWITCH_ON		2
+#define SWITCH_OFF		0
+
+
+#define SET_MODULE_CMD              0
+#define SET_GROUP_CMD              1
+
+enum _FIRMWARE_TYPE
+{
+	_Fw_pri_app = 		0,
+	_Fw_sec_app,
+	_Fw_pri_bootload,
+	_Fw_sec_bootload
+};
+
+struct _RecordPsuData
+{
+	byte 				_phy_addr;
+	char 				_serial_num[32];
+	byte 				_fire_index;
+
+};
+
+unsigned char _gunCount = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
+struct ChargingInfoData *chargingInfo[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+bool rework = false;
+
+struct timeval _id_assign_time;
+struct timeval _chk_output_time;
+bool isCheckOutputTimeStart = false;
+
+byte _curCheckPsuIndexForFireLine = 0x00;
+struct _RecordPsuData recordPsuData[PSU_QUANTITY];
+
+struct timeval _chk_cap_time;
+bool _chkTotalCapStart = false;
+
+bool isUpgradeFlag = false;
+
+struct timeval _workModePriority_time;
+struct timeval _derating_time;
+int deratingTime = 0;
+
+int connector_1[] = {0};
+int connector_2[] = {1};
+int conn_1_count = 0;
+int conn_2_count = 0;

+ 363 - 0
EVSE/Projects/PlugIt360/Apps/PrimaryComm.c

@@ -0,0 +1,363 @@
+#include 	<sys/time.h>
+#include 	<sys/timeb.h>
+#include    <sys/types.h>
+#include    <sys/stat.h>
+#include 	<sys/types.h>
+#include 	<sys/ioctl.h>
+#include 	<sys/socket.h>
+#include 	<sys/ipc.h>
+#include 	<sys/shm.h>
+#include 	<sys/shm.h>
+#include 	<sys/mman.h>
+#include 	<linux/wireless.h>
+#include 	<arpa/inet.h>
+#include 	<netinet/in.h>
+
+#include 	<unistd.h>
+#include 	<stdarg.h>
+#include    <stdio.h>      /*標準輸入輸出定義*/
+#include    <stdlib.h>     /*標準函數庫定義*/
+#include    <unistd.h>     /*Unix 標準函數定義*/
+#include    <fcntl.h>      /*檔控制定義*/
+#include    <termios.h>    /*PPSIX 終端控制定義*/
+#include    <errno.h>      /*錯誤號定義*/
+#include 	<errno.h>
+#include 	<string.h>
+#include	<time.h>
+#include	<ctype.h>
+#include 	<ifaddrs.h>
+#include 	<math.h>
+#include 	"PrimaryComm.h"
+
+#define PASS				1
+#define FAIL				-1
+
+struct Address Addr={0x01,0x02,0x03,0x04,0xFF};
+struct Command Cmd={0x01,0x02,0x0a,0x86,0x87,0xe0,0xe1,0xe2,0xe3};
+
+int tranceive(int fd, unsigned char* cmd, unsigned char cmd_len, unsigned char* rx)
+{
+	int len;
+	//sleep(2); //required to make flush work, for some reason
+	tcflush(fd,TCIOFLUSH);
+	if(write(fd, cmd, cmd_len) >= cmd_len)
+	{
+		usleep(50000);
+		len = read(fd, rx, 512);
+	}
+	else
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("Serial command %s response fail.\n", cmd);
+		#endif
+	}
+
+	return len;
+}
+
+unsigned char Query_FW_Ver(unsigned char fd, unsigned char targetAddr, Ver *Ret_Buf)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_FW_Ver, 0x00, 0x00, 0x00};
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+	if(len > 0)
+	{
+		for(int idx = 0; idx < (rx[4] | rx[5]<<8); idx++)
+		{
+			chksum ^= rx[6+idx];
+		}
+
+		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
+		   (rx[2] == tx[1]) &&
+		   (rx[1] == tx[2]) &&
+		   (rx[3] == tx[3]))
+		{
+			memcpy(Ret_Buf->Version_FW, (char *)rx+6, (rx[4] | rx[5]<<8));
+			*(Ret_Buf->Version_FW + 8) = 0x00;
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+unsigned char Query_HW_Ver(unsigned char fd, unsigned char targetAddr, Ver *Ret_Buf)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_HW_Ver, 0x00, 0x00, 0x00};
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+
+	if(tranceive(fd, tx, sizeof(tx), rx) >0)
+	{
+		for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
+		{
+			chksum ^= rx[6+idx];
+		}
+
+		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
+		   (rx[2] == tx[1]) &&
+		   (rx[1] == tx[2]) &&
+		   (rx[3] == tx[3]))
+		{
+			memcpy(Ret_Buf->Version_HW, (char *)rx+6, (rx[4] | rx[5]<<8));
+			//*(Ret_Buf->Version_HW + 8) = 0x00;
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+unsigned char Query_Gpio_Input(unsigned char fd, unsigned char targetAddr, Gpio_in *Ret_Buf)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_Gpio_In, 0x00, 0x00, 0x00};
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+	if(len > 0)
+	{
+		for (int idx = 0; idx < (rx[4] | rx[5] << 8); idx++)
+		{
+			chksum ^= rx[6+idx];
+		}
+
+		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
+		   (rx[2] == tx[1]) &&
+		   (rx[1] == tx[2]) &&
+		   (rx[3] == tx[3]))
+		{
+			Ret_Buf->AC_Connector 		= (rx[6] >> 0) & 0x01;
+			Ret_Buf->AC_MainBreaker 	= (rx[6] >> 1) & 0x01;
+			Ret_Buf->SPD 				= (rx[6] >> 2) & 0x01;
+			Ret_Buf->Door_Open 			= (rx[6] >> 3) & 0x01;
+			Ret_Buf->GFD[0] 			= (rx[6] >> 4) & 0x01;
+			Ret_Buf->GFD[1] 			= (rx[6] >> 5) & 0x01;
+			Ret_Buf->AC_Drop 			= (rx[6] >> 6) & 0x01;
+			Ret_Buf->Emergency_IO 		= (rx[6] >> 7) & 0x01;
+
+			Ret_Buf->Emergency_Btn		= (rx[7] >> 0) & 0x01;
+			Ret_Buf->Button[0] 			= (rx[7] >> 1) & 0x01;
+			Ret_Buf->Button[1] 			= (rx[7] >> 2) & 0x01;
+			Ret_Buf->Key[0]				= (rx[7] >> 3) & 0x01;
+			Ret_Buf->Key[1]				= (rx[7] >> 4) & 0x01;
+			Ret_Buf->Key[2]				= (rx[7] >> 5) & 0x01;
+			Ret_Buf->Key[3]				= (rx[7] >> 6) & 0x01;
+
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+unsigned char Config_Gpio_Output(unsigned char fd, unsigned char targetAddr, Gpio_out *Set_Buf)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[9] = {0xaa, 0x00, targetAddr, Cmd.config_Gpio_Output, 0x01, 0x00, 0x00, 0x00};
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+
+	for (int idx = 0; idx < 2; idx++)
+		tx[6] |= (Set_Buf->Button_LED[idx] ? 0x01:0x00) << (0+idx);
+
+	for (int idx = 0; idx < 4; idx++)
+			tx[6] |= (Set_Buf->System_LED[idx] ? 0x01:0x00) << (2+idx);
+
+	tx[6] |= (Set_Buf->AC_Connector ? 0x01:0x00) << 6;
+	tx[6] |= (Set_Buf->AC_Breaker ? 0x01:0x00) << 7;
+
+	for (int idx = 0; idx < (tx[4] | tx[5] << 8); idx++)
+		chksum ^= tx[6+idx];
+	tx[7] = chksum;
+
+	if (tranceive(fd, tx, sizeof(tx), rx) > 0)
+	{
+		chksum = 0x00;
+		for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
+		{
+			chksum ^= rx[6+idx];
+		}
+
+		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
+		   (rx[2] == tx[1]) &&
+		   (rx[1] == tx[2]) &&
+		   (rx[3] == tx[3]) &&
+		   (rx[6] == tx[6]))
+		{
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+unsigned char Config_Rtc_Data(unsigned char fd, unsigned char targetAddr, Rtc *Set_Buf)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[21] = { 0xaa, 0x00, targetAddr, Cmd.config_Rtc_Data, 0x0E, 0x00, Set_Buf->RtcData[0], Set_Buf->RtcData[1],
+			Set_Buf->RtcData[2], Set_Buf->RtcData[3], Set_Buf->RtcData[4], Set_Buf->RtcData[5], Set_Buf->RtcData[6], Set_Buf->RtcData[7],
+			Set_Buf->RtcData[8], Set_Buf->RtcData[9], Set_Buf->RtcData[10], Set_Buf->RtcData[11], Set_Buf->RtcData[12], Set_Buf->RtcData[13]};
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+
+	for (int idx = 0; idx < (tx[4] | tx[5] << 8); idx++)
+		chksum ^= tx[6 + idx];
+	tx[20] = chksum;
+
+	if (tranceive(fd, tx, sizeof(tx), rx) > 0)
+	{
+		chksum = 0x00;
+		for (int idx = 0; idx < (rx[4] | rx[5] << 8); idx++)
+		{
+			chksum ^= rx[6 + idx];
+		}
+
+		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
+				(rx[2] == tx[1]) &&
+				(rx[1] == tx[2]) &&
+				(rx[3] == tx[3]) &&
+				(rx[6] == tx[6]))
+		{
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+unsigned char Update_Start(unsigned char fd, unsigned char targetAddr, unsigned int crc32)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[11] = {0xaa, 0x00, targetAddr, Cmd.update_Start, 0x04, 0x00, (crc32>>0)&0xff, (crc32>>8)&0xff, (crc32>>16)&0xff, (crc32>>24)&0xff, 0x00};
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+
+	for (int idx = 0; idx < (tx[4] | tx[5] << 8); idx++)
+		chksum ^= tx[6+idx];
+	tx[10] = chksum;
+
+
+	if(tranceive(fd, tx, sizeof(tx), rx) > 0)
+	{
+		chksum = 0x00;
+		for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
+		{
+			chksum ^= rx[6+idx];
+		}
+
+		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
+		   (rx[2] == tx[1]) &&
+		   (rx[1] == tx[2]) &&
+		   (rx[3] == tx[3]) &&
+		   (rx[6] == 0x00))
+		{
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+unsigned char Update_Abord(unsigned char fd, unsigned char targetAddr)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.update_Start, 0x04, 0x00, 0x00};
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+
+	if(tranceive(fd, tx, sizeof(tx), rx) >0)
+	{
+		for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
+		{
+			chksum ^= rx[6+idx];
+		}
+
+		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
+		   (rx[2] == tx[1]) &&
+		   (rx[1] == tx[2]) &&
+		   (rx[3] == tx[3]) &&
+		   (rx[6] == 0x00))
+		{
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+unsigned char Update_Transfer(unsigned char fd, unsigned char targetAddr, unsigned int startAddr, unsigned char *data, unsigned short int length)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[11 + length];
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+
+	tx[0] = 0xaa;
+	tx[1] = 0x00;
+	tx[2] = targetAddr;
+	tx[3] = Cmd.update_Transfer;
+	tx[4] = (4 + length) & 0xff;
+	tx[5] = ((4 + length)>>8) & 0xff;
+	tx[6] = (startAddr>>0) & 0xff;
+	tx[7] = (startAddr>>8) & 0xff;
+	tx[8] = (startAddr>>16) & 0xff;
+	tx[9] = (startAddr>>24) & 0xff;
+	memcpy(tx+10, data, length);
+
+	for (int idx = 0; idx < (tx[4] | tx[5] << 8); idx++)
+		chksum ^= tx[6+idx];
+	tx[sizeof(tx)-1] = chksum;
+
+	if(tranceive(fd, tx, sizeof(tx), rx) >0)
+	{
+		for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
+		{
+			chksum ^= rx[6+idx];
+		}
+
+		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
+		   (rx[2] == tx[1]) &&
+		   (rx[1] == tx[2]) &&
+		   (rx[3] == tx[3]) &&
+		   (rx[6] == 0x00))
+		{
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+unsigned char Update_Finish(unsigned char fd, unsigned char targetAddr)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.update_Finish, 0x04, 0x00, 0x00};
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+
+	if(tranceive(fd, tx, sizeof(tx), rx) >0)
+	{
+		for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
+		{
+			chksum ^= rx[6+idx];
+		}
+
+		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
+		   (rx[2] == tx[1]) &&
+		   (rx[1] == tx[2]) &&
+		   (rx[3] == tx[3]) &&
+		   (rx[6] == 0x00))
+		{
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+

+ 79 - 0
EVSE/Projects/PlugIt360/Apps/PrimaryComm.h

@@ -0,0 +1,79 @@
+#ifndef PRIMARYCOMM_H_
+#define PRIMARYCOMM_H_
+
+extern struct Address
+{
+	unsigned char Aux;
+	unsigned char Fan;
+	unsigned char Relay;
+	unsigned char IoExtend;
+	unsigned char Broadcast;
+}Addr;
+
+extern struct Command
+{
+	unsigned char query_FW_Ver; 		//0x01
+	unsigned char query_HW_Ver;		//0x02
+	unsigned char query_Gpio_In;		//0x0a
+
+	unsigned char config_Gpio_Output;	//0x86
+	unsigned char config_Rtc_Data;		//0x87
+
+	unsigned char update_Start;		//0xe0
+	unsigned char update_Abort;		//0xe1
+	unsigned char update_Transfer;		//0xe2
+	unsigned char update_Finish;		//0xe3
+
+}Cmd;
+
+typedef struct Verion
+{
+	char Version_FW[16];
+	char Version_HW[16];
+}Ver;
+
+typedef struct GPIO_IN
+{
+	unsigned char AC_Connector;
+	unsigned char AC_MainBreaker;
+	unsigned char SPD;
+	unsigned char Door_Open;
+	unsigned char GFD[2];
+	unsigned char AC_Drop;
+	unsigned char Emergency_IO;
+
+	unsigned char Emergency_Btn;
+	unsigned char Button[2];
+	unsigned char Key[4];
+}Gpio_in;
+
+typedef struct GPIO_OUT
+{
+	unsigned char Button_LED[2];
+	unsigned char System_LED[4];
+	unsigned char AC_Connector;
+	unsigned char AC_Breaker;
+}Gpio_out;
+
+typedef struct RTC
+{
+	unsigned char RtcData[14];
+}Rtc;
+
+extern unsigned char Query_FW_Ver(unsigned char fd, unsigned char targetAddr, Ver *Ret_Buf);
+extern unsigned char Query_HW_Ver(unsigned char fd, unsigned char targetAddr, Ver *Ret_Buf);
+extern unsigned char Query_Gpio_Input(unsigned char fd, unsigned char targetAddr, Gpio_in *Ret_Buf);
+
+extern unsigned char Config_Gpio_Output(unsigned char fd, unsigned char targetAddr, Gpio_out *Set_Buf);
+extern unsigned char Config_Rtc_Data(unsigned char fd, unsigned char targetAddr, Rtc *Set_Buf);
+// 13 bytes
+// year : 4, month : 2, day : 2, hour : 2, min : 2, sec : 2
+//extern unsigned char Config_RTC();
+
+extern unsigned char Update_Start(unsigned char fd, unsigned char targetAddr, unsigned int crc32);
+extern unsigned char Update_Abord(unsigned char fd, unsigned char targetAddr);
+extern unsigned char Update_Transfer(unsigned char fd, unsigned char targetAddr, unsigned int startAddr, unsigned char *data, unsigned short int length);
+extern unsigned char Update_Finish(unsigned char fd, unsigned char targetAddr);
+
+
+#endif /* PRIMARYCOMM_H_ */

BIN
EVSE/Projects/PlugIt360/Apps/ReadCmdline


+ 865 - 0
EVSE/Projects/PlugIt360/Apps/ReadCmdline.c

@@ -0,0 +1,865 @@
+/*
+ * Main.c
+ *
+ *  Created on: 2019年8月6日
+ *      Author: 7564
+ */
+
+
+#include 	<sys/time.h>
+#include 	<sys/timeb.h>
+#include    <sys/types.h>
+#include    <sys/stat.h>
+#include 	<sys/types.h>
+#include 	<sys/ioctl.h>
+#include 	<sys/socket.h>
+#include 	<sys/ipc.h>
+#include 	<sys/shm.h>
+#include 	<sys/shm.h>
+#include 	<sys/mman.h>
+#include 	<linux/wireless.h>
+#include 	<arpa/inet.h>
+#include 	<netinet/in.h>
+
+#include 	<unistd.h>
+#include 	<stdarg.h>
+#include    <stdio.h>      /*標準輸入輸出定義*/
+#include    <stdlib.h>     /*標準函數庫定義*/
+#include    <unistd.h>     /*Unix 標準函數定義*/
+#include    <fcntl.h>      /*檔控制定義*/
+#include    <termios.h>    /*PPSIX 終端控制定義*/
+#include    <errno.h>      /*錯誤號定義*/
+#include 	<errno.h>
+#include 	<string.h>
+#include	<time.h>
+#include	<ctype.h>
+#include 	<ifaddrs.h>
+#include 	<math.h>
+#include 	<stdbool.h>
+#include 	"../../define.h"
+
+typedef unsigned char			byte;
+#define PASS				1
+#define FAIL				-1
+#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
+
+#define TTY_PATH            "/dev/tty"
+#define STTY_US             "stty raw -echo -F "
+#define STTY_DEF            "stty -raw echo -F "
+
+struct SysConfigAndInfo			*ShmSysConfigAndInfo;
+struct StatusCodeData 			*ShmStatusCodeData;
+struct PrimaryMcuData			*ShmPrimaryMcuData;
+struct CHAdeMOData				*ShmCHAdeMOData;
+struct CcsData					*ShmCcsData;
+struct FanModuleData			*ShmFanModuleData;
+struct RelayModuleData			*ShmRelayModuleData;
+struct PsuData 					*ShmPsuData;
+
+struct ChargingInfoData 		*_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+int gunCount = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
+
+char *msg = "state : get gun state (index) \n"
+		"card : scanning card (x) : \n"
+		"gun : get gun plugit state (index) \n"
+		"lock : get gun locked state (index) \n"
+		"self : self test state (x) \n"
+		"ver : ver of board (407 or index or rb or fan) \n"
+		"ac : get ac relay state (x) \n";
+
+bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
+{
+	for (byte index = 0; index < CHAdeMO_QUANTITY; index++)
+	{
+		if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)
+		{
+			chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
+			return true;
+		}
+	}
+
+	for (byte index = 0; index < CCS_QUANTITY; index++)
+	{
+		if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)
+		{
+			chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
+			return true;
+		}
+	}
+
+	for (byte index = 0; index < GB_QUANTITY; index++)
+	{
+		if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)
+		{
+			chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
+			return true;
+		}
+	}
+
+	return false;
+}
+
+int InitShareMemory()
+{
+	int result = PASS;
+	int MeterSMId;
+
+	//initial ShmSysConfigAndInfo
+	if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0)
+    {
+		result = FAIL;
+	}
+    else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+    {
+    	result = FAIL;
+   	 }
+    else
+    {}
+
+   	//initial ShmStatusCodeData
+   	if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0)
+    {
+   		result = FAIL;
+	}
+    else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+    {
+    	result = FAIL;
+   	}
+    else
+    {}
+
+   	if(CHAdeMO_QUANTITY > 0)
+   	{
+		if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData),
+				IPC_CREAT | 0777)) < 0) {
+			result = FAIL;
+		} else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0))
+				== (void *) -1) {
+			result = FAIL;
+		} else {
+		}
+   	}
+
+   	if(CCS_QUANTITY > 0)
+   	{
+		if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData),
+				IPC_CREAT | 0777)) < 0) {
+			result = FAIL;
+		} else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1) {
+			result = FAIL;
+		} else {
+		}
+   	}
+
+   	if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), IPC_CREAT | 0777)) < 0)
+   	{
+   		result = FAIL;
+   	}
+   	else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+   	{
+   		result = FAIL;
+   	}
+
+   	if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData),	IPC_CREAT | 0777)) < 0)
+   	{
+   		result = FAIL;
+   	}
+   	else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+   	{
+   		result = FAIL;
+   	}
+
+   	if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData),	IPC_CREAT | 0777)) < 0)
+   	{
+   		result = FAIL;
+   	}
+   	else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+   	{
+   		result = FAIL;
+   	}
+
+   	if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData),	IPC_CREAT | 0777)) < 0)
+   	{
+   		result = FAIL;
+   	}
+   	else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+   	{
+   		result = FAIL;
+   	}
+
+    return result;
+}
+
+void RunStatusProc(char *v1, char *v2)
+{
+	int _index = atoi(v1);
+	if (!FindChargingInfoData(_index, &_chargingData[0]))
+	{
+		printf ("FindChargingInfoData error\n");
+		return;
+	}
+
+	if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
+	{
+		// get
+		printf ("index = %x, status = %x (%d)\n", _index, _chargingData[_index]->SystemStatus, _chargingData[_index]->IsAvailable);
+	}
+	else
+	{
+		// set
+		_chargingData[_index]->SystemStatus = atoi(v2);
+	}
+}
+
+void RunCardProc(char *v1, char *v2)
+{
+	if (ShmSysConfigAndInfo->SysInfo.WaitForPlugit)
+	{
+		ShmSysConfigAndInfo->SysInfo.WaitForPlugit = 0x00;
+		printf ("SysInfo.WaitForPlugit = %x \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
+	}
+	else
+	{
+		ShmSysConfigAndInfo->SysInfo.WaitForPlugit = 0x01;
+		printf ("SysInfo.WaitForPlugit = %x \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
+	}
+}
+
+void RunGunPlugitProc(char *v1, char *v2)
+{
+	int _index = atoi(v1);
+	if (!FindChargingInfoData(_index, &_chargingData[0]))
+	{
+		printf("FindChargingInfoData error\n");
+		return;
+	}
+
+	if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
+	{
+		// get
+		printf("index = %x, plug it = %x\n", _index, _chargingData[_index]->ConnectorPlugIn);
+	}
+	else
+	{
+		// set
+		_chargingData[_index]->ConnectorPlugIn = atoi(v2);
+	}
+}
+
+void GetGunLockStatusProc(char *v1, char *v2)
+{
+	if (strcmp(v1, "0") == 0)
+	{
+		printf("Gun Locked Status = %x \n", _chargingData[0]->GunLocked);
+	}
+
+	if (strcmp(v1, "1") == 0)
+	{
+		printf("Gun Locked Status = %x \n", _chargingData[1]->GunLocked);
+	}
+}
+
+void SetSystemIDProc()
+{
+	char *systemId = "Alston_Test";
+	memcpy(&ShmSysConfigAndInfo->SysConfig.SystemId, systemId, strlen(systemId));
+}
+
+void RunSelfProc()
+{
+	printf("self test status = %x\n", ShmSysConfigAndInfo->SysInfo.SelfTestSeq);
+}
+
+void GetFwVerProc(char *v1)
+{
+	if (strcmp(v1, "407") == 0)
+	{
+		printf("407 FW Version = %s \n", ShmPrimaryMcuData->version);
+	}
+	else if (strcmp(v1, "0") == 0)
+	{
+		printf("Ev board 1 FW Version = %s \n", ShmCHAdeMOData->evse[0].version);
+		printf("Ev board 1 FW Version = %s \n", ShmCcsData->V2GMessage_DIN70121->version);
+	}
+	else if (strcmp(v1, "1") == 0)
+	{
+		printf("Ev board 2 FW Version = %s \n", ShmCHAdeMOData->evse[1].version);
+		printf("Ev board 2 FW Version = %s \n", ShmCcsData->V2GMessage_DIN70121->version);
+	}
+	else if (strcmp(v1, "rb") == 0)
+	{
+		printf("RB Version = %s \n", ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev);
+	}
+	else if (strcmp(v1, "fan") == 0)
+	{
+		printf("FAN Version = %s \n", ShmSysConfigAndInfo->SysInfo.FanModuleFwRev);
+	}
+	else if (strcmp(v1, "dc") == 0)
+	{
+		printf("DC Main Version = %s \n", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
+	}
+}
+
+void FwUpdateFlagProc()
+{
+	ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = 0x01;
+}
+
+void CheckAcStatus(char *v1)
+{
+	if (strcmp(v1, "-1") == 0|| strcmp(v1, "") == 0)
+	{
+		printf("AC Status = %d \n", ShmSysConfigAndInfo->SysInfo.AcContactorStatus);
+	}
+}
+
+void SetCableChkStatus(char *v1, char *v2)
+{
+	int _index = atoi(v1);
+	if (!FindChargingInfoData(_index, &_chargingData[0]))
+	{
+		printf ("FindChargingInfoData error\n");
+		return;
+	}
+
+	_chargingData[_index]->GroundFaultStatus = atoi(v2);
+}
+
+void SetPowerValue(char *v1, char *v2)
+{
+//	int _index = atoi(v1);
+//	if (!FindChargingInfoData(_index, &_chargingData[0])) {
+//		printf("FindChargingInfoData error\n");
+//		return;
+//	}
+//
+//	if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0) {
+//		// get
+//		printf("index = %x, max cur = %f\n", _index,
+//				_chargingData[_index]->MaxChargingCurrentForTest);
+//	} else {
+//		// set
+//		_chargingData[_index]->MaxChargingCurrentForTest = atoi(v2);
+//	}
+}
+
+void GetGunSelectedNum(char *v1)
+{
+	if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0)
+		printf("connector selected = %d \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+	else
+	{
+		int _index = atoi(v1);
+		ShmSysConfigAndInfo->SysInfo.CurGunSelected = _index;
+		printf("connector select changed = %d \n", _index);
+	}
+}
+
+void SetFanSpeed(char *v1)
+{
+	int speed = atoi(v1);
+
+	ShmFanModuleData->TestFanSpeed = speed;
+}
+
+void GetFanSpeed()
+{
+	printf("ShmFanModuleData->PresentFan1Speed = %d \n", ShmFanModuleData->PresentFan1Speed);
+	printf("ShmFanModuleData->PresentFan2Speed = %d \n", ShmFanModuleData->PresentFan2Speed);
+	printf("ShmFanModuleData->PresentFan3Speed = %d \n", ShmFanModuleData->PresentFan3Speed);
+	printf("ShmFanModuleData->PresentFan4Speed = %d \n", ShmFanModuleData->PresentFan4Speed);
+}
+
+void GetPsuInformation(char *v1)
+{
+	printf("*************************************************\n");
+	if(strcmp(v1, "count") == 0)
+	{
+		for (int i = 0; i < 4; i++)
+		{
+			printf("Group Index = %d, Module Count = %d \n", i, ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity);
+		}
+	}
+	else if(strcmp(v1, "ver") == 0)
+	{
+		for (int i = 0; i < ShmPsuData->GroupCount; i++)
+		{
+			for (int j = 0; j < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; j++)
+			{
+				printf("Group Index = %d, Psu Index = %d, Version = %s \n",
+					i, j, ShmPsuData->PsuGroup[i].PsuModule[j].FwVersion);
+			}
+		}
+	}
+	else if(strcmp(v1, "cap") == 0)
+	{
+		for (int i = 0; i < ShmPsuData->GroupCount; i++)
+		{
+			printf("Group Index = %d, MaxCur = %d, Power = %d \n",
+					i, ShmPsuData->PsuGroup[i].GroupAvailableCurrent, ShmPsuData->PsuGroup[i].GroupAvailablePower);
+		}
+	}
+	else if (strcmp(v1, "output") == 0)
+	{
+		for (int i = 0; i < ShmPsuData->GroupCount; i++)
+		{
+			printf("Group Index = %d, OutputV = %d, OutputC = %d \n",
+					i, ShmPsuData->PsuGroup[i].GroupPresentOutputVoltage, ShmPsuData->PsuGroup[i].GroupPresentOutputCurrent);
+		}
+	}
+	printf("*************************************************\n");
+}
+
+static int get_char()
+{
+    fd_set rfds;
+    struct timeval tv;
+    int ch = 0;
+
+    FD_ZERO(&rfds);
+    FD_SET(0, &rfds);
+    tv.tv_sec = 0;
+    tv.tv_usec = 10; //wait input timout time
+
+    //if input
+    if (select(1, &rfds, NULL, NULL, &tv) > 0)
+    {
+        ch = getchar();
+    }
+
+    return ch;
+}
+
+void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
+{
+	int _GunIndex = atoi(v1);
+	float _Voltage = atof(v2);
+	int _Current = atoi(v3);
+	unsigned char PreviousSystemStatus = 0xff;
+	int ch = 0;
+
+	if (!FindChargingInfoData(_GunIndex, &_chargingData[0]))
+	{
+		printf ("FindChargingInfoData error\n");
+		return;
+	}
+
+    printf ("ReqVoltage = %f, ReqCurrent = %d\n", _Voltage,_Current);
+
+    if(_Voltage > 1000 || _Voltage < 150){
+
+        printf ("Input Voltage over range\n");
+        return;
+    }
+
+//    if(_Current > 100 || _Current < 2){
+//
+//        printf ("Input Current over range\n");
+//        return;
+//    }
+
+    //測試期間先跳過自我測試 _STEST_COMPLETE = 0xfe
+    //ShmSysConfigAndInfo->SysInfo.SelfTestSeq = 0xfe;
+
+    //kill ev task
+    system("killall Module_EvComm");
+
+    _Voltage = (_Voltage * 10);
+    _Current = (_Current * 10);
+
+    //system(STTY_US TTY_PATH);
+
+    while(true)
+    {
+        //fix gun 1
+        ShmSysConfigAndInfo->SysInfo.CurGunSelected = _GunIndex;
+
+    	switch(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
+    	{
+            case S_IDLE:
+    		{
+        	    if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
+        	    {
+        	        PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
+
+        	        printf ("[UnconditionalCharge - S_IDLE]\n");
+
+        	    }
+
+                _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_PREPARNING;
+    		}
+    		break;
+
+
+    		case S_PREPARNING:
+    		{
+        	    if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
+        	    {
+        	        PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
+
+        	        printf ("[UnconditionalCharge - S_PREPARNIN]\n");
+
+        	        //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
+        	        printf ("wait find module\n");
+
+        	    }
+    		    //main 會在此階段判斷以下資料跳到下一個 state
+    		    //用來得知 AC 是否有搭上 (搭上模組的資訊才會出來) 因為每次  AC_Contactor
+
+
+    		    //ShmPsuData->SystemPresentPsuQuantity;
+    		    //ShmPsuData->PsuGroup[gun_index].GroupPresentPsuQuantity;
+    		    //ShmPsuData->PsuGroup[gun_index].GroupAvailablePower;
+    		    //_chargingData[gun_index]->AvailableChargingPower;
+
+    		    //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
+    		    //sleep(10);
+
+    		    //清除 main timeout 機制
+    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
+    		    //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
+    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
+
+    		}
+    		break;
+
+    		case S_PREPARING_FOR_EV:
+    		{
+        	    if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
+        	    {
+        	        PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
+
+        	        printf ("[UnconditionalCharge - S_PREPARING_FOR_EV]\n");
+        	        printf ("ReqVoltage = %f, ReqCurrent = %d\n", _Voltage,_Current);
+
+        	    }
+    		    //清除 main timeout 機制
+    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
+    		    //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
+    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
+
+    		    //充電電壓電流
+    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
+   		        _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 5000;
+    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 20;
+    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
+
+    		    //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
+    		    //確定模組己升壓完成
+    		    //if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage <=  (3000+500) &&
+    		    //  _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage >=  (3000-500) )
+    		    {
+    		        printf ("Precharge Done = %f \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage);
+    		        //EV done
+    		        _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_PREPARING_FOR_EVSE;
+    		    }
+
+    		}
+    		break;
+
+
+    		case S_PREPARING_FOR_EVSE:
+    		{
+        	    if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
+        	    {
+        	        PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
+
+        	        printf ("[UnconditionalCharge - S_PREPARING_FOR_EVSE]\n");
+
+        	    }
+        	    //printf ("tar vol = %d \n", _Voltage);
+        	    //printf ("tar cur = %d \n", _Current);
+
+    		    //清除 main timeout 機制
+    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
+    		    //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
+    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
+
+    		    //充電電壓電流
+    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
+    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 5000;
+    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 20;
+    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
+
+    		    //printf ("tar vol_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage);
+        	   // printf ("tar cur_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent);
+
+    		    //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
+    		    //確定模組己升壓完成
+    		    if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x01 ||
+    		        _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x03)
+    		    {
+    		        printf ("First Ground Fault State (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
+    		        printf ("Wait K1K2 = %f \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage);
+    		        sleep(5);
+    		        //EV done
+    		        _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_CHARGING;
+    		    }
+    		    else if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus > 0x02)
+    		    {
+    		             printf ("First Ground Fault check Fail (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
+    		            _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
+    		    }
+
+    		}
+    		break;
+
+    		case S_CHARGING:
+    		{
+        	    if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
+        	    {
+        	        PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
+
+        	        printf ("[UnconditionalCharge - S_CHARGING]\n");
+
+        	    }
+    		    //充電電壓電流
+    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
+    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _Voltage;
+    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _Current;
+    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
+
+    		    //ev task do this
+    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingPower = ((float)((_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage / 10) * (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingCurrent / 10)) / 1000);
+
+    		    if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x02){
+    		         printf ("Charging Ground Fault check Fail (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
+    		        _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
+    		    }
+
+    		    if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x03){
+    		         printf ("Charging Ground Fault Warning (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
+    		        _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
+    		    }
+
+    		}
+    		break;
+
+     		case S_TERMINATING:
+    		{
+        	    if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
+        	    {
+        	        PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
+        	        system("/root/Module_EvComm &");
+
+        	        printf ("[UnconditionalCharge - S_TERMINATING]\n");
+        	        //無阻塞偵測 keybaord 結束
+        	        system(STTY_DEF TTY_PATH);
+
+        	    }
+
+        	    sleep(3);
+        	    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_COMPLETE;
+        	    return;
+    		}
+    		break;
+
+    		case S_COMPLETE:
+    		{
+        	    if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
+        	    {
+        	        PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
+
+        	        printf ("[UnconditionalCharge - S_COMPLETE]\n");
+
+        	    }
+        	    sleep(3);
+        	    return;
+    		}
+    		break;
+    	}
+
+    	/*
+    	//使用 Keyboard input 阻塞方法
+        fgets(InputChar, sizeof(InputChar), stdin);
+
+        if (InputChar[0] == 's' && InputChar[1] == 't' && InputChar[2] == 'o' && InputChar[3] == 'p')
+        {
+           printf ("Precharge Done\n");
+           _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
+
+        }
+        */
+
+        //使用 keybaord input 非阻塞方法
+        ch = get_char();
+        if (ch)
+        {
+            printf("%c \n\r", ch);
+
+            switch (ch)
+            {
+                //Ctrl + C
+                case 3:
+                    //system(STTY_DEF TTY_PATH);
+                        return;
+                //input c or C
+                case 'c':
+                case 'C':
+                    printf("stop \n\r");
+                    //system(STTY_DEF TTY_PATH);
+                    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
+                    break;
+            }
+        }
+
+    }
+
+}
+
+int main(void)
+{
+	if(InitShareMemory() == FAIL)
+	{
+		printf ("InitShareMemory = FAIL \n");
+		if(ShmStatusCodeData != NULL)
+		{
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
+		}
+		sleep(5);
+		return 0;
+	}
+
+	for(;;)
+	{
+		char word[128];
+		char newString[7][10];
+		int i,j,ctr;
+
+		fgets(word, sizeof(word), stdin);
+
+		j=0; ctr=0;
+		strcpy(newString[1], "-1");
+		strcpy(newString[2], "-1");
+		for (i = 0; i <= (strlen(word)); i++)
+		{
+			if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
+			{
+				newString[ctr][j] = '\0';
+				ctr++;
+				j = 0;
+			}
+			else
+			{
+				newString[ctr][j] = word[i];
+				j++;
+			}
+		}
+
+		if(strcmp(newString[0], "state") == 0)
+		{
+			if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
+				continue;
+
+			// 槍狀態
+			RunStatusProc(newString[1], newString[2]);
+		}
+		else if(strcmp(newString[0], "card") == 0)
+		{
+			// 刷卡狀態
+			RunCardProc(newString[1], newString[2]);
+		}
+		else if(strcmp(newString[0], "gun") == 0)
+		{
+			if (strcmp(newString[1], "-1") == 0	|| strcmp(newString[1], "") == 0)
+				continue;
+
+			// 插槍狀態
+			RunGunPlugitProc(newString[1], newString[2]);
+		}
+		else if(strcmp(newString[0], "lock") == 0)
+		{
+			if (strcmp(newString[1], "-1") == 0	|| strcmp(newString[1], "") == 0)
+				continue;
+
+			// 插槍狀態
+			GetGunLockStatusProc(newString[1], newString[2]);
+		}
+		else if(strcmp(newString[0], "sysid") == 0)
+		{
+			// 測試 sys id
+			SetSystemIDProc();
+		}
+		else if(strcmp(newString[0], "self") == 0)
+		{
+			// CSU 自我檢測狀態
+			RunSelfProc(newString[1]);
+		}
+		else if(strcmp(newString[0], "ver") == 0)
+		{
+			if (strcmp(newString[1], "-1") == 0	|| strcmp(newString[1], "") == 0)
+				continue;
+			// 取 FW 版號
+			GetFwVerProc(newString[1]);
+		}
+		else if (strcmp(newString[0], "update") == 0)
+		{
+			// 更新
+			FwUpdateFlagProc(newString[1]);
+		}
+		else if (strcmp(newString[0], "ac") == 0)
+		{
+			// AC contactor 狀態
+			CheckAcStatus(newString[1]);
+		}
+		else if (strcmp(newString[0], "cable") == 0)
+		{
+			if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
+				continue;
+			// cable check pass
+			SetCableChkStatus(newString[1], newString[2]);
+		}
+		else if (strcmp(newString[0], "pow") == 0)
+		{
+			if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
+				continue;
+			// cable check pass
+			SetPowerValue(newString[1], newString[2]);
+		}
+		else if(strcmp(newString[0], "select") == 0)
+		{
+			// 取得當前選的槍號
+			GetGunSelectedNum(newString[1]);
+		}
+		else if(strcmp(newString[0], "fan") == 0)
+		{
+			// 設定風扇速度
+			SetFanSpeed(newString[1]);
+		}
+		else if(strcmp(newString[0], "speed") == 0)
+		{
+			// 取得風扇速度
+			GetFanSpeed();
+		}
+		else if(strcmp(newString[0], "psu") == 0)
+		{
+			//如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
+			if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
+			{
+				printf ("PSU : Param fail..Please retry again......\n");
+				continue;
+			}
+
+			// 取得 PSU 資訊
+			GetPsuInformation(newString[1]);
+		}
+		else if(strcmp(newString[0], "strchg") == 0)
+		{
+			//如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
+			if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
+					strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
+			{
+				printf ("Input cmd fail ------  strchg [vol 150-1000] [cru 2-100]\n");
+				continue;
+			}
+
+			// 槍狀態
+			RunUnconditionalChargeIndex1(newString[1], newString[2], newString[3]);
+		}
+
+		printf ("%s\n", msg);
+		usleep(100000);
+	}
+
+	return 0;
+}

+ 11 - 0
EVSE/Projects/PlugIt360/Apps/init.sh

@@ -0,0 +1,11 @@
+chmod 777 Module_CSU
+chmod 777 Module_PrimaryComm
+chmod 777 Module_LcmControl
+chmod 777 Module_InternalComm
+chmod 777 Module_EventLogging
+chmod 777 Module_EvComm
+chmod 777 Module_PsuComm
+chmod 777 OcppBackend
+chmod 777 kill.sh
+chmod 777 ReadCmdline
+

+ 835 - 0
EVSE/Projects/PlugIt360/Apps/internalComm.c

@@ -0,0 +1,835 @@
+/*
+ * internalComm.c
+ *
+ *  Created on: 2019年5月7日
+ *      Author: foluswen
+ */
+#include 	<sys/time.h>
+#include 	<sys/timeb.h>
+#include    <sys/types.h>
+#include    <sys/stat.h>
+#include 	<sys/types.h>
+#include 	<sys/ioctl.h>
+#include 	<sys/socket.h>
+#include 	<sys/ipc.h>
+#include 	<sys/shm.h>
+#include 	<sys/shm.h>
+#include 	<sys/mman.h>
+#include 	<linux/wireless.h>
+#include 	<arpa/inet.h>
+#include 	<netinet/in.h>
+
+#include 	<unistd.h>
+#include 	<stdarg.h>
+#include    <stdio.h>      /*標準輸入輸出定義*/
+#include    <stdlib.h>     /*標準函數庫定義*/
+#include    <unistd.h>     /*Unix 標準函數定義*/
+#include    <fcntl.h>      /*檔控制定義*/
+#include    <termios.h>    /*PPSIX 終端控制定義*/
+#include    <errno.h>      /*錯誤號定義*/
+#include 	<errno.h>
+#include 	<string.h>
+#include	<time.h>
+#include	<ctype.h>
+#include 	<ifaddrs.h>
+#include 	<math.h>
+#include 	"internalComm.h"
+
+#define PASS				1
+#define FAIL				-1
+
+struct Address Addr={0x01,0x02,0x03,0xFF};
+struct Command Cmd={0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x81,0x83,0x85,0x86, 0x87,0x8B,0xe0,0xe1,0xe2,0xe3};
+
+int tranceive(int fd, unsigned char* cmd, unsigned char cmd_len, unsigned char* rx)
+{
+	int len;
+	//sleep(2); //required to make flush work, for some reason
+	tcflush(fd,TCIOFLUSH);
+	if(write(fd, cmd, cmd_len) >= cmd_len)
+	{
+		usleep(10000);
+		len = read(fd, rx, 512);
+	}
+	else
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("Serial command %s response fail.\n", cmd);
+		#endif
+	}
+
+	return len;
+}
+
+unsigned char Query_FW_Ver(unsigned char fd, unsigned char targetAddr, Ver *Ret_Buf)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_FW_Ver, 0x00, 0x00, 0x00};
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+	if(len > 6)
+	{
+		if (len < 6+(rx[4] | rx[5]<<8))
+			return result;
+
+		for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
+		{
+			chksum ^= rx[6+idx];
+		}
+
+		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
+		   (rx[2] == tx[1]) &&
+		   (rx[1] == tx[2]) &&
+		   (rx[3] == tx[3]))
+		{
+			memcpy(Ret_Buf->Version_FW, (char *)rx+6, (rx[4] | rx[5]<<8));
+			*(Ret_Buf->Version_FW + 8) = 0x00;
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+unsigned char Query_HW_Ver(unsigned char fd, unsigned char targetAddr, Ver *Ret_Buf)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_HW_Ver, 0x00, 0x00, 0x00};
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+	if(len > 6)
+	{
+		if (len < 6+(rx[4] | rx[5]<<8))
+			return result;
+
+		for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
+		{
+			chksum ^= rx[6+idx];
+		}
+
+		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
+		   (rx[2] == tx[1]) &&
+		   (rx[1] == tx[2]) &&
+		   (rx[3] == tx[3]))
+		{
+			memcpy(Ret_Buf->Version_HW, (char *)rx+6, (rx[4] | rx[5]<<8));
+			*(Ret_Buf->Version_HW + 8) = 0x00;
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+unsigned char Query_Present_InputVoltage(unsigned char fd, unsigned char targetAddr, PresentInputVoltage *Ret_Buf)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_Present_InputVoltage, 0x00, 0x00, 0x00};
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+	if(len > 6)
+	{
+		if (len < 6+(rx[4] | rx[5]<<8))
+			return result;
+
+		for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
+		{
+			chksum ^= rx[6+idx];
+		}
+		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
+		   (rx[2] == tx[1]) &&
+		   (rx[1] == tx[2]) &&
+		   (rx[3] == tx[3]))
+		{
+			Ret_Buf->inputType = rx[6];
+			Ret_Buf->L1N_L12 =(rx[7] | (rx[8]<<8))/10.0;
+			Ret_Buf->L2N_L23 =(rx[9] | (rx[10]<<8))/10.0;
+			Ret_Buf->L3N_L31 =(rx[11] | (rx[12]<<8))/10.0;
+
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+unsigned char Query_Present_OutputVoltage(unsigned char fd, unsigned char targetAddr, PresentOutputVoltage *Ret_Buf)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_Present_OutputVoltage, 0x00, 0x00, 0x00};
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+	if(len > 6)
+	{
+		if (len < 6+(rx[4] | rx[5]<<8))
+			return result;
+
+		for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
+		{
+			chksum ^= rx[6+idx];
+		}
+
+		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
+		   (rx[2] == tx[1]) &&
+		   (rx[1] == tx[2]) &&
+		   (rx[3] == tx[3]))
+		{
+
+			Ret_Buf->behindFuse_Voltage_C1 =(rx[6] | (rx[7]<<8));
+			Ret_Buf->behindRelay_Voltage_C1 =(rx[8] | (rx[9]<<8));
+			if((rx[4] | rx[5]<<8) > 4)
+			{
+				Ret_Buf->behindFuse_Voltage_C2 =(rx[10] | (rx[11]<<8));
+				Ret_Buf->behindRelay_Voltage_C2 =(rx[12] | (rx[13]<<8));
+			}
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+unsigned char Query_Fan_Speed(unsigned char fd, unsigned char targetAddr, FanSpeed *Ret_Buf)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_Fan_Speed, 0x00, 0x00, 0x00};
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+//		for (int i = 0; i < 7; i++)
+//			printf("tx = %x \n", tx[i]);
+//		for (int i = 0; i < len; i++)
+//			printf("rx = %x \n", rx[i]);
+
+	if(len > 6)
+	{
+		if (len < 6+(rx[4] | rx[5]<<8))
+			return result;
+
+		for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
+		{
+			chksum ^= rx[6+idx];
+		}
+
+		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
+		   (rx[2] == tx[1]) &&
+		   (rx[1] == tx[2]) &&
+		   (rx[3] == tx[3]))
+		{
+			for(int idx=0;idx < 4;idx++)
+				Ret_Buf->speed[idx] = (rx[6+(2*idx)] | (rx[6+(2*idx)+1]<<8));
+
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+unsigned char Query_Temperature(unsigned char fd, unsigned char targetAddr, Temperature *Ret_Buf)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_Temperature, 0x00, 0x00, 0x00};
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+	if(len > 6)
+	{
+		if (len < 6+(rx[4] | rx[5]<<8))
+			return result;
+
+		for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
+		{
+			chksum ^= rx[6+idx];
+		}
+
+		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
+		   (rx[2] == tx[1]) &&
+		   (rx[1] == tx[2]) &&
+		   (rx[3] == tx[3]))
+		{
+			for(int idx=0;idx < 4;idx++)
+				Ret_Buf->temperature[idx] = rx[6+idx] - 60;
+
+			result = PASS;
+		}
+	}
+
+
+	return result;
+}
+
+unsigned char Query_Aux_PowerVoltage(unsigned char fd, unsigned char targetAddr, AuxPower *Ret_Buf)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_Aux_PowerVoltage, 0x00, 0x00, 0x00};
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+	if(len > 6)
+	{
+		if (len < 6+(rx[4] | rx[5]<<8))
+			return result;
+
+		for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
+		{
+			chksum ^= rx[6+idx];
+		}
+
+		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
+		   (rx[2] == tx[1]) &&
+		   (rx[1] == tx[2]) &&
+		   (rx[3] == tx[3]))
+		{
+			for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
+				Ret_Buf->voltage[idx] = rx[6+idx];
+
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+unsigned char Query_Relay_Output(unsigned char fd, unsigned char targetAddr, Relay *Ret_Buf)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_Relay_Output, 0x00, 0x00, 0x00};
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+//	for (int i = 0; i < 7; i++)
+//		printf("tx = %x \n", tx[i]);
+//	for (int i = 0; i < len; i++)
+//		printf("rx = %x \n", rx[i]);
+
+	if(len > 6)
+	{
+		if (len < 6+(rx[4] | rx[5]<<8))
+			return result;
+
+		for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
+		{
+			chksum ^= rx[6+idx];
+		}
+
+		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
+		   (rx[2] == tx[1]) &&
+		   (rx[1] == tx[2]) &&
+		   (rx[3] == tx[3]))
+		{
+			Ret_Buf->relay_event.bits.AC_Contactor = (rx[6] >> 0) & 0x01;
+			Ret_Buf->relay_event.bits.CCS_Precharge = (rx[6] >> 1) & 0x01;
+
+			Ret_Buf->relay_event.bits.Gun1_N = (rx[7] >> 0) & 0x01;
+			Ret_Buf->relay_event.bits.Gun1_P = (rx[7] >> 1) & 0x01;
+			Ret_Buf->relay_event.bits.Gun1_Parallel_N = (rx[7] >> 2) & 0x01;
+			Ret_Buf->relay_event.bits.Gun1_Parallel_P = (rx[7] >> 3) & 0x01;
+
+			Ret_Buf->relay_event.bits.Gun2_N = (rx[8] >> 0) & 0x01;
+			Ret_Buf->relay_event.bits.Gun2_P = (rx[8] >> 1) & 0x01;
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+unsigned char Query_Gfd_Adc(unsigned char fd, unsigned char targetAddr, Gfd *Ret_Buf)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_Gfd_Adc, 0x00, 0x00, 0x00};
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+//	for(int i = 0; i < 7; i++)
+//		printf ("tx = %d \n", tx[i]);
+	if(len > 6)
+	{
+		if (len < 6+(rx[4] | rx[5]<<8))
+		{
+			//printf("Query_Gfd_Adc fail \n");
+			return result;
+		}
+
+//		for(int i = 0; i < len; i++)
+//			printf ("rx = %d \n", rx[i]);
+
+		for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
+		{
+			chksum ^= rx[6+idx];
+		}
+
+		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
+		   (rx[2] == tx[1]) &&
+		   (rx[1] == tx[2]) &&
+		   (rx[3] == tx[3]))
+		{
+			Ret_Buf->Resister_conn1 = (rx[6] | (rx[7] << 8));
+			Ret_Buf->voltage_conn1 = (rx[8] | (rx[9] << 8));
+			Ret_Buf->result_conn1 = rx[10];
+			Ret_Buf->rb_step_1 = rx[11];
+
+			Ret_Buf->Resister_conn2 = (rx[12] | (rx[13] << 8));
+			Ret_Buf->voltage_conn2 = (rx[14] | (rx[15] << 8));
+			Ret_Buf->result_conn2 = rx[16];
+			Ret_Buf->rb_step_2 = rx[17];
+
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+unsigned char Query_Gpio_Input(unsigned char fd, unsigned char targetAddr, Gpio_in *Ret_Buf)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_Gpio_In, 0x00, 0x00, 0x00};
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+	if(len > 6)
+	{
+		if (len < 6+(rx[4] | rx[5]<<8))
+			return result;
+
+		for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
+		{
+			chksum ^= rx[6+idx];
+		}
+
+		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
+		   (rx[2] == tx[1]) &&
+		   (rx[1] == tx[2]) &&
+		   (rx[3] == tx[3]))
+		{
+			Ret_Buf->AC_Connector 		= (rx[6] >> 0) & 0x01;
+			Ret_Buf->AC_MainBreaker 	= (rx[6] >> 1) & 0x01;
+			Ret_Buf->SPD 				= (rx[6] >> 2) & 0x01;
+			Ret_Buf->Door_Open 			= (rx[6] >> 3) & 0x01;
+			Ret_Buf->GFD[0] 			= (rx[6] >> 4) & 0x01;
+			Ret_Buf->GFD[1] 			= (rx[6] >> 5) & 0x01;
+			Ret_Buf->AC_Drop 			= (rx[6] >> 6) & 0x01;
+
+			Ret_Buf->Emergency_IO		= (rx[7] >> 0) & 0x01;
+
+			Ret_Buf->Button_Emergency_Press	= (rx[8] >> 0) & 0x01;
+			Ret_Buf->Button_On_Press 	= (rx[8] >> 1) & 0x01;
+			Ret_Buf->Button_Off_Press	= (rx[8] >> 2) & 0x01;
+			Ret_Buf->Key_1_Press 		= (rx[8] >> 3) & 0x01;
+			Ret_Buf->Key_2_Press 		= (rx[8] >> 4) & 0x01;
+			Ret_Buf->Key_3_Press 		= (rx[8] >> 5) & 0x01;
+			Ret_Buf->Key_4_Press 		= (rx[8] >> 6) & 0x01;
+
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+unsigned char Config_Fan_Speed(unsigned char fd, unsigned char targetAddr, FanSpeed *Set_Buf)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[15] = {0xaa, 0x00, targetAddr, Cmd.config_Fan_Speed, 0x08, 0x00, Set_Buf->speed[0]&0xff, (Set_Buf->speed[0]>>8)&0xff, Set_Buf->speed[1]&0xff, (Set_Buf->speed[1]>>8)&0xff, Set_Buf->speed[2]&0xff, (Set_Buf->speed[2]>>8)&0xff, Set_Buf->speed[3]&0xff, (Set_Buf->speed[3]>>8)&0xff, 0x00};
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+
+	for(int idx = 0;idx<(tx[4] | tx[5]<<8);idx++)
+		chksum ^= tx[6+idx];
+	tx[14] = chksum;
+
+//		for(int i = 0; i < 15; i++)
+//			printf ("tx = %x \n", tx[i]);
+
+	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+//	for(int i = 0; i < len; i++)
+//				printf ("rx = %x \n", rx[i]);
+	if(len > 6)
+	{
+		if (len < 6+(rx[4] | rx[5]<<8))
+			return result;
+
+		chksum = 0x00;
+		for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
+		{
+			chksum ^= rx[6+idx];
+		}
+
+		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
+		   (rx[2] == tx[1]) &&
+		   (rx[1] == tx[2]) &&
+		   (rx[3] == tx[3]))
+		{
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+unsigned char Config_Relay_Output(unsigned char fd, unsigned char targetAddr, Relay *Set_Buf)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[10] = {0xaa, 0x00, targetAddr, Cmd.config_Relay_Output, 0x03, 0x00, Set_Buf->relay_event.relay_status[0], Set_Buf->relay_event.relay_status[1], Set_Buf->relay_event.relay_status[2]};
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+
+	for(int idx = 0;idx<(tx[4] | tx[5]<<8);idx++)
+		chksum ^= tx[6 + idx];
+	tx[9] = chksum;
+
+//	for (int i = 0; i < 10; i++)
+//		printf("set relay cmd : tx = %x \n", tx[i]);
+
+	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+	if(len > 6)
+	{
+		if (len < 6+(rx[4] | rx[5]<<8))
+			return result;
+
+//		for (int i = 0; i < len; i++)
+//			printf("set relay cmd : rx = %x \n", rx[i]);
+
+		chksum = 0x00;
+		for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
+		{
+			chksum ^= rx[6+idx];
+		}
+
+		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
+		   (rx[2] == tx[1]) &&
+		   (rx[1] == tx[2]) &&
+		   (rx[3] == tx[3]) &&
+		   (rx[6] == 0x01))
+		{
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+unsigned char Config_Gpio_Output(unsigned char fd, unsigned char targetAddr, Gpio_out *Set_Buf)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[9] = {0xaa, 0x00, targetAddr, Cmd.config_Gpio_Output, 0x01, 0x00, 0x00, 0x00};
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+
+	tx[6] |= (Set_Buf->AC_Connector?0x01:0x00);
+
+	for(int idx = 0;idx<2;idx++)
+		tx[6] |= (Set_Buf->Button_LED[idx]?0x01:0x00)<<(1+idx);
+
+	for(int idx = 0;idx<4;idx++)
+			tx[6] |= (Set_Buf->System_LED[idx]?0x01:0x00)<<(3+idx);
+
+	for(int idx = 0;idx<(tx[4] | tx[5]<<8);idx++)
+		chksum ^= tx[6+idx];
+	tx[14] = chksum;
+
+	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+	if(len > 6)
+	{
+		if (len < 6+(rx[4] | rx[5]<<8))
+			return result;
+
+		chksum = 0x00;
+		for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
+		{
+			chksum ^= rx[6+idx];
+		}
+
+		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
+		   (rx[2] == tx[1]) &&
+		   (rx[1] == tx[2]) &&
+		   (rx[3] == tx[3]) &&
+		   (rx[6] == tx[6]))
+		{
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+unsigned char Config_Gfd_Value(unsigned char fd, unsigned char targetAddr, Gfd_config *Set_Buf)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[9] = {0xaa, 0x00, targetAddr, Cmd.config_Gfd_Value, 0x02, 0x00, 0x00, 0x00, 0x00};
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+
+	tx[6] = Set_Buf->index;
+	tx[7] = Set_Buf->state;
+
+	for(int idx = 0; idx<(tx[4] | tx[5]<<8);idx++)
+		chksum ^= tx[6+idx];
+	tx[8] = chksum;
+
+	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+	if(len > 6)
+	{
+		if (len < 6+(rx[4] | rx[5]<<8))
+			return result;
+
+		chksum = 0x00;
+		for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
+		{
+			chksum ^= rx[6+idx];
+		}
+
+		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
+		   (rx[2] == tx[1]) &&
+		   (rx[1] == tx[2]) &&
+		   (rx[3] == tx[3]) &&
+		   (rx[6] == tx[6]))
+		{
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+unsigned char Config_Model_Name(unsigned char fd, unsigned char targetAddr, unsigned char *modelname)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[21] = {0xaa, 0x00, targetAddr, Cmd.config_Model_Name, 0x0E, 0x00,
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+
+	memcpy(tx + 6, modelname, 14);
+
+	for(int idx = 0; idx<(tx[4] | tx[5]<<8);idx++)
+		chksum ^= tx[6+idx];
+	tx[20] = chksum;
+
+//	for(int i = 0; i < 21; i++)
+//				printf ("tx = %x \n", tx[i]);
+	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+//	for(int i = 0; i < len; i++)
+//					printf ("rx = %x \n", rx[i]);
+	if(len > 6)
+	{
+		if (len < 6+(rx[4] | rx[5]<<8))
+			return result;
+
+		chksum = 0x00;
+		for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
+		{
+			chksum ^= rx[6+idx];
+		}
+
+		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
+			  (rx[2] == tx[1]) &&
+			  (rx[1] == tx[2]) &&
+			  (rx[3] == tx[3]) &&
+			  (rx[6] == tx[6]))
+		{
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+unsigned char Config_Rtc_Data(unsigned char fd, unsigned char targetAddr, Rtc *Set_Buf)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[21] = { 0xaa, 0x00, targetAddr, Cmd.config_Rtc_Data, 0x0E, 0x00, Set_Buf->RtcData[0], Set_Buf->RtcData[1],
+			Set_Buf->RtcData[2], Set_Buf->RtcData[3], Set_Buf->RtcData[4], Set_Buf->RtcData[5], Set_Buf->RtcData[6], Set_Buf->RtcData[7],
+			Set_Buf->RtcData[8], Set_Buf->RtcData[9], Set_Buf->RtcData[10], Set_Buf->RtcData[11], Set_Buf->RtcData[12], Set_Buf->RtcData[13]};
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+
+	for (int idx = 0; idx < (tx[4] | tx[5] << 8); idx++)
+		chksum ^= tx[6 + idx];
+	tx[20] = chksum;
+
+	if (tranceive(fd, tx, sizeof(tx), rx) > 0)
+	{
+		chksum = 0x00;
+		for (int idx = 0; idx < (rx[4] | rx[5] << 8); idx++)
+		{
+			chksum ^= rx[6 + idx];
+		}
+
+		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
+				(rx[2] == tx[1]) &&
+				(rx[1] == tx[2]) &&
+				(rx[3] == tx[3]) &&
+				(rx[6] == tx[6]))
+		{
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+unsigned char Update_Start(unsigned char fd, unsigned char targetAddr, unsigned int crc32)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[11] = {0xaa, 0x00, targetAddr, Cmd.update_Start, 0x04, 0x00, (crc32>>0)&0xff, (crc32>>8)&0xff, (crc32>>16)&0xff, (crc32>>24)&0xff, 0x00};
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+
+	for(int idx = 0;idx<(tx[4] | tx[5]<<8);idx++)
+		chksum ^= tx[6+idx];
+	tx[10] = chksum;
+
+	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+	if(len > 6)
+	{
+		if (len < 6+(rx[4] | rx[5]<<8))
+			return result;
+
+		chksum = 0x00;
+		for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
+		{
+			chksum ^= rx[6+idx];
+		}
+
+		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
+		   (rx[2] == tx[1]) &&
+		   (rx[1] == tx[2]) &&
+		   (rx[3] == tx[3]) &&
+		   (rx[6] == 0x00))
+		{
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+unsigned char Update_Abord(unsigned char fd, unsigned char targetAddr)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.update_Start, 0x04, 0x00, 0x00};
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+	if(len > 6)
+	{
+		if (len < 6+(rx[4] | rx[5]<<8))
+			return result;
+
+		for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
+		{
+			chksum ^= rx[6+idx];
+		}
+
+		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
+		   (rx[2] == tx[1]) &&
+		   (rx[1] == tx[2]) &&
+		   (rx[3] == tx[3]) &&
+		   (rx[6] == 0x00))
+		{
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+unsigned char Update_Transfer(unsigned char fd, unsigned char targetAddr, unsigned int startAddr, unsigned char *data, unsigned short int length)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[11 + length];
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+
+	tx[0] = 0xaa;
+	tx[1] = 0x00;
+	tx[2] = targetAddr;
+	tx[3] = Cmd.update_Transfer;
+	tx[4] = (4 + length) & 0xff;
+	tx[5] = ((4 + length)>>8) & 0xff;
+	tx[6] = (startAddr>>0) & 0xff;
+	tx[7] = (startAddr>>8) & 0xff;
+	tx[8] = (startAddr>>16) & 0xff;
+	tx[9] = (startAddr>>24) & 0xff;
+	memcpy(tx+10, data, length);
+
+	for(int idx = 0;idx<(tx[4] | tx[5]<<8);idx++)
+		chksum ^= tx[6+idx];
+	tx[sizeof(tx)-1] = chksum;
+
+	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+	if(len > 6)
+	{
+		if (len < 6+(rx[4] | rx[5]<<8))
+			return result;
+
+		for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
+		{
+			chksum ^= rx[6+idx];
+		}
+
+		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
+		   (rx[2] == tx[1]) &&
+		   (rx[1] == tx[2]) &&
+		   (rx[3] == tx[3]) &&
+		   (rx[6] == 0x00))
+		{
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+unsigned char Update_Finish(unsigned char fd, unsigned char targetAddr)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.update_Finish, 0x04, 0x00, 0x00};
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+	if(len > 6)
+	{
+		if (len < 6+(rx[4] | rx[5]<<8))
+			return result;
+
+		for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
+		{
+			chksum ^= rx[6+idx];
+		}
+
+		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
+		   (rx[2] == tx[1]) &&
+		   (rx[1] == tx[2]) &&
+		   (rx[3] == tx[3]) &&
+		   (rx[6] == 0x00))
+		{
+			result = PASS;
+		}
+	}
+
+	return result;
+}

+ 194 - 0
EVSE/Projects/PlugIt360/Apps/internalComm.h

@@ -0,0 +1,194 @@
+/*
+ * internalComm.h
+ *
+ *  Created on: 2019¦~5¤ë7¤é
+ *      Author: foluswen
+ */
+
+#ifndef INTERNALCOMM_H_
+#define INTERNALCOMM_H_
+
+extern struct Address
+{
+	unsigned char Aux;
+	unsigned char Fan;
+	unsigned char Relay;
+	unsigned char Broadcast;
+}Addr;
+
+extern struct Command
+{
+	unsigned char query_FW_Ver; 				//0x01
+	unsigned char query_HW_Ver; 				//0x02
+	unsigned char query_Present_InputVoltage;	//0x03
+	unsigned char query_Present_OutputVoltage;	//0x04
+	unsigned char query_Fan_Speed;				//0x05
+	unsigned char query_Temperature;			//0x06
+	unsigned char query_Aux_PowerVoltage;		//0x07
+	unsigned char query_Relay_Output;			//0x08
+	unsigned char query_Gfd_Adc;				//0x09
+	unsigned char query_Gpio_In;				//0x0a
+
+	unsigned char config_Fan_Speed;			//0x81
+	unsigned char config_Model_Name;			//0x83
+	unsigned char config_Relay_Output;			//0x85
+	unsigned char config_Gpio_Output;			//0x86
+	unsigned char config_Rtc_Data;				//0x87
+	unsigned char config_Gfd_Value;			//0x8B
+
+	unsigned char update_Start;				//0xe0
+	unsigned char update_Abort;				//0xe1
+	unsigned char update_Transfer;				//0xe2
+	unsigned char update_Finish;				//0xe3
+
+}Cmd;
+
+typedef struct Verion
+{
+	char Version_FW[9];
+	char Version_HW[9];
+}Ver;
+
+typedef struct PRESENTINPUTVOLTAGE
+{
+	unsigned char inputType;	// 0x00: Line to Line       0x01: Line to Neutral
+	double L1N_L12;
+	double L2N_L23;
+	double L3N_L31;
+}PresentInputVoltage;
+
+typedef struct PRESENTOUTPUTVOLTAGE
+{
+	double behindFuse_Voltage_C1;
+	double behindRelay_Voltage_C1;
+	double behindFuse_Voltage_C2;
+	double behindRelay_Voltage_C2;
+}PresentOutputVoltage;
+
+typedef struct FANSPEED
+{
+	unsigned short int speed[8];
+}FanSpeed;
+
+typedef struct TEMPERATURE
+{
+	unsigned char temperature[8];
+}Temperature;
+
+typedef struct AUXPOWER
+{
+	unsigned char voltage[8];
+}AuxPower;
+
+typedef struct RELAY
+{
+	union
+	{
+		unsigned char relay_status[8];
+		struct
+		{
+			unsigned char AC_Contactor :1;		//bit 0
+			unsigned char CCS_Precharge :1;	//bit 1
+			unsigned char :1;  				//bit 2 reserved
+			unsigned char :1;					//bit 3 reserved
+			unsigned char :1;					//bit 4 reserved
+			unsigned char :1;					//bit 5 reserved
+			unsigned char :1;					//bit 6 reserved
+			unsigned char :1;					//bit 7 reserved
+
+			unsigned char Gun1_N :1;			//bit 0
+			unsigned char Gun1_P :1;			//bit 1
+			unsigned char Gun1_Parallel_N :1;  //bit 2
+			unsigned char Gun1_Parallel_P :1;	//bit 3
+			unsigned char :1;					//bit 4 reserved
+			unsigned char :1;					//bit 5 reserved
+			unsigned char :1;					//bit 6 reserved
+			unsigned char :1;					//bit 7 reserved
+
+			unsigned char Gun2_N :1;			//bit 0
+			unsigned char Gun2_P :1;			//bit 1
+			unsigned char :1; 					//bit 2 reserved
+			unsigned char :1;					//bit 3 reserved
+			unsigned char :1;					//bit 4 reserved
+			unsigned char :1;					//bit 5 reserved
+			unsigned char :1;					//bit 6 reserved
+			unsigned char :1;					//bit 7 reserved
+		}bits;
+	}relay_event;
+}Relay;
+
+typedef struct GFD
+{
+	unsigned short Resister_conn1;
+	unsigned short voltage_conn1;
+	unsigned char result_conn1;
+	unsigned char rb_step_1;
+
+	unsigned short Resister_conn2;
+	unsigned short voltage_conn2;
+	unsigned char result_conn2;
+	unsigned char rb_step_2;
+}Gfd;
+
+typedef struct Gfd_CONFIG
+{
+	unsigned char index;
+	unsigned char state;
+}Gfd_config;
+
+typedef struct GPIO_IN
+{
+	unsigned char AC_Connector;			// bit 0
+	unsigned char AC_MainBreaker;			// bit 1
+	unsigned char SPD;						// bit 2
+	unsigned char Door_Open;				// bit 3
+	unsigned char GFD[2];					// bit 4,5
+	unsigned char AC_Drop;					// bit 6
+
+	unsigned char Emergency_IO;			// bit 0
+
+	unsigned char Button_Emergency_Press;	// bit 0
+	unsigned char Button_On_Press;			// bit 1
+	unsigned char Button_Off_Press;		// bit 2
+	unsigned char Key_1_Press;				// bit 3
+	unsigned char Key_2_Press;				// bit 4
+	unsigned char Key_3_Press;				// bit 5
+	unsigned char Key_4_Press;				// bit 6
+}Gpio_in;
+
+typedef struct GPIO_OUT
+{
+	unsigned char AC_Connector;
+	unsigned char Button_LED[2];
+	unsigned char System_LED[4];
+}Gpio_out;
+
+typedef struct RTC
+{
+	unsigned char RtcData[14];
+}Rtc;
+
+extern unsigned char Query_FW_Ver(unsigned char fd, unsigned char targetAddr, Ver *Ret_Buf);
+extern unsigned char Query_HW_Ver(unsigned char fd, unsigned char targetAddr, Ver *Ret_Buf);
+extern unsigned char Query_Present_InputVoltage(unsigned char fd, unsigned char targetAddr, PresentInputVoltage *Ret_Buf);
+extern unsigned char Query_Present_OutputVoltage(unsigned char fd, unsigned char targetAddr, PresentOutputVoltage *Ret_Buf);
+extern unsigned char Query_Fan_Speed(unsigned char fd, unsigned char targetAddr, FanSpeed *Ret_Buf);
+extern unsigned char Query_Temperature(unsigned char fd, unsigned char targetAddr, Temperature *Ret_Buf);
+extern unsigned char Query_Aux_PowerVoltage(unsigned char fd, unsigned char targetAddr, AuxPower *Ret_Buf);
+extern unsigned char Query_Relay_Output(unsigned char fd, unsigned char targetAddr, Relay *Ret_Buf);
+extern unsigned char Query_Gfd_Adc(unsigned char fd, unsigned char targetAddr, Gfd *Ret_Buf);
+extern unsigned char Query_Gpio_Input(unsigned char fd, unsigned char targetAddr, Gpio_in *Ret_Buf);
+
+extern unsigned char Config_Fan_Speed(unsigned char fd, unsigned char targetAddr, FanSpeed *Set_Buf);
+extern unsigned char Config_Relay_Output(unsigned char fd, unsigned char targetAddr, Relay *Set_Buf);
+extern unsigned char Config_Gpio_Output(unsigned char fd, unsigned char targetAddr, Gpio_out *Set_Buf);
+extern unsigned char Config_Gfd_Value(unsigned char fd, unsigned char targetAddr, Gfd_config *Set_Buf);
+extern unsigned char Config_Model_Name(unsigned char fd, unsigned char targetAddr, unsigned char *modelname);
+extern unsigned char Config_Rtc_Data(unsigned char fd, unsigned char targetAddr, Rtc *Set_Buf);
+
+extern unsigned char Update_Start(unsigned char fd, unsigned char targetAddr, unsigned int crc32);
+extern unsigned char Update_Abord(unsigned char fd, unsigned char targetAddr);
+extern unsigned char Update_Transfer(unsigned char fd, unsigned char targetAddr, unsigned int startAddr, unsigned char *data, unsigned short int length);
+extern unsigned char Update_Finish(unsigned char fd, unsigned char targetAddr);
+
+#endif /* INTERNALCOMM_H_ */

+ 12 - 0
EVSE/Projects/PlugIt360/Apps/kill.sh

@@ -0,0 +1,12 @@
+pkill Module_CSU
+pkill Module_PrimaryComm
+pkill Module_LcmControl
+pkill Module_InternalComm
+pkill Module_EventLogging
+pkill Module_EvComm
+pkill Module_PsuComm
+pkill Module_4g
+pkill Module_Wifi
+pkill OcppBackend
+pkill main
+

BIN
EVSE/Projects/PlugIt360/Apps/main


+ 3743 - 0
EVSE/Projects/PlugIt360/Apps/main.c

@@ -0,0 +1,3743 @@
+#include    <sys/types.h>
+#include    <sys/stat.h>
+#include 	<sys/time.h>
+#include 	<sys/timeb.h>
+#include 	<sys/types.h>
+#include 	<sys/ioctl.h>
+#include 	<sys/socket.h>
+#include 	<sys/ipc.h>
+#include 	<sys/shm.h>
+#include 	<sys/mman.h>
+#include 	<linux/wireless.h>
+#include 	<arpa/inet.h>
+#include 	<netinet/in.h>
+
+#include 	<unistd.h>
+#include 	<stdarg.h>
+#include    <stdio.h>      /*標準輸入輸出定義*/
+#include    <stdlib.h>     /*標準函數庫定義*/
+#include    <unistd.h>     /*Unix 標準函數定義*/
+#include    <fcntl.h>      /*檔控制定義*/
+#include    <termios.h>    /*PPSIX 終端控制定義*/
+#include    <errno.h>      /*錯誤號定義*/
+#include 	<errno.h>
+#include 	<string.h>
+#include 	<stdint.h>
+#include	<time.h>
+#include	<ctype.h>
+#include 	<ifaddrs.h>
+#include 	<math.h>
+#include 	"../../define.h"
+#include 	"Config.h"
+#include 	<stdbool.h>
+#include 	<dirent.h>
+#include	"timeout.h"
+
+#define 	ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
+#define 	PASS				1
+#define 	FAIL				-1
+#define 	BUFFER_SIZE			128
+#define 	YES					1
+#define 	NO					0
+#define 	NORMAL				0
+#define		ABNORMAL			1
+#define 	EQUAL				0
+#define 	BTN_RELEASE			0
+#define 	BTN_PRESS			1
+#define 	MAX_BUF 			64
+#define 	MtdBlockSize 		0x600000
+#define 	SYSFS_GPIO_DIR 		"/sys/class/gpio"
+#define		UPGRADE_FAN			0x02
+#define		UPGRADE_RB			0x03
+#define		UPGRADE_PRI			0x04
+
+char 	*valid_Internet[2] 	  = {"8.8.8.8", "180.76.76.76"};
+unsigned char mask_table[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
+int whileLoopTime = 10000; // 10 ms
+int	wtdFd = -1;
+
+bool IsAuthorizingMode();
+void ClearAuthorizedFlag();
+bool isDetectPlugin();
+void ClearDetectPluginFlag();
+int mystrcmp(unsigned char *p1, unsigned char *p2);
+
+unsigned char DetectBitValue(unsigned char _byte, unsigned char _bit);
+void SetBitValue(unsigned char *_byte, unsigned char _bit, unsigned char value);
+void ChargingTerminalProcess(byte gunIndex);
+void ChkPrimaryStatus();
+void StartSystemTimeoutDet(unsigned char flag);
+void StopSystemTimeoutDet();
+void StartGunInfoTimeoutDet(unsigned char gunIndex, unsigned char flag);
+void StopGunInfoTimeoutDet(unsigned char gunIndex);
+int StoreLogMsg_1(const char *fmt, ...);
+unsigned long GetTimeoutValue(struct timeval _sour_time);
+void gpio_set_value(unsigned int gpio, unsigned int value);
+void PRINTF_FUNC(char *string, ...);
+
+#define DEBUG_INFO_MSG(format, args...) StoreLogMsg_1("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define DEBUG_WARN_MSG(format, args...) StoreLogMsg_1("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define DEBUG_ERROR_MSG(format, args...) StoreLogMsg_1("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+
+struct SysConfigAndInfo			*ShmSysConfigAndInfo;
+struct StatusCodeData 			*ShmStatusCodeData;
+struct PsuData 					*ShmPsuData;
+struct CHAdeMOData				*ShmCHAdeMOData;
+struct CcsData					*ShmCcsData;
+struct PrimaryMcuData			*ShmPrimaryMcuData;
+struct FanModuleData			*ShmFanModuleData;
+struct RelayModuleData			*ShmRelayModuleData;
+struct OCPP16Data				*ShmOCPP16Data;
+
+struct ChargingInfoData			*chargingInfo[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+struct timeb 					startChargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+struct timeb 					endChargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+
+byte _gunCount = 0;
+// for initial index to check EV board type is correct
+byte _gunIndex = 0;
+byte _chademoIndex = 0;
+byte _ccsIndex = 0;
+byte _gb_Index = 0;
+byte bd0_1_status = 0;
+byte bd0_2_status = 0;
+byte bd1_1_status = 0;
+byte bd1_2_status = 0;
+
+bool isCardScan = false;
+
+int rfidFd = -1;
+char* rfidPortName = "/dev/ttyS2";
+
+//================================================
+// initial can-bus
+//================================================
+int InitCanBus()
+{
+	int 					s0,nbytes;
+	struct timeval			tv;
+	struct ifreq 			ifr0;
+	struct sockaddr_can		addr0;
+
+	system("/sbin/ip link set can0 down");
+	system("/sbin/ip link set can0 type can bitrate 500000 restart-ms 100");
+	system("/sbin/ip link set can0 up");
+
+	s0 = socket(PF_CAN, SOCK_RAW, CAN_RAW);
+
+	tv.tv_sec = 0;
+	tv.tv_usec = 10000;
+   	if (setsockopt(s0, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct	timeval)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("Set SO_RCVTIMEO NG");
+		#endif
+	}
+	nbytes=40960;
+	if (setsockopt(s0, SOL_SOCKET,  SO_RCVBUF, &nbytes, sizeof(int)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("Set SO_RCVBUF NG");
+		#endif
+	}
+	nbytes=40960;
+	if (setsockopt(s0, SOL_SOCKET, SO_SNDBUF, &nbytes, sizeof(int)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("Set SO_SNDBUF NG");
+		#endif
+	}
+
+   	strcpy(ifr0.ifr_name, "can0" );
+	ioctl(s0, SIOCGIFINDEX, &ifr0); /* ifr.ifr_ifindex gets filled with that device's index */
+	addr0.can_family = AF_CAN;
+	addr0.can_ifindex = ifr0.ifr_ifindex;
+	bind(s0, (struct sockaddr *)&addr0, sizeof(addr0));
+	return s0;
+}
+
+//================================================
+// initial uart port
+//================================================
+char *_priPortName = "/dev/ttyS1";
+char *_485PortName = "/dev/ttyS5";
+
+int InitComPort(byte target)
+{
+	int fd;
+	struct termios tios;
+
+	if(target == UPGRADE_PRI)
+		fd = open(_priPortName, O_RDWR);
+	else if (target == UPGRADE_FAN ||  target == UPGRADE_RB)
+		fd = open(_485PortName, O_RDWR);
+
+	if(fd<=0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("open 407 Communication port NG \n");
+		#endif
+		return -1;
+	}
+	ioctl (fd, TCGETS, &tios);
+	tios.c_cflag = B115200| CS8 | CLOCAL | CREAD;
+	tios.c_lflag = 0;
+	tios.c_iflag = 0;
+	tios.c_oflag = 0;
+	tios.c_cc[VMIN]=0;
+	tios.c_cc[VTIME]=(unsigned char)1;
+	tios.c_lflag=0;
+	tcflush(fd, TCIFLUSH);
+	ioctl (fd, TCSETS, &tios);
+
+	return fd;
+}
+
+//=================================
+// Common routine
+//=================================
+int InitWatchDog()
+{
+	int fd;
+	system("/usr/bin/fuser -k /dev/watchdog");
+	sleep(1);
+	system("echo V > /dev/watchdog");
+	sleep(1);
+	fd=open("/dev/watchdog", O_RDWR);
+
+	if(fd<=0)
+	{
+		DEBUG_ERROR_MSG("System watch dog initial fail.\r\n");
+	}
+	return fd;
+}
+
+int StoreLogMsg_1(const char *fmt, ...)
+{
+	char Buf[4096+256];
+	char buffer[4096];
+	time_t CurrentTime;
+	struct tm *tm;
+	va_list args;
+
+	va_start(args, fmt);
+	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
+	va_end(args);
+
+	memset(Buf,0,sizeof(Buf));
+	CurrentTime = time(NULL);
+	tm=localtime(&CurrentTime);
+	sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
+			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
+			buffer,
+			tm->tm_year+1900,tm->tm_mon+1);
+	system(Buf);
+
+	return rc;
+}
+
+unsigned long GetTimeoutValue(struct timeval _sour_time)
+{
+	struct timeval _end_time;
+	gettimeofday(&_end_time, NULL);
+
+	return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
+}
+
+int mystrcmp(unsigned char *p1, unsigned char *p2)
+{
+    while(*p1==*p2)
+    {
+        if(*p1=='\0' || *p2=='\0')
+            break;
+        p1++;
+        p2++;
+    }
+    if(*p1=='\0' && *p2=='\0')
+        return(PASS);
+    else
+        return(FAIL);
+}
+
+int DiffTimeb(struct timeb ST, struct timeb ET)
+{
+	//return milli-second
+	unsigned int StartTime,StopTime;
+
+	StartTime=(unsigned int)ST.time;
+	StopTime=(unsigned int)ET.time;
+	//return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
+	return (StopTime-StartTime);
+}
+
+bool CheckTimeOut(struct timeb ST)
+{
+	struct timeb ET;
+	unsigned int StartTime, StopTime;
+
+	ftime(&ET);
+	StartTime = (unsigned int) ST.time;
+	StopTime = (unsigned int) ET.time;
+	return (StopTime > StartTime)? YES : NO;
+}
+
+void setChargerMode(byte gun_index, byte mode)
+{
+	chargingInfo[gun_index]->SystemStatus = mode;
+}
+
+void PRINTF_FUNC(char *string, ...)
+{
+	if (DEBUG)
+	{
+		va_list args;
+		char buffer[4096];
+
+		va_start(args, string);
+		vsnprintf(buffer, sizeof(buffer), string, args);
+		va_end(args);
+		printf("%s \n", buffer);
+	}
+}
+//==========================================
+// Check interface status
+//==========================================
+int isInterfaceUp(const char *interface)
+{
+	int result = FAIL;
+
+	FILE *fp;
+	char cmd[256];
+	char buf[512];
+
+	strcpy(cmd, "ifconfig");
+	fp = popen(cmd, "r");
+	if(fp != NULL)
+	{
+		while(fgets(buf, sizeof(buf), fp) != NULL)
+		{
+			if(strstr(buf, interface) > 0)
+			{
+				result = PASS;
+			}
+		}
+	}
+	pclose(fp);
+
+	return result;
+}
+
+//=================================
+// Create all share memory
+//=================================
+int CreateShareMemory()
+{
+	int MeterSMId;
+
+	if ((MeterSMId = shmget(ShmSysConfigAndInfoKey,	sizeof(struct SysConfigAndInfo), IPC_CREAT | 0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmSysConfigAndInfo NG \n");
+		#endif
+		return 0;
+	}
+	else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0))	== (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmSysConfigAndInfo NG \n");
+		#endif
+		return 0;
+	}
+	memset(ShmSysConfigAndInfo, 0, sizeof(struct SysConfigAndInfo));
+
+	if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), IPC_CREAT | 0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmStatusCodeData NG \n");
+		#endif
+		return 0;
+	}
+	else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmStatusCodeData NG \n");
+		#endif
+		return 0;
+	}
+
+	memset(ShmStatusCodeData, 0, sizeof(struct StatusCodeData));
+
+	//creat ShmPsuData
+	if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), IPC_CREAT | 0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmPsuData NG \n");
+		#endif
+		return 0;
+	}
+	else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmPsuData NG \n");
+		#endif
+		return 0;
+	}
+	memset(ShmPsuData, 0, sizeof(struct PsuData));
+
+	if(CHAdeMO_QUANTITY > 0)
+	{
+		if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData),	IPC_CREAT | 0777)) < 0)
+		{
+			#ifdef SystemLogMessage
+			DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmCHAdeMOData NG \n");
+			#endif
+			return 0;
+		}
+		else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+		{
+			#ifdef SystemLogMessage
+			DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmCHAdeMOData NG \n");
+			#endif
+			return 0;
+		}
+		memset(ShmCHAdeMOData, 0, sizeof(struct CHAdeMOData));
+	}
+
+	//creat ShmCcsData
+	if(CCS_QUANTITY > 0)
+	{
+		if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData),	IPC_CREAT | 0777)) < 0)
+		{
+			#ifdef SystemLogMessage
+			DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmCcsData NG \n");
+			#endif
+			return 0;
+		}
+		else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+		{
+			#ifdef SystemLogMessage
+			DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmCcsData NG \n");
+			#endif
+			return 0;
+		}
+		memset(ShmCcsData, 0, sizeof(struct CcsData));
+	}
+
+	//creat ShmPrimaryMcuData
+	if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), IPC_CREAT | 0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmPrimaryMcuData NG \n");
+		#endif
+		return 0;
+	}
+	else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmPrimaryMcuData NG \n");
+		#endif
+		return 0;
+	}
+	memset(ShmPrimaryMcuData, 0, sizeof(struct PrimaryMcuData));
+
+	//creat ShmFanModuleData
+	if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData),	IPC_CREAT | 0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmFanModuleData NG \n");
+		#endif
+		return 0;
+	}
+	else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmFanModuleData NG \n");
+		#endif
+		return 0;
+	}
+	memset(ShmFanModuleData, 0, sizeof(struct FanModuleData));
+
+	//creat ShmRelayModuleData
+	if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData),	IPC_CREAT | 0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmRelayModuleData NG \n");
+		#endif
+		return 0;
+	}
+	else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmRelayModuleData NG \n");
+		#endif
+		return 0;
+	}
+	memset(ShmRelayModuleData, 0, sizeof(struct RelayModuleData));
+
+	//creat ShmOCPP16Data
+	if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), IPC_CREAT | 0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmOCPP16Data NG \n");
+		#endif
+		return 0;
+	}
+	else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmOCPP16Data NG \n");
+		#endif
+		return 0;
+	}
+	// memset(ShmOCPP16Data,0,sizeof(struct OCPP16Data));
+	return 1;
+}
+
+//=================================
+// LCM Page
+//=================================
+void ChangeLcmByIndex(byte page_index)
+{
+	if (ShmSysConfigAndInfo->SysWarningInfo.Level != 2 ||
+			page_index == _LCM_COMPLETE || page_index == _LCM_FIX)
+	{
+		ShmSysConfigAndInfo->SysInfo.PageIndex = page_index;
+	}
+}
+
+//======================================================
+// Peripheral initial
+//======================================================
+void InitGPIO()
+{
+	/*****************0~3, 4 bank, bank x 32+ num*********************/
+	/***************************************************************/
+	/*************** GPIO 0 ***************************************/
+	/***************************************************************/
+	/* GPMC_AD8			=> 	GPIO0_22 *//*ID BD1_1*/
+	system("echo 22 > /sys/class/gpio/export");
+	system("echo \"in\" > /sys/class/gpio/gpio22/direction");
+	/* GPMC_AD9			=>	GPIO0_23 *//*ID BD1_2*/
+	system("echo 23 > /sys/class/gpio/export");
+	system("echo \"in\" > /sys/class/gpio/gpio23/direction");
+	/* GPMC_AD10		=>	GPIO0_26 *//*IO BD1_1*/
+	system("echo 26 > /sys/class/gpio/export");
+	system("echo \"out\" > /sys/class/gpio/gpio26/direction");
+	system("echo 1 > /sys/class/gpio/gpio26/value");
+	/* GPMC_AD11		=>	GPIO0_27 *//*IO BD1_2*/
+	system("echo 27 > /sys/class/gpio/export");
+	system("echo \"in\" > /sys/class/gpio/gpio27/direction");
+	/* RMII1_REF_CLK		=>	GPIO0_29 *//*USB 0 OCP detection*/
+	system("echo 29 > /sys/class/gpio/export");
+	system("echo \"in\" > /sys/class/gpio/gpio29/direction");
+	/*XDMA_EVENT_INTR0	=>	GPIO0_19 *//*AM_RFID_RST*/
+	system("echo 19 > /sys/class/gpio/export");
+	system("echo \"out\" > /sys/class/gpio/gpio19/direction");
+	system("echo 1 > /sys/class/gpio/gpio19/value");
+	/*XDMA_EVENT_INTR1	=>	GPIO0_20 *//*AM_RFID_ICC*/
+	system("echo 20 > /sys/class/gpio/export");
+	system("echo \"in\" > /sys/class/gpio/gpio20/direction");
+	/***************************************************************/
+	/*************** GPIO 1 ***************************************/
+	/***************************************************************/
+	/* GPMC_AD12	=> 	GPIO1_12 *//*ID BD2_1*/
+	system("echo 44 > /sys/class/gpio/export");
+	system("echo \"in\" > /sys/class/gpio/gpio44/direction");
+	/* GPMC_AD13	=>	GPIO1_13 *//*ID BD2_2*/
+	system("echo 45 > /sys/class/gpio/export");
+	system("echo \"in\" > /sys/class/gpio/gpio45/direction");
+	/* GPMC_AD14	=>	GPIO1_14 *//*IO BD2_1*/
+	system("echo 46 > /sys/class/gpio/export");
+	system("echo \"out\" > /sys/class/gpio/gpio46/direction");
+	system("echo 0 > /sys/class/gpio/gpio46/value");
+	/* GPMC_AD15	=>	GPIO1_15 *//*IO BD2_2*/
+	system("echo 47 > /sys/class/gpio/export");
+	system("echo \"in\" > /sys/class/gpio/gpio47/direction");
+	/***************************************************************/
+	/*************** GPIO 2 ***************************************/
+	/***************************************************************/
+	/*LCD_AC_BIAS_EN	=>	GPIO2_25*//*RS-485 for module DE control*/
+	system("echo 89 > /sys/class/gpio/export");
+	system("echo \"out\" > /sys/class/gpio/gpio89/direction");
+	system("echo 1 > /sys/class/gpio/gpio89/value");
+	/*LCD_HSYNC		=>	GPIO2_23*//*RS-485 for module RE control*/
+	system("echo 87 > /sys/class/gpio/export");
+	system("echo \"out\" > /sys/class/gpio/gpio87/direction");
+	system("echo 0 > /sys/class/gpio/gpio87/value");
+	/*LCD_PCLK		=>	GPIO2_24*//*CCS communication board 1 proximity*/
+	system("echo 88 > /sys/class/gpio/export");
+	system("echo \"in\" > /sys/class/gpio/gpio88/direction");
+	/*LCD_VSYNC		=>	GPIO2_22*//*CCS communication board 2 proximity*/
+	system("echo 86 > /sys/class/gpio/export");
+	system("echo \"in\" > /sys/class/gpio/gpio86/direction");
+	/***************************************************************/
+	/*************** GPIO 3 ***************************************/
+	/***************************************************************/
+	/*MCASP0_FSX		=>	GPIO3_15*//*Emergency Stop button detect*/
+	system("echo 111 > /sys/class/gpio/export");
+	system("echo \"in\" > /sys/class/gpio/gpio111/direction");
+	/*MCASP0_ACLKR	=>	GPIO3_18*//*USB1 OCP detect*/
+	system("echo 114 > /sys/class/gpio/export");
+	system("echo \"in\" > /sys/class/gpio/gpio114/direction");
+	/*MCASP0_AHCLKR	=>	GPIO3_17*//*Emergency IO for AM3352 and STM32F407*/
+	system("echo 113 > /sys/class/gpio/export");
+	system("echo \"in\" > /sys/class/gpio/gpio113/direction");
+	/*MCASP0_ACLKX	=>	GPIO3_14*//*Ethernet PHY reset*/
+	system("echo 110 > /sys/class/gpio/export");
+	system("echo \"out\" > /sys/class/gpio/gpio110/direction");
+	system("echo 0 > /sys/class/gpio/gpio110/value");
+	/* MCASP0_FSR		=>	GPIO3_19 *//*SMR Enable control_1 for Pskill_1*/
+	system("echo 115 > /sys/class/gpio/export");
+	system("echo \"out\" > /sys/class/gpio/gpio115/direction");
+	system("echo 0 > /sys/class/gpio/gpio115/value");
+	/* MCASP0_AXR0	=>	GPIO3_16 *//*CSU board function OK indicator.*/
+	system("echo 112 > /sys/class/gpio/export");
+	system("echo \"out\" > /sys/class/gpio/gpio112/direction");
+	system("echo 1 > /sys/class/gpio/gpio112/value");
+	/* MCASP0_AXR1	=>	GPIO3_20 *//*SMR Enable control_2 for Pskill_2*/
+	system("echo 116 > /sys/class/gpio/export");
+	system("echo \"out\" > /sys/class/gpio/gpio116/direction");
+	system("echo 0 > /sys/class/gpio/gpio116/value");
+#ifdef SystemLogMessage
+	DEBUG_INFO_MSG("[main]InitGPIO: Initial GPIO OK");
+#endif
+}
+
+int LoadSysConfigAndInfo(struct SysConfigData *ptr)
+{
+	int fd,wrd;
+	unsigned char *buf;
+	unsigned int ChkSum,ChkSumOrg;
+
+	if((buf=malloc(MtdBlockSize))==NULL)
+	{
+		DEBUG_ERROR_MSG("malloc buffer NG,rebooting..\r\n");
+		if(ShmStatusCodeData!=NULL)
+		{
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
+		}
+		sleep(5);
+		system("reboot -f");
+		sleep(5);
+		system("reboot -f");
+	}
+	memset(buf, 0, MtdBlockSize);
+
+	//================================================
+	// Load configuration from mtdblock10
+	//================================================
+	fd = open("/dev/mtdblock10", O_RDWR);
+	if (fd < 0)
+	{
+		free(buf);
+		DEBUG_ERROR_MSG("open mtdblock10 NG,rebooting..\r\n");
+		if(ShmStatusCodeData!=NULL)
+		{
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
+		}
+		sleep(5);
+		system("reboot -f");
+		sleep(5);
+		system("reboot -f");
+	}
+
+	wrd=read(fd, buf, MtdBlockSize);
+	close(fd);
+	if(wrd<MtdBlockSize)
+	{
+		free(buf);
+		DEBUG_ERROR_MSG("read SysConfigData data NG,rebooting..\r\n");
+		if(ShmStatusCodeData!=NULL)
+		{
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
+		}
+		sleep(5);
+		system("reboot -f");
+		sleep(5);
+		system("reboot -f");
+	}
+	ChkSum=0;
+	for(wrd=0;wrd<MtdBlockSize-4;wrd++)
+	{
+		ChkSum+=buf[wrd];
+	}
+	memcpy(&ChkSumOrg,buf+(0x00600000-4),sizeof(ChkSumOrg));
+
+	//================================================
+	// Load configuration from mtdblock11
+	//================================================
+	if(ChkSum!=ChkSumOrg)
+	{
+		DEBUG_ERROR_MSG("Primary SysConfigData checksum NG, read backup\r\n");
+		fd = open("/dev/mtdblock11", O_RDWR);
+		if (fd < 0)
+		{
+			free(buf);
+			DEBUG_ERROR_MSG("open mtdblock11 (backup) NG,rebooting..\r\n");
+			if(ShmStatusCodeData!=NULL)
+			{
+				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
+			}
+			sleep(5);
+			system("reboot -f");
+			sleep(5);
+			system("reboot -f");
+		}
+
+		memset(buf, 0, MtdBlockSize);
+	    wrd=read(fd, buf,MtdBlockSize);
+	    close(fd);
+		if(wrd<MtdBlockSize)
+		{
+			free(buf);
+			DEBUG_ERROR_MSG("read backup SysConfigData data NG,rebooting..\r\n");
+			if(ShmStatusCodeData!=NULL)
+			{
+				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
+			}
+			sleep(5);
+			system("reboot -f");
+			sleep(5);
+			system("reboot -f");
+		}
+		ChkSum=0;
+		for(wrd=0;wrd<MtdBlockSize-4;wrd++)
+		{
+			ChkSum+=buf[wrd];
+		}
+		memcpy(&ChkSumOrg,buf+(0x00600000-4),sizeof(ChkSumOrg));
+
+		//================================================
+		// Load configuration from mtdblock12 (Factory default)
+		//================================================
+		if(ChkSum!=ChkSumOrg)
+		{
+			DEBUG_ERROR_MSG("backup SysConfigData checksum NG, read Factory default\r\n");
+			fd = open("/dev/mtdblock12", O_RDWR);
+			if (fd < 0)
+			{
+				free(buf);
+				DEBUG_ERROR_MSG("open mtdblock12 (Factory default) NG,rebooting..\r\n");
+				if(ShmStatusCodeData!=NULL)
+				{
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
+				}
+				sleep(5);
+				system("reboot -f");
+				sleep(5);
+				system("reboot -f");
+		    }
+		    memset(buf, 0, MtdBlockSize);
+	   		wrd=read(fd, buf,MtdBlockSize);
+	    	close(fd);
+			if(wrd<MtdBlockSize)
+			{
+				free(buf);
+				DEBUG_ERROR_MSG("read factory default  SysConfigData data NG,rebooting..\r\n");
+				if(ShmStatusCodeData!=NULL)
+				{
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
+				}
+				sleep(5);
+				system("reboot -f");
+				sleep(5);
+				system("reboot -f");
+			}
+			ChkSum=0;
+			for(wrd=0;wrd<MtdBlockSize-4;wrd++)
+			{
+				ChkSum+=buf[wrd];
+			}
+			memcpy(&ChkSumOrg,buf+(0x00600000-4),sizeof(ChkSumOrg));
+			if(ChkSum!=ChkSumOrg)
+			{
+				DEBUG_ERROR_MSG("factory default  SysConfigData checksum NG, restore factory default\r\n");
+				free(buf);
+				system("cd /root;./FactoryConfig -m");
+				system("sync");
+				sleep(5);
+				system("reboot -f");
+				sleep(5);
+				system("reboot -f");
+
+				return FAIL;
+			}
+		}
+	}
+
+	//load OK
+	memcpy((struct SysConfigData *)ptr,buf,sizeof(struct SysConfigData));
+	free(buf);
+	DEBUG_INFO_MSG("Load SysConfigData OK\r\n");
+	return PASS;
+}
+
+int isReachableInternet()
+{
+	int result = FAIL;
+	FILE *fp;
+	char cmd[256];
+	char buf[512];
+	//char tmp[512];
+
+	for(int idx=0;idx<ARRAY_SIZE(valid_Internet);idx++)
+	{
+		strcpy(cmd, "ping -c 1 -w 3 ");
+		strcat(cmd, valid_Internet[idx]);
+		fp = popen(cmd, "r");
+		if(fp != NULL)
+		{
+			while(fgets(buf, sizeof(buf), fp) != NULL)
+			{
+				if(strstr(buf, "transmitted") > 0)
+				{
+					//sscanf(buf, "%*s%*s%*s%*s%*s%*s%s", tmp);
+
+					if(strstr(buf,"100%") != NULL)
+					{
+
+					}
+					else
+					{
+						result = PASS;
+					}
+					//DEBUG_INFO("%s",buf);
+					//DEBUG_INFO("%s\n",tmp);
+				}
+			}
+		}
+		pclose(fp);
+	}
+
+	return result;
+}
+
+void InitEthernet()
+{
+	char tmpbuf[256];
+	// /sbin/ifconfig eth0 192.168.1.10 netmask 255.255.255.0 down
+	system("echo 1 > /sys/class/gpio/gpio110/value");//reset PHY
+	sleep(2);
+	//Init Eth0 for internet
+	memset(tmpbuf,0,256);
+	sprintf(tmpbuf,"/sbin/ifconfig eth0 %s netmask %s up",
+	ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
+	ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress);
+	system(tmpbuf);
+	memset(tmpbuf,0,256);
+	sprintf(tmpbuf,"route add default gw %s eth0 ",
+	ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
+	system(tmpbuf);
+
+    //Init Eth1 for administrator tool
+	memset(tmpbuf,0,256);
+	sprintf(tmpbuf,"/sbin/ifconfig eth1 %s netmask %s up",
+	ShmSysConfigAndInfo->SysConfig.Eth1Interface.EthIpAddress,
+	ShmSysConfigAndInfo->SysConfig.Eth1Interface.EthSubmaskAddress);
+	system(tmpbuf);
+
+    //Run DHCP client if enabled
+	system("killall udhcpc");
+	system("rm -rf /etc/resolv.conf");
+	system("echo nameserver 8.8.8.8 > /etc/resolv.conf");		//Google DNS server
+	system("echo nameserver 180.76.76.76 > /etc/resolv.conf");	//Baidu DNS server
+
+	if(ShmSysConfigAndInfo->SysConfig.Eth1Interface.EthDhcpClient == 0)
+		system("/sbin/udhcpc -i eth0 -s /root/dhcp_script/eth0.script > /dev/null &");
+
+	pid_t pid = fork();
+	uint8_t cnt_pingDNS_Fail;
+
+	if(pid == 0)
+	{
+		for(;;)
+		{
+			if(isReachableInternet() == PASS)
+			{
+				ShmSysConfigAndInfo->SysInfo.InternetConn = YES;
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet= NO;
+				cnt_pingDNS_Fail = 0;
+			}
+			else
+			{
+				if(++cnt_pingDNS_Fail > 3)
+				{
+					ShmSysConfigAndInfo->SysInfo.InternetConn = NO;
+					ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet= YES;
+				}
+			}
+
+			sleep(5);
+		}
+	}
+
+	#ifdef SystemLogMessage
+	DEBUG_INFO_MSG("[main]InitEthernet: Initial Ethernet OK");
+	#endif
+}
+
+int InitialRfidPort()
+{
+	int uartO2 = open(rfidPortName, O_RDWR);
+	struct termios tios;
+
+	if (uartO2 != FAIL)
+	{
+		ioctl (uartO2, TCGETS, &tios);
+		tios.c_cflag = B19200 | CS8 | CLOCAL | CREAD;
+		tios.c_lflag = 0;
+		tios.c_iflag = 0;
+		tios.c_oflag = 0;
+		tios.c_cc[VMIN] = 0;
+		tios.c_cc[VTIME] = (unsigned char) 1;
+		tios.c_lflag = 0;
+		tcflush(uartO2, TCIFLUSH);
+		ioctl(uartO2, TCSETS, &tios);
+	}
+
+	if (uartO2 < 0)
+	{
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RfidModuleCommFail = 1;
+	}
+
+	return uartO2;
+}
+
+void InitialShareMemoryInfo()
+{
+	FILE *fp;
+	char cmd[512];
+	char buf[512];
+
+	sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn, "Internet");
+	sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId, " ");
+	sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd, " ");
+
+	ShmSysConfigAndInfo->SysInfo.FactoryConfiguration = 0;
+	ShmSysConfigAndInfo->SysInfo.InputVoltageR = 0;
+	ShmSysConfigAndInfo->SysInfo.InputVoltageS = 0;
+	ShmSysConfigAndInfo->SysInfo.InputVoltageT = 0;
+	ShmSysConfigAndInfo->SysInfo.SystemFanRotaSpeed = 0;
+	ShmSysConfigAndInfo->SysInfo.PsuFanRotaSpeed = 0;
+	ShmSysConfigAndInfo->SysInfo.AuxPower5V = 0;
+	ShmSysConfigAndInfo->SysInfo.AuxPower12V = 0;
+	ShmSysConfigAndInfo->SysInfo.AuxPower24V = 0;
+	ShmSysConfigAndInfo->SysInfo.AuxPower48V = 0;
+
+	sprintf((char *)ShmSysConfigAndInfo->SysInfo.CsuHwRev, "REV:5.0");
+	memcpy(ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev, ShmSysConfigAndInfo->SysConfig.CsuBootLoadFwRev, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.CsuBootLoadFwRev));
+
+	sprintf(cmd, "/bin/uname -r");
+	fp = popen(cmd, "r");
+	if(fp == NULL)
+		sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev, "Unknown version");
+	else
+	{
+		while(fgets(buf, sizeof(buf), fp) != NULL)
+		{
+			strcpy((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev, buf);
+		}
+	}
+
+	sprintf((char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, "D0.01.04.20.02.00");
+	sprintf((char *) ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, " ");
+
+	sprintf((char *) ShmSysConfigAndInfo->SysInfo.LcmHwRev, " ");
+	sprintf((char *) ShmSysConfigAndInfo->SysInfo.LcmFwRev, " ");
+	sprintf((char *) ShmSysConfigAndInfo->SysInfo.PsuHwRev, " ");
+	sprintf((char *) ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev, " ");
+	sprintf((char *) ShmSysConfigAndInfo->SysInfo.PsuSecFwRev, " ");
+	sprintf((char *) ShmSysConfigAndInfo->SysInfo.AuxPwrHwRev, " ");
+	sprintf((char *) ShmSysConfigAndInfo->SysInfo.AuxPwrFwRev, " ");
+	sprintf((char *) ShmSysConfigAndInfo->SysInfo.FanModuleHwRev, " ");
+	sprintf((char *) ShmSysConfigAndInfo->SysInfo.FanModuleFwRev, " ");
+	sprintf((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleHwRev, " ");
+	sprintf((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev, " ");
+	sprintf((char *) ShmSysConfigAndInfo->SysInfo.TelcomModemFwRev, " ");
+	ShmSysConfigAndInfo->SysInfo.SystemAmbientTemp = 0;
+	ShmSysConfigAndInfo->SysInfo.SystemCriticalTemp = 0;
+	ShmSysConfigAndInfo->SysInfo.PsuAmbientTemp = 0;
+	ShmSysConfigAndInfo->SysInfo.CcsConnectorTemp = 0;
+	ShmSysConfigAndInfo->SysInfo.InternetConn = 0;
+	ShmSysConfigAndInfo->SysInfo.OcppConnStatus = 0;
+	ShmSysConfigAndInfo->SysInfo.OrderCharging = FAIL;
+
+	strcpy((char *) ShmSysConfigAndInfo->SysConfig.UserId, "");
+
+	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RelayboardStestFail = NO;
+	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FanboardStestFail = NO;
+	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PrimaryStestFail = NO;
+	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoboardStestFail = NO;
+	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CCSboardStestFail = NO;
+	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcContactStestFail = NO;
+	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuModuleStestFail = NO;
+
+	memset(ShmSysConfigAndInfo->SysInfo.FanModuleFwRev, 0, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
+	memset(ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev, 0, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
+	ShmPrimaryMcuData->SelfTest_Comp = NO;
+	ShmRelayModuleData->SelfTest_Comp = NO;
+	ShmFanModuleData->SelfTest_Comp = NO;
+	ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+	ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
+
+	ShmFanModuleData->TestFanSpeed = 0;
+
+	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ModelNameNoneMatchStestFail = NO;
+	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = NO;
+}
+
+int Initialization()
+{
+	// 初始化卡號驗證的 Flag
+	ClearAuthorizedFlag();
+	// 初始化插槍驗證的 Flag
+	ClearDetectPluginFlag();
+
+	// UART 2 for Rfid
+	rfidFd = InitialRfidPort();
+
+	int pinOut[2] = { 115, 116 };
+	for (byte count = 0; count < _gunCount; count++)
+	{
+		if (chargingInfo[count]->Type == _Type_Chademo)
+		{
+			gpio_set_value(pinOut[count], 0x01);
+			ShmCHAdeMOData->evse[chargingInfo[count]->type_index].SelfTest_Comp = NO;
+		}
+		else if (chargingInfo[count]->Type == _Type_CCS_2)
+		{
+			if (ShmCcsData->CommProtocol == 0x01)
+			{
+				if (_gunCount == 1)
+					gpio_set_value(pinOut[1], 0x00);
+				else
+					gpio_set_value(pinOut[count], 0x00);
+				ShmCcsData->V2GMessage_DIN70121[chargingInfo[count]->type_index].SelfTest_Comp = NO;
+			}
+		}
+
+
+		strcpy((char *)ShmOCPP16Data->StatusNotification[count].ErrorCode, "NoError");
+	}
+
+	PRINTF_FUNC("Initialization OK \n");
+	return PASS;
+}
+
+bool InitialSystemDefaultConfig()
+{
+	bool result = true;
+
+	LoadSysConfigAndInfo(&ShmSysConfigAndInfo->SysConfig);
+	InitGPIO();
+	//InitEthernet();
+
+	system("echo 1 > /sys/class/gpio/gpio110/value"); //reset PHY
+	sleep(3);
+	system("/sbin/ifconfig eth0 192.168.1.10 netmask 255.255.255.0 down");
+	sleep(1);
+	system("/sbin/ifconfig eth0 192.168.1.10 netmask 255.255.255.0 up");
+
+	return result;
+}
+
+void DisplaySelfTestFailReason()
+{
+	// RB、FB、407、EV 小板中有些板子無回應
+	if (ShmRelayModuleData->SelfTest_Comp == NO)
+	{ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RelayboardStestFail = YES; }
+	if (ShmFanModuleData->SelfTest_Comp == NO)
+	{ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FanboardStestFail = YES; }
+	if (ShmPrimaryMcuData->SelfTest_Comp == NO)
+	{ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PrimaryStestFail = YES; }
+	for (byte index = 0; index < _gunCount; index++)
+	{
+		if (chargingInfo[index]->Type == _Type_Chademo)
+		{
+			if (ShmCHAdeMOData->evse[chargingInfo[index]->type_index].SelfTest_Comp == NO)
+			{ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoboardStestFail = YES; }
+		}
+		else if (chargingInfo[index]->Type == _Type_CCS_2)
+		{
+			if (ShmCcsData->CommProtocol == 0x01)
+			{
+				if (ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].SelfTest_Comp == NO)
+				{ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CCSboardStestFail = YES; }
+			}
+		}
+	}
+
+	if (ShmSysConfigAndInfo->SysInfo.AcContactorStatus == NO)
+	{
+		// AC Contact 未搭上
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcContactStestFail = YES;
+	}
+	else
+	{
+		// PSU 通訊問題
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuModuleStestFail = YES;
+	}
+}
+
+void SelfTestRun()
+{
+	bool evInitFlag = false;
+
+	StartSystemTimeoutDet(Timeout_SelftestChk);
+	ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_VERSION;
+	while (ShmSysConfigAndInfo->SysInfo.SelfTestSeq != _STEST_COMPLETE)
+	{
+		ChkPrimaryStatus();
+		if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2)
+		{
+			ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_FAIL;
+			return;
+		}
+
+		if (_gunCount > 0)
+		{
+			if (ShmPsuData->Work_Step == _NO_WORKING ||
+					ShmSysConfigAndInfo->SysInfo.SelfTestSeq == _STEST_FAIL)
+			{
+				ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_FAIL;
+				return;
+			}
+
+			switch(ShmSysConfigAndInfo->SysInfo.SelfTestSeq)
+			{
+				case _STEST_VERSION:
+				{
+					if (strlen((char *)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev) != 0 ||
+							ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev[0] != '\0')
+					{
+						//PRINTF_FUNC("RB pass \n");
+						ShmRelayModuleData->SelfTest_Comp = YES;
+					}
+
+					if  (strlen((char *)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev) != 0 ||
+							ShmSysConfigAndInfo->SysInfo.FanModuleFwRev[0] != '\0')
+					{
+						//PRINTF_FUNC("Fan pass \n");
+						ShmFanModuleData->SelfTest_Comp = YES;
+					}
+
+					if (strlen((char *)ShmPrimaryMcuData->version) != 0 ||
+							ShmPrimaryMcuData->version[0] != '\0')
+					{
+						//PRINTF_FUNC("407 pass \n");
+						ShmPrimaryMcuData->SelfTest_Comp = YES;
+					}
+					// EV 小板
+					if (!evInitFlag)
+					{
+						evInitFlag = YES;
+						for (byte index = 0; index < _gunCount; index++)
+						{
+							if (chargingInfo[index]->Type == _Type_Chademo)
+							{
+								if (strlen((char *)ShmCHAdeMOData->evse[chargingInfo[index]->type_index].version) != 0 ||
+										ShmCHAdeMOData->evse[chargingInfo[index]->type_index].version[0] != '\0')
+								{
+									//PRINTF_FUNC("chademo pass \n");
+									ShmCHAdeMOData->evse[chargingInfo[index]->type_index].SelfTest_Comp = YES;
+								}
+								else
+								{
+									//PRINTF_FUNC("chademo fw lose...... %s \n", ShmCHAdeMOData->evse[chargingInfo[index]->type_index].version);
+									evInitFlag = NO;
+								}
+							}
+							else if (chargingInfo[index]->Type == _Type_CCS_2)
+							{
+								if (ShmCcsData->CommProtocol == 0x01)
+								{
+									if (strlen((char *)ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version) != 0 ||
+										ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version[0] != '\0')
+									{
+										//PRINTF_FUNC("ccs fw =  %s \n", ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version);
+										ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].SelfTest_Comp = YES;
+									}
+									else
+									{
+										//PRINTF_FUNC("ccs fw lose...... %s \n", ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version);
+										evInitFlag = NO;
+									}
+								}
+							}
+						}
+					}
+
+					if (ShmFanModuleData->SelfTest_Comp &&
+							ShmRelayModuleData->SelfTest_Comp &&
+							ShmPrimaryMcuData->SelfTest_Comp &&
+							evInitFlag)
+					{
+						ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_AC_CONTACTOR;
+					}
+				}
+					break;
+				case _STEST_AC_CONTACTOR:
+				{
+					//ShmPsuData->Work_Step = _TEST_COMPLETE;
+					// 因為 30KW 以下沒有 Relay feedback 功能,所以暫時先直接跳過
+					if (ShmSysConfigAndInfo->SysInfo.AcContactorStatus == YES)
+					{
+						ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_PSU_DETECT;
+						PRINTF_FUNC("Communication board pass. \n");
+					}
+				}
+					break;
+				case _STEST_PSU_DETECT:
+				{
+					// 此測試主要測試 PSU 對應是否為正確的火線上電壓
+					// 如果沒有 PSU 模組請 bypass
+					if (ShmPsuData->Work_Step == _TEST_POWER_STEP || ShmPsuData->Work_Step == _TEST_COMPLETE)
+					{
+						ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_PSU_CAP;
+					}
+				}
+					break;
+				case _STEST_PSU_CAP:
+				{
+					// 此測試是要確認當前總輸出能力
+					// 如果沒有 PSU 模組請 bypass
+					if (ShmPsuData->Work_Step == _TEST_COMPLETE)
+					{
+						sleep(1);
+						ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_COMPLETE;
+						ShmSysConfigAndInfo->SysInfo.BootingStatus = BOOT_COMPLETE;
+					}
+				}
+					break;
+			}
+		}
+		else
+			break;
+
+		usleep(100000);
+	}
+}
+
+int SpawnTask()
+{
+	system("/root/Module_EventLogging &");
+	system("/root/Module_PrimaryComm &");
+	system("/root/Module_EvComm &");
+	system("/root/Module_LcmControl &");
+	system("/root/Module_InternalComm &");
+	system("/root/Module_PsuComm &");
+	//system("/root/OcppBackend &");
+
+	if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T')
+	{
+		//system("/root/Module_4g &");
+	}
+	else if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W')
+	{
+		//system("/root/Module_Wifi &");
+	}
+
+	// 加入參數
+//	char str[64];
+//	memset(str, '\0', sizeof(65));
+//	sprintf(str, "/root/Module_EvComm %x &", (CHAdeMO_QUANTITY + CCS_QUANTITY));
+//	PRINTF_FUNC("%s \n", str);
+//	system(str);
+
+	return PASS;
+}
+
+int StoreUsrConfigData(struct SysConfigData *UsrData)
+{
+	int result = PASS;
+	int fd,wrd;
+	unsigned int i,Chk;
+	unsigned char *ptr, *BufTmp;
+
+	Chk=0;
+	ptr=(unsigned char *)UsrData;
+	if((BufTmp = malloc(MtdBlockSize)) != NULL)
+	{
+		memset(BufTmp, 0, MtdBlockSize);
+		memcpy(BufTmp, ptr, sizeof(struct SysConfigData));
+		for(i=0; i<MtdBlockSize-4; i++)
+			Chk+=*(ptr+i);
+
+		memcpy(BufTmp + MtdBlockSize-4, &Chk, 4);
+		fd = open("/dev/mtdblock10", O_RDWR);
+		if (fd > 0)
+		{
+			wrd=write(fd, BufTmp, MtdBlockSize);
+			close(fd);
+			if(wrd >= MtdBlockSize)
+			{
+				fd = open("/dev/mtdblock11", O_RDWR);
+				if (fd > 0)
+				{
+					wrd=write(fd, BufTmp, MtdBlockSize);
+	    			close(fd);
+					if(wrd < MtdBlockSize)
+					{
+						DEBUG_ERROR_MSG("write /dev/mtdblock11(backup) NG\r\n");
+					   	result = FAIL;
+					}
+				}
+				else
+				{
+					DEBUG_ERROR_MSG("open /dev/mtdblock11(backup) NG\r\n");
+					result = FAIL;
+				}
+			}
+			else
+			{
+				DEBUG_ERROR_MSG("write /dev/mtdblock10 NG\r\n");
+			    result = FAIL;
+			}
+
+		}
+		else
+		{
+			DEBUG_ERROR_MSG("open /dev/mtdblock10 NG\r\n");
+			result = FAIL;
+		}
+	}
+	else
+	{
+		DEBUG_ERROR_MSG("alloc BlockSize NG\r\n");
+	    result = FAIL;
+	}
+
+	if(BufTmp != NULL)
+		free(BufTmp);
+
+	return result;
+}
+
+//===============================================
+// Common Detect Chk - Stop Charging ?
+//===============================================
+bool isEvBoardStopChargeFlag(byte gunIndex)
+{
+	return chargingInfo[gunIndex]->StopChargeFlag;
+}
+
+//===============================================
+// 掃描插槍狀況
+//===============================================
+void ClearDetectPluginFlag()
+{
+	ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
+}
+
+void DetectPluginStart()
+{
+	ShmSysConfigAndInfo->SysInfo.WaitForPlugit = YES;
+}
+
+bool isDetectPlugin()
+{
+	if(ShmSysConfigAndInfo->SysInfo.WaitForPlugit == YES)
+		return YES;
+
+	return NO;
+}
+
+//===============================================
+// Common Detect Chk - Chademo
+//===============================================
+bool isEvGunLocked_chademo(byte gunIndex)
+{
+	return (DetectBitValue(chargingInfo[gunIndex]->GunLocked , 0) == 0)? NO : YES;
+}
+
+bool isEvContactorWelding_chademo(byte gunIndex)
+{
+	return DetectBitValue(ShmCHAdeMOData->ev[chargingInfo[gunIndex]->type_index].EvDetection, 3);
+}
+
+bool isEvStopReq_chademo(byte gunIndex)
+{
+	return DetectBitValue(ShmCHAdeMOData->ev[chargingInfo[gunIndex]->type_index].EvDetection, 4);
+}
+
+bool isEvStopCharging_chademo(byte gunIndex)
+{
+	if (isEvGunLocked_chademo(gunIndex) == NO)
+	{
+		// 無鎖槍 = 停止
+		PRINTF_FUNC("gun locked none. \n");
+		return YES;
+	}
+
+	return NO;
+}
+
+byte isPrechargeStatus_chademo(byte gunIndex)
+{
+	byte result = 0x00;
+
+	result = ShmCHAdeMOData->ev[chargingInfo[gunIndex]->type_index].PresentMsgFlowStatus;
+
+	return result;
+}
+//===============================================
+// Common Detect Chk - CCS
+//===============================================
+bool isEvGunLocked_ccs(byte gunIndex)
+{
+	return (DetectBitValue(chargingInfo[gunIndex]->GunLocked , 0) == 0)? NO : YES;
+}
+
+byte isPrechargeStatus_ccs(byte gunIndex)
+{
+	byte result = 0x00;
+
+	if (ShmCcsData->CommProtocol == 0x01)
+	{
+		result = ShmCcsData->V2GMessage_DIN70121[chargingInfo[gunIndex]->type_index].PresentMsgFlowStatus;
+	}
+
+	return result;
+}
+
+bool isEvStopCharging_ccs(byte gunIndex)
+{
+	if (isEvGunLocked_ccs(gunIndex) == NO)
+	{
+		// 無鎖槍 = 停止
+		PRINTF_FUNC("gun locked none. \n");
+		return YES;
+	}
+
+	return NO;
+}
+
+//===============================================
+// Callback
+//===============================================
+void DisplayChargingInfo()
+{
+	for (byte i = _gunCount - 1; i >= 0; i--)
+	{
+		if (chargingInfo[i]->SystemStatus != S_IDLE)
+		{
+			ShmSysConfigAndInfo->SysInfo.CurGunSelected = i;
+			break;
+		}
+	}
+	ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+}
+
+void _AutoReturnTimeout()
+{
+	if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_WAIT_FOR_PLUG)
+	{
+		ClearDetectPluginFlag();
+	}
+	else if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZ_COMP)
+	{
+		DetectPluginStart();
+	}
+
+	ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+}
+
+void _SelfTestTimeout()
+{
+	if (ShmSysConfigAndInfo->SysInfo.BootingStatus != BOOT_COMPLETE)
+	{
+		for (byte gun_index = 0; gun_index < _gunCount; gun_index++)
+		{
+			setChargerMode(gun_index, MODE_ALARM);
+		}
+	}
+	ShmPsuData->Work_Step = _NO_WORKING;
+	ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_FAIL;
+	PRINTF_FUNC("Self test timeout. \n");
+}
+
+void _AuthorizedTimeout()
+{
+	if(IsAuthorizingMode())
+	{
+		PRINTF_FUNC("_AuthorizedTimeout \n");
+		isCardScan = false;
+		ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_FAIL;
+		//ChangeLcmByIndex(_LCM_AUTHORIZ_FAIL);
+		strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+		ClearAuthorizedFlag();
+	}
+}
+
+void _DetectPlugInTimeout()
+{
+	strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+	PRINTF_FUNC("_DetectPlugInTimeout \n");
+	ClearDetectPluginFlag();
+	ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+}
+
+void _DetectEvChargingEnableTimeout(byte gunIndex)
+{
+	if (chargingInfo[gunIndex]->Type == _Type_Chademo)
+	{
+		if(!isEvGunLocked_chademo(gunIndex))
+		{
+			PRINTF_FUNC("_DetectEvChargingEnableTimeout (chademo) \n");
+			ChargingTerminalProcess(gunIndex);
+			_AutoReturnTimeout();
+		}
+	}
+	else if (chargingInfo[gunIndex]->Type == _Type_CCS_2)
+	{
+		if(!isEvGunLocked_ccs(gunIndex))
+		{
+			PRINTF_FUNC("_DetectEvChargingEnableTimeout (ccs) \n");
+			ChargingTerminalProcess(gunIndex);
+			_AutoReturnTimeout();
+		}
+	}
+}
+
+void _DetectEvseChargingEnableTimeout(byte gunIndex)
+{
+	PRINTF_FUNC("_DetectEvseChargingEnableTimeout (GFD timeout) \n");
+	//if (chargingInfo[gunIndex]->GroundFaultStatus != GFD_PASS)
+	{
+		setChargerMode(gunIndex, MODE_IDLE);
+		_AutoReturnTimeout();
+	}
+}
+
+void _PrepareTimeout(byte gunIndex)
+{
+	PRINTF_FUNC("_PrechargeTimeout \n");
+	setChargerMode(gunIndex, MODE_IDLE);
+	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = NO;
+	_AutoReturnTimeout();
+}
+
+void _CompleteTimeout(byte gunIndex)
+{
+	PRINTF_FUNC("_CompleteTimeout ====> %d \n", gunIndex);
+	setChargerMode(gunIndex, MODE_IDLE);
+}
+
+void _CcsPrechargeTimeout(byte gunIndex)
+{
+	PRINTF_FUNC("_CcsPrechargeTimeout \n");
+	setChargerMode(gunIndex, MODE_IDLE);
+}
+
+//===============================================
+// 取得卡號與卡號驗證
+//===============================================
+bool canStartCharging()
+{
+	char buf2[16] = "";
+	memset(buf2, 0, ARRAY_SIZE(buf2));
+
+	for (byte index = 0; index < strlen((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status); index++)
+	{
+		sprintf(buf2 + (index - 1) * 2, "%02X",	ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status[index]);
+	}
+	sprintf(buf2, "%s",	ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
+
+	// 因為無法得知實際的長度,所以只能用搜尋的方式
+	if(strcmp(buf2, "Accepted") == EQUAL)
+		return true;
+	else
+	{
+
+	}
+
+	return false;
+}
+
+void AuthorizingStart()
+{
+	ShmOCPP16Data->SpMsg.bits.AuthorizeReq = YES;
+	ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = YES;
+}
+
+void ClearAuthorizedFlag()
+{
+	ShmOCPP16Data->SpMsg.bits.AuthorizeReq = NO;
+	ShmOCPP16Data->SpMsg.bits.AuthorizeConf = NO;
+	ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = NO;
+}
+
+bool isAuthorizedComplete()
+{
+	if (ShmOCPP16Data->SpMsg.bits.AuthorizeConf == NO)
+		return false;
+
+	return true;
+}
+
+bool IsAuthorizingMode()
+{
+	if(ShmSysConfigAndInfo->SysInfo.AuthorizeFlag == NO)
+		return false;
+
+	return true;
+}
+
+//===============================================
+// 紀錄 Alarm Code
+//===============================================
+void RecordAlarmCode(char *code)
+{
+	if (strcmp(code, "012234") == 0) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip = YES;
+	if (strcmp(code, "012235") == 0) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip = YES;
+}
+
+void ReleaseAlarmCode(byte gunIndex)
+{
+	if (chargingInfo[gunIndex]->Type == _Type_Chademo)
+	{
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip = NO;
+	}
+	else if (chargingInfo[gunIndex]->Type == _Type_CCS_2)
+	{
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip = NO;
+	}
+}
+
+//===============================================
+// EmergencyStop and Charging Stop
+//===============================================
+void ChargingTerminalProcess(byte gunIndex)
+{
+	setChargerMode(gunIndex, MODE_TERMINATING);
+}
+
+void StopChargingProcessByString(byte level, byte gun_index, char *string)
+{
+	if (level > ShmSysConfigAndInfo->SysWarningInfo.Level)
+	{
+		ShmSysConfigAndInfo->SysWarningInfo.Level = level;
+	}
+}
+
+void ReleaseChargingProcessByString(byte level, char *code)
+{
+	if (level >= ShmSysConfigAndInfo->SysWarningInfo.Level)
+		ShmSysConfigAndInfo->SysWarningInfo.Level = 0;
+}
+
+// 一般錯誤停止充電處理函式
+void BoardErrOccurByString(byte index, char *code)
+{
+	byte level = 1;
+	if ((chargingInfo[index]->SystemStatus > S_IDLE && chargingInfo[index]->SystemStatus < S_TERMINATING) ||
+			(chargingInfo[index]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[index]->SystemStatus <= S_CCS_PRECHARGE_ST1))
+	{
+		ChargingTerminalProcess(index);
+	}
+
+	StopChargingProcessByString(level, index, code);
+}
+
+// 急停狀況的停止充電處理函式
+void EmcOccureByString(char *code)
+{
+	byte level = 2;
+	// 嚴重的急停有四種 : EMC 按鈕、Mainbreak、Dooropen、SPD Trip
+	// 其錯誤等級為 2
+	if (strncmp(code, "012251", 6) == 0 || strncmp(code, "012252", 6) == 0 ||
+			strncmp(code, "012237", 6) == 0 || strncmp(code, "012238", 6) == 0)
+	{
+		for (byte gun = 0; gun < _gunCount; gun++)
+		{
+			if ((chargingInfo[gun]->SystemStatus > S_IDLE && chargingInfo[gun]->SystemStatus < S_TERMINATING) ||
+					(chargingInfo[gun]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[gun]->SystemStatus <= S_CCS_PRECHARGE_ST1))
+			{
+				ChargingTerminalProcess(gun);
+			}
+
+			StopChargingProcessByString(level, gun, code);
+		}
+	}
+}
+
+void ReleaseBoardErrOccurByString(byte index, char *code)
+{
+	bool isTrigger = false;
+	byte level = 1;
+
+	if (strncmp(code, "023730", 6) == 0 && ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop == YES)
+	{
+		isTrigger = true;
+		ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop = NO;
+	}
+
+	if (isTrigger)
+	{
+		ReleaseChargingProcessByString(level, code);
+	}
+}
+
+void ReleaseEmsOccureByString(byte index, char *code)
+{
+	bool isTrigger = false;
+	byte level = 2;
+
+	if (strncmp(code, "012251", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == YES)
+	{
+		isTrigger = true;
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = NO;
+	}
+	else if (strncmp(code, "012252", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen == YES)
+	{
+		isTrigger = true;
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen = NO;
+	}
+	else if (strncmp(code, "012237", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip == YES)
+	{
+		isTrigger = true;
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = NO;
+	}
+	else if (strncmp(code, "012238", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip == YES)
+	{
+		isTrigger = true;
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip = NO;
+	}
+
+	if (isTrigger)
+	{
+		ReleaseChargingProcessByString(level, code);
+	}
+}
+
+//===============================================
+// 確認硬體 (按鈕) 狀態
+//===============================================
+bool leftBtnPush = false;
+bool rightBtnPush = false;
+
+void ChkPrimaryStatus()
+{
+	if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton == ABNORMAL)
+	{
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = YES;
+		EmcOccureByString("012251");
+	}
+	else
+		ReleaseEmsOccureByString(0, "012251");
+
+	if (ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec == ABNORMAL)
+	{
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip = YES;
+		EmcOccureByString("012238");
+	}
+	else
+		ReleaseEmsOccureByString(0, "012238");
+
+	if (ShmPrimaryMcuData->InputDet.bits.SpdDetec == ABNORMAL)
+	{
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = YES;
+		EmcOccureByString("012237");
+	}
+	else
+		ReleaseEmsOccureByString(0, "012237");
+
+	if (ShmPrimaryMcuData->InputDet.bits.DoorOpen == ABNORMAL)
+	{
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen = YES;
+		EmcOccureByString("012252");
+	}
+	else
+		ReleaseEmsOccureByString(0, "012252");
+
+	if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_PRESS && !leftBtnPush)
+	{
+		if(!leftBtnPush)
+		{
+			leftBtnPush = true;
+			PRINTF_FUNC("left btn down............................... \n");
+			if (ShmSysConfigAndInfo->SysInfo.CurGunSelected + 1 < _gunCount)
+				ShmSysConfigAndInfo->SysInfo.CurGunSelected += 1;
+			else
+				ShmSysConfigAndInfo->SysInfo.CurGunSelected = 0;
+		}
+		// 左邊的選槍按鈕,只有在雙槍都在充電時候才有用 : 30KW 以下該按鈕無作用
+	}
+	else if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_RELEASE)
+	{
+		if(leftBtnPush)
+		{
+			leftBtnPush = false;
+			PRINTF_FUNC("left btn up............................... \n");
+		}
+	}
+
+	if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_PRESS && !rightBtnPush)
+	{
+		if(!rightBtnPush)
+		{
+			rightBtnPush = true;
+			PRINTF_FUNC("right btn down............................... %d \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+			if (_gunCount > 1)
+			{
+				switch(chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
+				{
+					case S_IDLE:
+					{
+						//ShmSysConfigAndInfo->SysInfo.WaitForPlugit = 0x01;
+					}
+					break;
+					case S_PREPARNING:
+					case S_PREPARING_FOR_EV:
+					case S_PREPARING_FOR_EVSE:
+					case S_CCS_PRECHARGE_ST0:
+					case S_CCS_PRECHARGE_ST1:
+					case S_CHARGING:
+					{
+						// 停止充電
+						ChargingTerminalProcess(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+					}
+						break;
+					case S_COMPLETE:
+					{
+						// 回 IDLE
+						PRINTF_FUNC("right btn down.................S_COMPLETE \n");
+						chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_IDLE;
+					}
+						break;
+				}
+			}
+		}
+
+		// 右邊的按鈕,只作用在當前頁面,當前頁面如果在可以回 Home 與 停止充電的狀態為可用
+//		switch(chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
+//		{
+//			case S_IDLE: {}break;
+//			case S_AUTHORIZING: {}break;
+//			case S_PREPARING_FOR_EV: {}break;
+//			case S_PREPARING_FOR_EVSE: {}break;
+//			case S_CCS_PRECHARGE_ST0: {}break;
+//			case S_CCS_PRECHARGE_ST1: {}break;
+//			case S_CHARGING:
+//			{
+//				// 停止充電
+//				PRINTF_FUNC("Stop --------------------------------------------------- \n");
+//				//ChargingTerminalProcess(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+//			}
+//				break;
+//			case S_COMPLETE:
+//			{
+//				//setChargerMode(ShmSysConfigAndInfo->SysInfo.CurGunSelected, MODE_IDLE);
+//			}
+//				break;
+//		}
+	}
+	else if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_RELEASE)
+	{
+		if(rightBtnPush)
+		{
+			rightBtnPush = false;
+			PRINTF_FUNC("right btn up............................... \n");
+		}
+	}
+}
+
+//===============================================
+// 確認各小板偵測的錯誤狀況
+//===============================================
+void CheckErrorOccurStatus(byte index)
+{
+	// 小板
+	if (chargingInfo[index]->Type == _Type_Chademo)
+	{
+		if (ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault == YES)
+			BoardErrOccurByString(index, "011012");
+		else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip == YES)
+			BoardErrOccurByString(index, "012234");
+	}
+	else if (chargingInfo[index]->Type == _Type_CCS_2)
+	{
+		if (ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault == YES)
+			BoardErrOccurByString(index, "011014");
+		else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip == YES)
+			BoardErrOccurByString(index, "012235");
+	}
+}
+
+//===============================================
+// 確認 GPIO 狀態
+//===============================================
+void gpio_set_value(unsigned int gpio, unsigned int value)
+{
+	int fd;
+	char buf[MAX_BUF];
+
+	snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/value", gpio);
+	fd = open(buf, O_WRONLY);
+	if (fd < 0)
+	{
+	    perror("gpio/set-value");
+	    return;
+	}
+
+	if (value)
+		write(fd, "1", 2);
+	else
+	    write(fd, "0", 2);
+
+	close(fd);
+}
+
+int gpio_get_value(unsigned int gpio, unsigned int *value)
+{
+    int fd;
+    char buf[MAX_BUF];
+    char ch;
+
+    snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/value", gpio);
+
+    fd = open(buf, O_RDONLY);
+    if (fd < 0) {
+        perror("gpio/get-value");
+        return fd;
+    }
+
+    read(fd, &ch, 1);
+
+    if (ch != '0') {
+        *value = 1;
+    } else {
+        *value = 0;
+    }
+
+    close(fd);
+    return 0;
+}
+
+void CheckGunTypeFromHw()
+{
+	int pinIn[4] = { 22, 23, 44, 45 };
+	unsigned int gpioValue = 0;
+
+	for (int i = 0; i < ARRAY_SIZE(pinIn); i++) {
+		gpio_get_value(pinIn[i], &gpioValue);
+		{
+			switch (pinIn[i])
+			{
+			case 22:
+				bd1_1_status = gpioValue;
+				break;
+			case 23:
+				bd1_2_status = gpioValue;
+				break;
+			case 44:
+				bd0_1_status = gpioValue;
+				break;
+			case 45:
+				bd0_2_status = gpioValue;
+				break;
+			}
+		}
+	}
+}
+
+void CheckGpioInStatus()
+{
+	int pinIn[2] = { 27, 47 };
+	unsigned int gpioValue = 0;
+
+	for (int i = 0; i < ARRAY_SIZE(pinIn); i++)
+	{
+		gpio_get_value(pinIn[i], &gpioValue);
+		if (gpioValue == 0x01)
+		{
+			switch(pinIn[i])
+			{
+				// 小板緊急停止
+				case 47:
+				{
+					for(int i = 0; i < _gunCount; i++)
+					{
+						if (chargingInfo[i]->slotsIndex == 1)
+						{
+							if (chargingInfo[i]->Type == _Type_Chademo)
+								BoardErrOccurByString(i, "023730");
+							else if (chargingInfo[i]->Type == _Type_CCS_2)
+								BoardErrOccurByString(i, "013627");
+							break;
+						}
+					}
+				}
+					break;
+				case 27:
+				{
+					for(int i = 0; i < _gunCount; i++)
+					{
+						if (chargingInfo[i]->slotsIndex == 3)
+						{
+							if (chargingInfo[i]->Type == _Type_Chademo)
+								BoardErrOccurByString(i, "023730");
+							else if (chargingInfo[i]->Type == _Type_CCS_2)
+								BoardErrOccurByString(i, "013627");
+							break;
+						}
+					}
+				}
+					break;
+			}
+		}
+		else
+		{
+			switch (pinIn[i])
+			{
+				// 小板解除緊急停止
+				case 47:
+				{
+					for(int i = 0; i < _gunCount; i++)
+					{
+						if (chargingInfo[i]->slotsIndex == 1)
+						{
+							if (chargingInfo[i]->Type == _Type_Chademo)
+								ReleaseEmsOccureByString(i, "023730");
+							else if (chargingInfo[i]->Type == _Type_CCS_2)
+								ReleaseEmsOccureByString(i, "013627");
+							break;
+						}
+					}
+				}
+					break;
+				case 27:
+				{
+					for (int i = 0; i < _gunCount; i++)
+					{
+						if (chargingInfo[i]->slotsIndex == 3)
+						{
+							if (chargingInfo[i]->Type == _Type_Chademo)
+								ReleaseEmsOccureByString(i, "023730");
+							else if (chargingInfo[i]->Type == _Type_CCS_2)
+								ReleaseEmsOccureByString(i, "013627");
+							break;
+						}
+					}
+				}
+				break;
+			}
+		}
+	}
+}
+
+//===============================================
+// Main process
+//===============================================
+// 檢查 Byte 中某個 Bit 的值
+// _byte : 欲改變的 byte
+// _bit : 該 byte 的第幾個 bit
+unsigned char DetectBitValue(unsigned char _byte, unsigned char _bit)
+{
+	return ( _byte & mask_table[_bit] ) != 0x00;
+}
+
+// 設定 Byte 中某個 Bit的值
+// _byte : 欲改變的 byte
+// _bit : 該 byte 的第幾個 bit
+// value : 修改的值為 0 or 1
+void SetBitValue(unsigned char *_byte, unsigned char _bit, unsigned char value)
+{
+	if(value == 1)
+		*_byte |= (1 << _bit);
+	else if (value == 0)
+		*_byte ^= (1 << _bit);
+}
+
+void UserScanFunction()
+{
+	bool idleReq = false;
+	unsigned char stopReq = 255;
+
+	// 當前非驗證的狀態
+	if(!IsAuthorizingMode())
+	{
+		// 先判斷現在是否可以提供刷卡
+		// 1. 如果當前沒有槍是閒置狀態,則無提供刷卡功能
+		// 2. 停止充電
+		for (byte i = 0; i < _gunCount; i++)
+		{
+			// 二擇一
+			if ((chargingInfo[i]->SystemStatus >= S_AUTHORIZING && chargingInfo[i]->SystemStatus <= S_PREPARNING) ||
+				(chargingInfo[i]->SystemStatus >= S_TERMINATING && chargingInfo[i]->SystemStatus < S_COMPLETE))
+			{
+				strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+				return;
+			}
+			if (chargingInfo[i]->SystemStatus == S_CHARGING)
+			{
+				stopReq = i;
+			}
+			else if (chargingInfo[i]->SystemStatus == S_IDLE && chargingInfo[i]->IsAvailable == YES)
+			{
+				idleReq = true;
+			}
+		}
+
+		if (strlen((char *)ShmSysConfigAndInfo->SysConfig.UserId) > 0)
+		{
+			if (stopReq < _gunCount &&
+					chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == S_CHARGING)
+			{
+				char value[32];
+
+				PRINTF_FUNC("stop charging \n");
+				PRINTF_FUNC("index = %d, card number = %s, UserId = %s \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected,
+						chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->StartUserId, ShmSysConfigAndInfo->SysConfig.UserId);
+				memcpy(value, (unsigned char *)chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->StartUserId,
+						ARRAY_SIZE(chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->StartUserId));
+				if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.UserId, value) == EQUAL)
+				{
+					ChargingTerminalProcess(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+				}
+				strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+			}
+			else if (chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == S_COMPLETE)
+			{
+				strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+			}
+			else if (idleReq)
+			{
+				if (_gunCount > 1 && stopReq != 255 && ONE_CONNECTOR_USE == YES)
+				{
+					idleReq = false;
+					strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+				}
+				else
+				{
+					PRINTF_FUNC("// LCM => Authorizing \n");
+					// LCM => Authorizing
+					ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZING;
+					// 進入確認卡號狀態
+					AuthorizingStart();
+				}
+			}
+			else
+			{
+				strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+			}
+		}
+	}
+}
+
+unsigned char isModeChange(unsigned char gun_index)
+{
+	unsigned char result = NO;
+
+	if(chargingInfo[gun_index]->SystemStatus != chargingInfo[gun_index]->PreviousSystemStatus)
+	{
+		result = YES;
+		chargingInfo[gun_index]->PreviousSystemStatus = chargingInfo[gun_index]->SystemStatus;
+	}
+
+	return result;
+}
+
+void ScannerCardProcess()
+{
+	if (!isDetectPlugin() && !isCardScan && ShmSysConfigAndInfo->SysWarningInfo.Level == 0 &&
+			ShmSysConfigAndInfo->SysConfig.AuthorisationMode == _SYS_AUTHORIZE_OCPP)
+	{
+		isCardScan = true;
+		// 處理刷卡及驗證卡號的動作
+		UserScanFunction();
+	}
+
+	if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZING)
+	{
+		StartSystemTimeoutDet(Timeout_Authorizing);
+
+		// 確認驗證卡號完成沒
+		if (isAuthorizedComplete() || ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING)
+		{
+			StopSystemTimeoutDet();
+			// 判斷後台回覆狀態
+			if(canStartCharging() || ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING)
+			{
+				// LCM => Authorize complete
+				ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_COMP;
+			}
+			else
+			{
+				// LCM => Authorize fail
+				ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_FAIL;
+			}
+			ClearAuthorizedFlag();
+		}
+		else if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST)
+		{
+			// 白名單驗證
+			for (int i = 0; i < 10; i++)
+			{
+				if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i], "") != EQUAL)
+				{
+					if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i], (char *)ShmSysConfigAndInfo->SysConfig.UserId) == EQUAL)
+					{
+						ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_COMP;
+						ClearAuthorizedFlag();
+						break;
+					}
+				}
+			}
+		}
+	}
+	else if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZ_FAIL)
+	{
+		StartSystemTimeoutDet(Timeout_VerifyFail);
+		isCardScan = false;
+	}
+	else if(ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZ_COMP)
+	{
+		StartSystemTimeoutDet(Timeout_VerifyComp);
+	}
+	else if(ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_WAIT_FOR_PLUG)
+	{
+		StartSystemTimeoutDet(Timeout_WaitPlug);
+	}
+	else
+		isCardScan = false;
+}
+
+void AddGunInfoByConnector(byte typeValue, byte slots)
+{
+	switch (typeValue)
+	{
+		case '0': // none
+			break;
+		case '1': // IEC 62196-2 Type 1/SAE J1772 Plug
+			break;
+		case '2': // IEC 62196-2 Type 1/SAE J1772 Socket
+			break;
+		case '3': // IEC 62196-2 Type 2 Plug
+			break;
+		case '4': // IEC 62196-2 Type 2 Socket
+			break;
+		case '5': // GB/T AC Plug
+			break;
+		case '6': // GB/T AC Socket
+			break;
+		case 'J': // CHAdeMO
+		{
+			if (CHAdeMO_QUANTITY > _chademoIndex)
+			{
+				chargingInfo[_gunIndex] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[_chademoIndex];
+
+				chargingInfo[_gunIndex]->Index = _gunIndex;
+				chargingInfo[_gunIndex]->slotsIndex = slots;
+				chargingInfo[_gunIndex]->SystemStatus = S_BOOTING;
+				chargingInfo[_gunIndex]->Type = _Type_Chademo;
+				chargingInfo[_gunIndex]->type_index = _chademoIndex;
+				chargingInfo[_gunIndex]->IsAvailable = YES;
+				_chademoIndex++;
+				_gunIndex++;
+			}
+		}
+			break;
+		case 'U': // CCS1 combo
+			break;
+		case 'E': // CCS2 combo
+		{
+			if (CCS_QUANTITY > _ccsIndex)
+			{
+				chargingInfo[_gunIndex] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[_ccsIndex];
+
+				chargingInfo[_gunIndex]->Index =	_gunIndex;
+				chargingInfo[_gunIndex]->slotsIndex = slots;
+				chargingInfo[_gunIndex]->SystemStatus = S_BOOTING;
+				chargingInfo[_gunIndex]->Type = _Type_CCS_2;
+				chargingInfo[_gunIndex]->type_index = _ccsIndex;
+				chargingInfo[_gunIndex]->IsAvailable = YES;
+				// 現階段預設為走 DIN70121
+				ShmCcsData->CommProtocol = 0x01;
+				_ccsIndex++;
+				_gunIndex++;
+			}
+		}
+			break;
+		case 'G': // GBT DC
+			break;
+		case 'D': // GBT DC x 2
+			break;
+	}
+}
+
+bool CheckConnectorTypeStatus()
+{
+	bool result = true;
+
+	PRINTF_FUNC("bd0_1_status = %d, bd0_2_status = %d, bd1_1_status = %d, bd1_2_status = %d \n",
+			bd0_1_status, bd0_2_status, bd1_1_status, bd1_2_status);
+	if (strlen((char *) ShmSysConfigAndInfo->SysConfig.ModelName) >= 9)
+	{
+		byte slots = 1;
+		for (byte typeIndex = 7; typeIndex <= 9; typeIndex++)
+		{
+			AddGunInfoByConnector(ShmSysConfigAndInfo->SysConfig.ModelName[typeIndex], slots);
+			slots++;
+		}
+
+		_gunCount = _gunIndex;
+		PRINTF_FUNC("_gunCount = %d \n", _gunCount);
+		if (_gunCount == 0)
+			result = false;
+
+		// 偵測槍屬於哪個 slot : 可知道插在板上的Slot 0 或 1 是 Chademo 還是 CCS
+		for (byte gunIndex = 0; gunIndex < _gunCount; gunIndex++)
+		{
+			if (bd0_1_status == 0 && bd0_2_status == 1)
+			{
+				// 與硬體相同 type : Chademo
+				if (chargingInfo[gunIndex]->Type == _Type_Chademo)
+				{
+					chargingInfo[gunIndex]->Evboard_id = 0x01;
+				}
+			}
+			else if (bd0_1_status == 1 && bd0_2_status == 0)
+			{
+				// 與硬體相同 type : CCS
+				if (chargingInfo[gunIndex]->Type == _Type_CCS_2)
+				{
+					chargingInfo[gunIndex]->Evboard_id = 0x01;
+				}
+			}
+
+			if (bd1_1_status == 0 && bd1_2_status == 1)
+			{
+				// 與硬體相同 type : Chademo
+				if (chargingInfo[gunIndex]->Type == _Type_Chademo)
+				{
+					chargingInfo[gunIndex]->Evboard_id = 0x02;
+				}
+
+				if (_gunCount == 1)
+					chargingInfo[gunIndex]->Evboard_id = 0x01;
+			}
+			else if (bd1_1_status == 1 && bd1_2_status == 0)
+			{
+				// 與硬體相同 type : CCS
+				if (chargingInfo[gunIndex]->Type == _Type_CCS_2)
+				{
+					chargingInfo[gunIndex]->Evboard_id = 0x02;
+				}
+
+				if (_gunCount == 1)
+					chargingInfo[gunIndex]->Evboard_id = 0x01;
+			}
+
+			PRINTF_FUNC("index = %d, Type = %d, Evboard_id = %d \n", gunIndex, chargingInfo[gunIndex]->Type, chargingInfo[gunIndex]->Evboard_id);
+			if (chargingInfo[gunIndex]->Evboard_id == 0x00)
+				result = false;
+		}
+	}
+	else
+	{
+		// Module Name 不正確 - 告警
+		result = false;
+	}
+
+	return result;
+}
+
+void KillTask()
+{
+	ChangeLcmByIndex(_LCM_FIX);
+	system("killall Module_EventLogging");
+	system("killall Module_PrimaryComm");
+	system("killall Module_EvComm");
+	system("killall Module_LcmControl");
+	system("killall Module_InternalComm");
+	system("killall Module_PsuComm");
+}
+
+char CheckUpdateProcess()
+{
+	DIR *d;
+	struct dirent *dir;
+	d = opendir("/mnt/");
+
+	if (d)
+	{
+		long int MaxLen=48*1024*1024, ImageLen = 0;
+		while ((dir = readdir(d)) != NULL)
+		{
+			char *new_str;
+			new_str = malloc(strlen("/mnt/")+strlen(dir->d_name)+1);
+			new_str[0] = '\0';
+			strcat(new_str, "/mnt/");
+			strcat(new_str, dir->d_name);
+			int fd = open(new_str, O_RDONLY);
+			if (fd < 0)
+			{
+				return FAIL;
+			}
+
+			unsigned char *ptr = malloc(MaxLen); //-48 is take out the header
+			memset(ptr, 0xFF, MaxLen);  //-48 is take out the header
+			//get the image length
+			ImageLen = read(fd, ptr, MaxLen);
+
+			if (ImageLen > 20)
+			{
+				unsigned int Type = (((unsigned int)ptr[16])<<24 | ((unsigned int)ptr[17])<<16 | ((unsigned int)ptr[18])<<8 | ((unsigned int)ptr[19]));
+			    PRINTF_FUNC("Typed...%x \r\n", Type);
+
+			    switch (Type)
+			    {
+			    	case 0x10000001:
+			    	case 0x10000002:
+			    	case 0x10000003:
+			    	case 0x10000004:
+			    	case 0x10000005:
+			    	{
+			    		if (Upgrade_Flash(Type, new_str, ShmSysConfigAndInfo->SysConfig.ModelName) == PASS)
+			    			return PASS;
+			    		else
+			    			return FAIL;
+			    	}
+			    	break;
+			    	case 0x10000006:
+			    	case 0x1000000D:
+			    	case 0x1000000E:
+			    	{
+			    		// CSU_PRIMARY_CONTROLLER : 0x10000006
+			    		byte target = 0x00;
+
+			    		if (Type == 0x10000006)
+			    			target = UPGRADE_PRI;
+			    		else if (Type == 0x1000000D)
+			    			target = UPGRADE_RB;
+			    		else if (Type == 0x1000000E)
+			    			target = UPGRADE_FAN;
+
+			    		int fd = InitComPort(target);
+
+			    		if (Upgrade_UART(fd, Type, target, new_str, ShmSysConfigAndInfo->SysConfig.ModelName) == PASS)
+			    			return PASS;
+			    		else
+			    			return FAIL;
+
+			    		close(fd);
+			    	}
+			    	break;
+			    	case 0x10000007:
+			    	case 0x10000008:
+			    	case 0x10000009:
+			    	case 0x1000000A:
+			    	case 0x1000000B:
+			    	case 0x1000000C:
+			    	{
+			    		// CHAdeMO_BOARD : 0x1000000B
+			    		bool isPass = true;
+			    		int CanFd = InitCanBus();
+
+			    		if (CanFd > 0)
+			    		{
+			    			for(byte index = 0; index < _gunCount; index++)
+			    			{
+			    				if (!isPass)
+			    					break;
+
+			    				if (Type == 0x1000000B && chargingInfo[index]->Type == _Type_Chademo)
+			    				{
+			    					if (Upgrade_CAN(CanFd, Type, chargingInfo[index]->Evboard_id, new_str, ShmSysConfigAndInfo->SysConfig.ModelName) != PASS)
+			    					{
+			    						PRINTF_FUNC("Upgrad Fail. \n");
+			    						isPass = false;
+			    					}
+			    				}
+			    				else if ((Type == 0x10000007 || Type == 0x10000008 || Type == 0x10000009 || Type == 0x1000000A) &&
+			    						chargingInfo[index]->Type == _Type_CCS_2)
+			    				{
+			    					if (Upgrade_CAN(CanFd, Type, chargingInfo[index]->Evboard_id, new_str, ShmSysConfigAndInfo->SysConfig.ModelName) != PASS)
+			    					{
+			    						PRINTF_FUNC("Upgrad Fail. \n");
+			    						isPass = false;
+			    					}
+			    				}
+			    			}
+			    		}
+			    		else
+			    		{
+			    			PRINTF_FUNC("Upgrad FD fail. \n");
+			    			isPass = false;
+			    		}
+
+			    		return isPass;
+			    		break;
+			    	}
+			    }
+			}
+			free(new_str);
+			free(ptr);
+		}
+	}
+	free(dir);
+	closedir(d);
+	return FAIL;
+}
+
+void CreateRfidFork()
+{
+	pid_t rfidRecPid;
+
+	rfidRecPid = fork();
+	if (rfidRecPid == 0)
+	{
+		while(true)
+		{
+			// 刷卡判斷
+			RFID rfid;
+			if(getRequestCardSN(rfidFd, 0, &rfid))
+			{
+				PRINTF_FUNC("Get Card.. \n");
+				if (strlen((char *)ShmSysConfigAndInfo->SysConfig.UserId) == 0)
+				{
+					if (ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian == RFID_ENDIAN_LITTLE)
+					{
+						switch (rfid.snType)
+						{
+						case RFID_SN_TYPE_6BYTE:
+							sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
+									"%02X%02X%02X%02X%02X%02X",
+									rfid.currentCard[0], rfid.currentCard[1],
+									rfid.currentCard[2], rfid.currentCard[3],
+									rfid.currentCard[4], rfid.currentCard[5]);
+							break;
+						case RFID_SN_TYPE_7BYTE:
+							sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
+									"%02X%02X%02X%02X%02X%02X%02X",
+									rfid.currentCard[0], rfid.currentCard[1],
+									rfid.currentCard[2], rfid.currentCard[3],
+									rfid.currentCard[4], rfid.currentCard[5],
+									rfid.currentCard[6]);
+							break;
+						case RFID_SN_TYPE_10BYTE:
+							sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
+									"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
+									rfid.currentCard[0], rfid.currentCard[1],
+									rfid.currentCard[2], rfid.currentCard[3],
+									rfid.currentCard[4], rfid.currentCard[5],
+									rfid.currentCard[6], rfid.currentCard[7],
+									rfid.currentCard[8], rfid.currentCard[9]);
+							break;
+						case RFID_SN_TYPE_4BYTE:
+							sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
+									"%02X%02X%02X%02X",
+									rfid.currentCard[0], rfid.currentCard[1],
+									rfid.currentCard[2], rfid.currentCard[3]);
+							break;
+						}
+					}
+					else if (ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian == RFID_ENDIAN_BIG)
+					{
+						switch (rfid.snType)
+						{
+						case RFID_SN_TYPE_6BYTE:
+							sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
+									"%02X%02X%02X%02X%02X%02X",
+									rfid.currentCard[5], rfid.currentCard[4],
+									rfid.currentCard[3], rfid.currentCard[2],
+									rfid.currentCard[1], rfid.currentCard[0]);
+							break;
+						case RFID_SN_TYPE_7BYTE:
+							sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
+									"%02X%02X%02X%02X%02X%02X%02X",
+									rfid.currentCard[6], rfid.currentCard[5],
+									rfid.currentCard[4], rfid.currentCard[3],
+									rfid.currentCard[2], rfid.currentCard[1],
+									rfid.currentCard[0]);
+							break;
+						case RFID_SN_TYPE_10BYTE:
+							sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
+									"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
+									rfid.currentCard[9], rfid.currentCard[8],
+									rfid.currentCard[7], rfid.currentCard[6],
+									rfid.currentCard[5], rfid.currentCard[4],
+									rfid.currentCard[3], rfid.currentCard[2],
+									rfid.currentCard[1], rfid.currentCard[0]);
+							break;
+						case RFID_SN_TYPE_4BYTE:
+							sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
+									"%02X%02X%02X%02X",
+									rfid.currentCard[3], rfid.currentCard[2],
+									rfid.currentCard[1], rfid.currentCard[0]);
+							break;
+						}
+					}
+
+					PRINTF_FUNC("card number = %s\n", ShmSysConfigAndInfo->SysConfig.UserId);
+				}
+			}
+			sleep(1);
+		}
+	}
+}
+
+void StartSystemTimeoutDet(unsigned char flag)
+{
+	if (ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag != flag)
+	{
+		gettimeofday(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer, NULL);
+	}
+	ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = flag;
+}
+
+void StopSystemTimeoutDet()
+{
+	gettimeofday(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer, NULL);
+	ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = Timeout_None;
+}
+
+void StartGunInfoTimeoutDet(unsigned char gunIndex, unsigned char flag)
+{
+	if (gunIndex < _gunCount)
+	{
+		if (chargingInfo[gunIndex]->TimeoutFlag != flag)
+		{
+			gettimeofday(&chargingInfo[gunIndex]->TimeoutTimer, NULL);
+		}
+		chargingInfo[gunIndex]->TimeoutFlag = flag;
+	}
+}
+
+void StopGunInfoTimeoutDet(unsigned char gunIndex)
+{
+	if (gunIndex < _gunCount)
+	{
+		chargingInfo[gunIndex]->TimeoutFlag = Timeout_None;
+	}
+}
+
+void CreateTimeoutFork()
+{
+	pid_t timeoutPid;
+
+	timeoutPid = fork();
+	if (timeoutPid == 0)
+	{
+		while(true)
+		{
+			// 系統
+			switch(ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag)
+			{
+				case Timeout_SelftestChk:
+					if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) >= 40000000)
+					{
+						_SelfTestTimeout();
+						StopSystemTimeoutDet();
+					}
+					break;
+				case Timeout_Authorizing:
+					if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) >= 30000000)
+					{
+						_AuthorizedTimeout();
+						StopSystemTimeoutDet();
+					}
+					break;
+				case Timeout_VerifyFail:
+					if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) >= 3000000)
+					{
+						_AutoReturnTimeout();
+						StopSystemTimeoutDet();
+					}
+					break;
+				case Timeout_VerifyComp:
+					if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) >= 3000000)
+					{
+						_AutoReturnTimeout();
+						StopSystemTimeoutDet();
+					}
+					break;
+				case Timeout_WaitPlug:
+					if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) >= 40000000)
+					{
+						_DetectPlugInTimeout();
+						StopSystemTimeoutDet();
+					}
+					break;
+				case Timeout_ReturnToChargingGunDet:
+				{
+					if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) >= 10000000)
+					{
+						DisplayChargingInfo();
+						StopSystemTimeoutDet();
+					}
+				}
+					break;
+			}
+			// 各槍
+			for (byte gun_index = 0; gun_index < _gunCount; gun_index++)
+			{
+				switch(chargingInfo[gun_index]->TimeoutFlag)
+				{
+					case Timeout_Preparing:
+						if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 30000000)
+						{
+							_PrepareTimeout(gun_index);
+							StopGunInfoTimeoutDet(gun_index);
+						}
+						break;
+					case Timeout_EvChargingDet:
+						if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 120000000)
+						{
+							_DetectEvChargingEnableTimeout(gun_index);
+							StopGunInfoTimeoutDet(gun_index);
+						}
+						break;
+					case Timeout_EvseChargingDet:
+						if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 30000000)
+						{
+							_DetectEvseChargingEnableTimeout(gun_index);
+							StopGunInfoTimeoutDet(gun_index);
+						}
+						break;
+					case Timeout_WaitforCompleteDet:
+						if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 10000000)
+						{
+							_CompleteTimeout(gun_index);
+							StopGunInfoTimeoutDet(gun_index);
+						}
+						break;
+					case Timeout_ForCcsPrechargeDet:
+						if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 60000000)
+						{
+							_CcsPrechargeTimeout(gun_index);
+							StopGunInfoTimeoutDet(gun_index);
+						}
+						break;
+				}
+			}
+			usleep(100000);
+		}
+	}
+}
+
+void GetSystemTime()
+{
+	struct timeb csuTime;
+	struct tm *tmCSU;
+
+	ftime(&csuTime);
+	tmCSU = localtime(&csuTime.time);
+	PRINTF_FUNC("Time : %04d-%02d-%02d %02d:%02d:%02d \n", tmCSU->tm_year + 1900,
+			tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
+			tmCSU->tm_sec);
+
+//	byte date[14];
+//
+//
+//		 //sprintf(&date, "%d", );
+//
+//		 date[0] = '0' + ((tmCSU->tm_year + 1900) / 1000 % 10);
+
+//	date[0] = (tmCSU->tm_year + 1900) / 1000 % 10;
+//	date[1] = (tmCSU->tm_year + 1900) / 100 % 10;
+//	date[2] = (tmCSU->tm_year + 1900) / 10 % 10;
+//	date[3] = (tmCSU->tm_year + 1900) / 1 % 10;
+//
+//	date[4] = (tmCSU->tm_mon + 1) / 10 % 10;
+//	date[5] = (tmCSU->tm_mon + 1) / 1 % 10;
+//
+//	date[6] = (tmCSU->tm_mday) / 10 % 10;
+//	date[7] = (tmCSU->tm_mday) / 1 % 10;
+//
+//	date[8] = (tmCSU->tm_hour) / 10 % 10;
+//	date[9] = (tmCSU->tm_hour) / 1 % 10;
+//
+//	date[10] = (tmCSU->tm_min) / 10 % 10;
+//	date[11] = (tmCSU->tm_min) / 1 % 10;
+//
+//	date[12] = (tmCSU->tm_sec) / 10 % 10;
+//	date[13] = (tmCSU->tm_sec) / 1 % 10;
+
+//	PRINTF_FUNC("%x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x \n", date[0], date[1], date[2], date[3],
+//			date[4], date[5], date[6], date[7],
+//			date[8], date[9], date[10], date[11],
+//			date[12], date[13]);
+}
+
+void CheckFactoryConfigFunction()
+{
+	if(ShmSysConfigAndInfo->SysInfo.FactoryConfiguration)
+	{
+		system("cd /root;./FactoryConfig -m");
+		system("sync");
+		sleep(5);
+		system("reboot -f");
+		sleep(5);
+		system("reboot -f");
+	}
+}
+
+void CheckFwUpdateFunction()
+{
+	//PRINTF_FUNC("ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = %d \n", ShmSysConfigAndInfo->SysInfo.FirmwareUpdate);
+	if (ShmSysConfigAndInfo->SysInfo.FirmwareUpdate == YES)
+	{
+		DEBUG_INFO_MSG("ftp : update start. \n");
+		KillTask();
+		if (CheckUpdateProcess() == PASS)
+			DEBUG_INFO_MSG("ftp : update complete. \n");
+		else
+			DEBUG_INFO_MSG("ftp : update fail. \n");
+
+		ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = NO;
+		sleep(5);
+		system("reboot -f");
+	}
+	else if(ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq == YES)
+	{
+		ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = NO;
+	}
+	else if (strcmp((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Downloaded") == EQUAL)
+	{
+		DEBUG_INFO_MSG("Backend : update start. \n");
+		strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "");
+		strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installing");
+		KillTask();
+
+		if (CheckUpdateProcess() == PASS)
+		{
+			DEBUG_INFO_MSG("Backend : update complete. \n");
+			strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "");
+			strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installed");
+		}
+		else
+		{
+			DEBUG_INFO_MSG("Backend : update fail. \n");
+			strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "");
+			strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "InstallationFailed");
+		}
+
+		ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
+		sleep(5);
+		system("reboot -f");
+	}
+	else if (strcmp((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "DownloadFailed") == EQUAL)
+	{
+		DEBUG_ERROR_MSG("Backend to download file fail. \n");
+		strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "");
+		strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "InstallationFailed");
+		ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
+	}
+}
+
+//===============================================
+// Check reservation date is expired
+//===============================================
+int isReservationExpired(unsigned char gun_index)
+{
+	int result = NO;
+	struct tm expiredDate;
+	struct timeb expiredTime;
+
+	if (sscanf((char*) ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,
+			"%4d-%2d-%2dT%2d:%2d:%2d", &expiredDate.tm_year,
+			&expiredDate.tm_mon, &expiredDate.tm_mday, &expiredDate.tm_hour,
+			&expiredDate.tm_min, &expiredDate.tm_sec) == 6)
+	{
+		expiredDate.tm_year -= 1900;
+		expiredDate.tm_mon -= 1;
+
+		expiredTime.time = mktime(&expiredDate);
+		if (!CheckTimeOut(expiredTime))
+		{
+			result = YES;
+		}
+	}
+
+	return result;
+}
+
+//===============================================
+// OCPP
+//===============================================
+void CheckOcppStatus()
+{
+	if (ShmOCPP16Data->SpMsg.bits.BootNotificationConf == YES)
+	{
+		ShmSysConfigAndInfo->SysInfo.OcppConnStatus = YES;
+		ShmOCPP16Data->SpMsg.bits.BootNotificationConf = NO;
+	}
+
+	if (ShmOCPP16Data->MsMsg.bits.ResetReq == YES)
+	{
+		ShmOCPP16Data->MsMsg.bits.ResetReq = NO;
+		if(strcmp((char *)ShmOCPP16Data->Reset.Type, "Hard") == EQUAL)
+		{
+			DEBUG_ERROR_MSG("****** Hard Reboot ****** \n");
+			sleep(3);
+			system("reboot -f");
+		}
+		else if (strcmp((char *)ShmOCPP16Data->Reset.Type, "Soft") == EQUAL)
+		{
+			DEBUG_ERROR_MSG("****** Soft Reboot ****** \n");
+			sleep(3);
+			KillTask();
+			system("/usr/bin/run_evse_restart.sh");
+		}
+	}
+}
+
+void OcppStartTransation(byte gunIndex)
+{
+	if(strcmp((char *)chargingInfo[gunIndex]->StartUserId, "") == EQUAL)
+		strcpy((char *)ShmOCPP16Data->StartTransaction[gunIndex].IdTag, (char *)ShmOCPP16Data->StartTransaction[gunIndex].IdTag);
+	else
+		strcpy((char *)ShmOCPP16Data->StartTransaction[gunIndex].IdTag, (char *)chargingInfo[gunIndex]->StartUserId);
+
+	PRINTF_FUNC("IdTag = %s \n", ShmOCPP16Data->StartTransaction[gunIndex].IdTag);
+	ShmOCPP16Data->CpMsg.bits[gunIndex].StartTransactionReq = YES;
+}
+
+void OcppStopTransation(byte gunIndex)
+{
+	if(strcmp((char *)chargingInfo[gunIndex]->StartUserId, "") == EQUAL)
+		strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].IdTag, (char *)ShmOCPP16Data->StopTransaction[gunIndex].IdTag);
+	else
+		strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].IdTag, (char *)chargingInfo[gunIndex]->StartUserId);
+
+	PRINTF_FUNC("IdTag = %s \n", ShmOCPP16Data->StopTransaction[gunIndex].IdTag);
+	ShmOCPP16Data->CpMsg.bits[gunIndex].StopTransactionReq = YES;
+}
+
+bool OcppRemoteStop(byte gunIndex)
+{
+	bool result = ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq;
+	if (ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq == YES)
+		ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq = NO;
+
+	return result;
+}
+
+void OcppRemoteStartChk()
+{
+	if(!isDetectPlugin())
+	{
+		for (byte gun_index = 0; gun_index < _gunCount; gun_index++)
+		{
+			if ((chargingInfo[gun_index]->SystemStatus == S_IDLE || chargingInfo[gun_index]->SystemStatus == S_RESERVATION)&&
+					ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStartTransactionReq == YES)
+			{
+				ShmSysConfigAndInfo->SysInfo.OrderCharging = gun_index;
+				ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStartTransactionReq = NO;
+				DetectPluginStart();
+				break;
+			}
+		}
+	}
+}
+
+void ChkOcppStatus(byte gunIndex)
+{
+	if (chargingInfo[gunIndex]->SystemStatus == S_IDLE &&
+			ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowReq == YES)
+	{
+		ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowReq = NO;
+		if (isReservationExpired(gunIndex))
+		{
+			PRINTF_FUNC("***************ChkOcppStatus : OcppReservedStatus******************** \n");
+			DEBUG_ERROR_MSG("***************ChkOcppStatus : OcppReservedStatus******************** \n");
+			chargingInfo[gunIndex]->ReservationId = ShmOCPP16Data->ReserveNow[gunIndex].ReservationId;
+			chargingInfo[gunIndex]->SystemStatus = S_RESERVATION;
+		}
+	}
+
+	if (chargingInfo[gunIndex]->SystemStatus == S_RESERVATION &&
+			ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationReq == YES)
+	{
+		ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationReq = NO;
+		if (isReservationExpired(gunIndex))
+		{
+			PRINTF_FUNC("***************ChkOcppStatus : Cancel OcppReservedStatus******************** \n");
+			DEBUG_ERROR_MSG("***************ChkOcppStatus : Cancel OcppReservedStatus******************** \n");
+			chargingInfo[gunIndex]->ReservationId = 0;
+			chargingInfo[gunIndex]->SystemStatus = S_IDLE;
+		}
+	}
+
+	if (ShmOCPP16Data->CsMsg.bits[gunIndex].ChangeAvailabilityReq == YES)
+	{
+		PRINTF_FUNC("***************ChkOcppStatus : OcppChangeAvailability******************** \n");
+		DEBUG_ERROR_MSG("***************ChkOcppStatus : OcppChangeAvailability******************** \n");
+		ShmOCPP16Data->CsMsg.bits[gunIndex].ChangeAvailabilityReq = NO;
+		if(strcmp((char *)ShmOCPP16Data->ChangeAvailability[gunIndex].Type, "Operative") == EQUAL)
+			chargingInfo[gunIndex]->IsAvailable = YES;
+		else if (strcmp((char *)ShmOCPP16Data->ChangeAvailability[gunIndex].Type, "Inoperative") == EQUAL)
+			chargingInfo[gunIndex]->IsAvailable = NO;
+	}
+}
+
+bool CheckBackendChargingTimeout(byte gunIndex)
+{
+	bool result = false;
+
+	if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == _SYS_AUTHORIZE_OCPP)
+	{
+		if (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration > 0)
+		{
+			if (chargingInfo[gunIndex]->RemainChargingDuration >= (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration * 60))
+				result = true;
+		}
+	}
+	else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == _SYS_AUTHORIZE_FREE)
+	{
+		// 隨插即充電的要看 offline
+		if (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration > 0)
+		{
+			if (chargingInfo[gunIndex]->RemainChargingDuration >= (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration * 60))
+				result = true;
+		}
+	}
+
+	return result;
+}
+
+bool CheckBackendChargingEnergy(byte gunIndex)
+{
+	bool result = false;
+
+	if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == _SYS_AUTHORIZE_OCPP)
+	{
+		if (ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy > 0)
+		{
+			if (chargingInfo[gunIndex]->PresentChargedEnergy >= ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy)
+				result = true;
+		}
+	}
+	else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == _SYS_AUTHORIZE_FREE)
+	{
+		// 隨插即充電的要看 offline
+		if (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy > 0)
+		{
+			if (chargingInfo[gunIndex]->PresentChargedEnergy >= (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy))
+				result = true;
+		}
+	}
+
+	return result;
+}
+
+//===============================================
+// Config process
+//===============================================
+void AddPlugInTimes(byte gunIndex)
+{
+	if (chargingInfo[gunIndex]->Type == _Type_Chademo)
+		ShmSysConfigAndInfo->SysConfig.ChademoPlugInTimes += 1;
+	else if(chargingInfo[gunIndex]->Type == _Type_CCS_2)
+		ShmSysConfigAndInfo->SysConfig.Ccs2PlugInTimes += 1;
+	else if(chargingInfo[gunIndex]->Type == _Type_GB)
+		ShmSysConfigAndInfo->SysConfig.GbPlugInTimes += 1;
+}
+
+void ChangeStartOrStopDateTime(byte isStart, byte gunIndex)
+{
+	char cmdBuf[32];
+	struct timeb csuTime;
+	struct tm *tmCSU;
+
+	ftime(&csuTime);
+	tmCSU = localtime(&csuTime.time);
+
+	sprintf(cmdBuf, "%04d-%02d-%02d %02d:%02d:%02d", tmCSU->tm_year + 1900,
+			tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
+			tmCSU->tm_sec);
+	if (isStart)
+		strcpy((char *)chargingInfo[gunIndex]->StartDateTime, cmdBuf);
+	else
+		strcpy((char *)chargingInfo[gunIndex]->StopDateTime, cmdBuf);
+}
+
+void zipLogFiles()
+{
+	const char* logPath = "/Storage/SystemLog";
+	// 獲取目錄
+	DIR* pDir = opendir(logPath);
+	if (pDir != NULL)
+	{
+		struct timeb csuTime;
+		struct tm *tmCSU;
+
+		ftime(&csuTime);
+		tmCSU = localtime(&csuTime.time);
+//		PRINTF_FUNC("Time : %04d-%02d-%02d %02d:%02d:%02d \n", tmCSU->tm_year + 1900,
+//			tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
+//			tmCSU->tm_sec);
+
+		// Read items inside the folder
+		struct dirent* pEntry = NULL;
+		while ((pEntry = readdir(pDir)) != NULL)
+		{
+			if (strcmp(pEntry->d_name, ".") != 0 &&
+					strcmp(pEntry->d_name, "..") != 0 &&
+					strncmp(pEntry->d_name, "[", 1) == 0 &&
+					strstr(pEntry->d_name, "tar") < 0)
+			{
+				char yearC[5];
+				unsigned short year = 0;
+				char monthC[3];
+				unsigned short month = 0;
+
+				yearC[4] = '\0';
+				strncpy(yearC, pEntry->d_name + 1, 4);
+				monthC[2] = '\0';
+				strncpy(monthC, pEntry->d_name + 6, 2);
+
+				year = atoi(yearC);
+				month = atoi(monthC);
+
+				if (year != 0)
+				{
+					if (year < tmCSU->tm_year + 1900 ||
+							(year >= tmCSU->tm_year + 1900 && month < tmCSU->tm_mon + 1))
+					{
+						DEBUG_INFO_MSG("tar file name : %s \n", pEntry->d_name);
+						char file[256];
+
+						memset(file, 0x00, sizeof(file));
+						strcat(file, "tar zcvf ");
+						strcat(file, logPath);
+						strncat(file, "/", 1);
+						strcat(file, pEntry->d_name);
+						strcat(file, ".tar");
+						strncat(file, " ", 1);
+						strcat(file, logPath);
+						strncat(file, "/", 1);
+						strcat(file, pEntry->d_name);
+						PRINTF_FUNC("zip = %s \n", file);
+						system(file);
+					}
+				}
+			}
+		}
+	}
+	// Close folder
+	closedir(pDir);
+}
+
+void StopProcessing()
+{
+	for (;;)
+		sleep(5);
+}
+
+void CreateWatchdog()
+{
+	if (DEBUG == NO)
+	{
+		wtdFd = InitWatchDog();
+
+		if (wtdFd < 0)
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
+	}
+}
+
+int main(void)
+{
+	if(CreateShareMemory() == 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("CreatShareMemory NG \n");
+		#endif
+		if(ShmStatusCodeData!=NULL)
+		{
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
+		}
+		return 0;
+		sleep(5);
+		system("reboot -f");
+		sleep(5);
+		system("reboot -f");
+	}
+
+	PRINTF_FUNC("\n"); PRINTF_FUNC("Initial SystemConfig and Info.......\n");
+	if (!InitialSystemDefaultConfig())
+	{
+		DEBUG_ERROR_MSG("InitialSystemDefaultConfig NG \n");
+		StopProcessing();
+	}
+
+	PRINTF_FUNC("CheckConnectorTypeStatus. \n");
+	CheckGunTypeFromHw();
+	PRINTF_FUNC("InitialShareMemoryInfo & Initialization. \n");
+	InitialShareMemoryInfo();
+	PRINTF_FUNC("CheckConnectorTypeStatus. \n");
+	ChangeLcmByIndex(_LCM_INIT);
+	if (!CheckConnectorTypeStatus())
+	{
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ModelNameNoneMatchStestFail = YES;
+		ChangeLcmByIndex(_LCM_FIX);
+		// Module Name 與硬體對應不正確
+		PRINTF_FUNC("Module Name & HW info none match. \n");
+		DEBUG_ERROR_MSG("Module Name & HW info none match. \n");
+		sleep(3);
+		KillTask();
+		StopProcessing();
+	}
+	Initialization();
+	ShmSysConfigAndInfo->SysInfo.InternetConn = 1;
+	PRINTF_FUNC("Spawn all Task. \n");
+	SpawnTask();
+	PRINTF_FUNC("Module Name & HW info correct. Initialize.......\n");
+	CreateTimeoutFork();
+	PRINTF_FUNC("Self test. \n");
+	SelfTestRun();
+	StopSystemTimeoutDet();
+
+	PRINTF_FUNC("SelfTestSeq = %d, Work_Step = %d \n", ShmSysConfigAndInfo->SysInfo.SelfTestSeq, ShmPsuData->Work_Step);
+	if (ShmSysConfigAndInfo->SysInfo.SelfTestSeq == _STEST_FAIL ||
+			ShmPsuData->Work_Step == _NO_WORKING)
+	{
+		DisplaySelfTestFailReason();
+		for (byte gun_index = 0; gun_index < _gunCount; gun_index++)
+		{
+			setChargerMode(gun_index, MODE_ALARM);
+		}
+		ChangeLcmByIndex(_LCM_FIX);
+		StopProcessing();
+	}
+	else
+	{
+		for (byte gun_index = 0; gun_index < _gunCount; gun_index++)
+		{
+			setChargerMode(gun_index, MODE_IDLE);
+		}
+	}
+
+	ChangeLcmByIndex(_LCM_IDLE);
+	sleep(1);
+	//***** 須新增的偵測 *****//
+	// 1. Thernal - 控制風扇轉速
+	// 2. ouput fuse - 控制風扇轉速
+	CreateRfidFork();
+	// Create Watchdog
+	CreateWatchdog();
+
+	// Main loop
+	PRINTF_FUNC("Main Loop. \n");
+	for (;;)
+	{
+		CheckOcppStatus();
+		ChkPrimaryStatus();
+		if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_IDLE &&
+				ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag != Timeout_ReturnToChargingGunDet)
+		{
+			CheckFactoryConfigFunction();
+
+			CheckFwUpdateFunction();
+		}
+
+		// OCPP 邏輯
+		OcppRemoteStartChk();
+		// 讀卡邏輯
+		ScannerCardProcess();
+		for (byte gun_index = 0; gun_index < _gunCount; gun_index++)
+		{
+			CheckGpioInStatus();
+			CheckErrorOccurStatus(gun_index);
+			ChkOcppStatus(gun_index);
+
+			//PRINTF_FUNC("index = %d, ErrorCode = %s \n", gun_index, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
+			switch(chargingInfo[gun_index]->SystemStatus)
+			{
+				case S_IDLE:
+				case S_RESERVATION:
+				{
+					if (chargingInfo[gun_index]->SystemStatus == S_IDLE &&
+							isModeChange(gun_index))
+					{
+						PRINTF_FUNC("S_IDLE================================== %x \n", gun_index);
+						chargingInfo[gun_index]->RemainChargingDuration = 0;
+						chargingInfo[gun_index]->PresentChargedEnergy = 0;
+					}
+					else if (chargingInfo[gun_index]->SystemStatus == S_RESERVATION &&
+							isModeChange(gun_index))
+					{
+						PRINTF_FUNC("S_RESERVATION....................%x \n", gun_index);
+						ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = YES;
+					}
+
+					if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2)
+					{
+						if (gun_index == ShmSysConfigAndInfo->SysInfo.CurGunSelected)
+						{
+							ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_FIX;
+						}
+						ClearDetectPluginFlag();
+					}
+					else
+					{
+						if (ShmSysConfigAndInfo->SysInfo.SystemPage == _LCM_FIX)
+						{
+							ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+						}
+
+						if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER)
+						{
+							// 均充 -> 最大充
+						}
+						else
+						{
+							// 判斷是否有啟用檢查插槍
+							if(isDetectPlugin())
+							{
+								// 卡號驗證成功後,等待充電槍插入充電車
+								if ((ShmSysConfigAndInfo->SysInfo.OrderCharging != FAIL &&
+										ShmSysConfigAndInfo->SysInfo.OrderCharging < _gunCount))
+								{
+									if (chargingInfo[(unsigned char)ShmSysConfigAndInfo->SysInfo.OrderCharging]->ConnectorPlugIn == YES &&
+											chargingInfo[gun_index]->IsAvailable)
+									{
+										PRINTF_FUNC("-----------------1----------------- %d \n", ShmSysConfigAndInfo->SysInfo.OrderCharging);
+										ShmSysConfigAndInfo->SysInfo.CurGunSelected = ShmSysConfigAndInfo->SysInfo.OrderCharging;
+										AddPlugInTimes(ShmSysConfigAndInfo->SysInfo.OrderCharging);
+										setChargerMode(ShmSysConfigAndInfo->SysInfo.OrderCharging, MODE_REASSIGN_CHECK);
+										ClearDetectPluginFlag();
+										continue;
+									}
+								}
+								else
+								{
+									if (chargingInfo[gun_index]->ConnectorPlugIn == YES && chargingInfo[gun_index]->IsAvailable &&
+											chargingInfo[gun_index]->SystemStatus == S_IDLE)
+									{
+										PRINTF_FUNC("-----------------2----------------- \n");
+										ShmSysConfigAndInfo->SysInfo.CurGunSelected = gun_index;
+										AddPlugInTimes(gun_index);
+										strcpy((char *)chargingInfo[gun_index]->StartUserId, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
+										PRINTF_FUNC("index = %d, CardNumber = %s \n", gun_index, chargingInfo[gun_index]->StartUserId);
+										strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+										// 當前操作的槍號,進入 Preparing
+										setChargerMode(gun_index, MODE_REASSIGN_CHECK);
+										ClearDetectPluginFlag();
+										continue;
+									}
+								}
+
+								if (!isCardScan)
+								{
+									// LCM => Waiting for plugging
+									ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_WAIT_FOR_PLUG;
+								}
+							}
+							else if (chargingInfo[gun_index]->SystemStatus == S_RESERVATION)
+							{
+								if (!isReservationExpired(gun_index))
+								{
+									chargingInfo[gun_index]->SystemStatus = S_IDLE;
+								}
+							}
+							else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == _SYS_AUTHORIZE_FREE &&
+									(chargingInfo[gun_index]->ConnectorPlugIn == YES && chargingInfo[gun_index]->IsAvailable))
+							{
+								PRINTF_FUNC("-----------------3----------------- \n");
+								ShmSysConfigAndInfo->SysInfo.CurGunSelected = gun_index;
+								AddPlugInTimes(gun_index);
+								setChargerMode(gun_index, MODE_REASSIGN_CHECK);
+								ClearDetectPluginFlag();
+								continue;
+							}
+							else
+							{
+								if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
+									ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_IDLE;
+
+								if (_gunCount > 1 &&
+										ShmSysConfigAndInfo->SysInfo.PageIndex != _LCM_AUTHORIZING &&
+										ShmSysConfigAndInfo->SysInfo.PageIndex != _LCM_AUTHORIZ_FAIL &&
+										ShmSysConfigAndInfo->SysInfo.PageIndex != _LCM_AUTHORIZ_COMP &&
+										ShmSysConfigAndInfo->SysInfo.PageIndex != _LCM_WAIT_FOR_PLUG)
+								{
+									for (byte count = 0; count < _gunCount; count++)
+									{
+										if (count != ShmSysConfigAndInfo->SysInfo.CurGunSelected &&
+											((chargingInfo[count]->SystemStatus >= S_REASSIGN_CHECK && chargingInfo[count]->SystemStatus <= S_COMPLETE) ||
+											(chargingInfo[count]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[count]->SystemStatus <= S_CCS_PRECHARGE_ST1)))
+										{
+											StartSystemTimeoutDet(Timeout_ReturnToChargingGunDet);
+										}
+									}
+								}
+							}
+						}
+					}
+
+					ReleaseAlarmCode(gun_index);
+				}
+					break;
+				case S_REASSIGN_CHECK:
+				{
+					if (isModeChange(gun_index))
+					{
+						PRINTF_FUNC("S_REASSIGN_CHECK================================== %x \n", gun_index);
+						ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+						if (ShmSysConfigAndInfo->SysInfo.OrderCharging != FAIL)
+							ShmSysConfigAndInfo->SysInfo.OrderCharging = FAIL;
+						StopSystemTimeoutDet();
+					}
+
+					bool isRessign = false;
+					if (_gunCount > 1)
+					{
+						for (byte index = 0; index < _gunCount; index++)
+						{
+							// 有其他槍已經分配好 psu 模塊
+							if (ShmSysConfigAndInfo->SysInfo.CurGunSelected != index &&
+									chargingInfo[index]->SystemStatus >= S_PREPARNING)
+							{
+								PRINTF_FUNC("=============Smart Charging============= Step 1 \n");
+								ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_PREPARE;
+								isRessign = true;
+								break;
+							}
+						}
+					}
+
+					if (isRessign)
+						setChargerMode(gun_index, MODE_REASSIGN);
+					else
+						setChargerMode(gun_index, MODE_PRECHARGE);
+				}
+					break;
+				case S_REASSIGN:
+				{
+					if (isModeChange(gun_index))
+					{
+						PRINTF_FUNC("S_REASSIGN================================== %x \n", gun_index);
+					}
+
+					// 重新分配,此階段主要是讓已經在充電或者準備進入充電前的緩衝
+					// 此狀態下~ 控制權在於 PSU 及 EV小板 Process
+					if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_NONE ||
+							ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_COMP)
+						setChargerMode(gun_index, MODE_PRECHARGE);
+					else if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_RELAY &&
+						ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == NO)
+					{
+						PRINTF_FUNC("=============Smart Charging : _REASSIGNED_COMP============= Step 6 \n");
+						ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_COMP;
+						ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_AVER;
+					}
+
+					PRINTF_FUNC("CurGunSelected = %d, gun_index = %d \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected, gun_index);
+					if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
+						ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
+				}
+					break;
+				case S_PREPARNING:
+				{
+					if (isModeChange(gun_index))
+					{
+						PRINTF_FUNC("S_PREPARNING================================== %x \n", gun_index);
+						StopGunInfoTimeoutDet(gun_index);
+						StartGunInfoTimeoutDet(gun_index, Timeout_Preparing);
+					}
+
+					if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_NONE)
+						ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
+
+					// Precharge 三個流程 : 1 Precharge, 2 Preparing for ev, 3 Preparing for evse
+					// Precharge : AC Contactor <Relay board>, Relay k1 k2 <Relay board>, PSU AddressAssignment, PSU GroupAvailablePower
+					// Preparing for ev : 車端通訊流程
+					// Preparing for evse : PSU (output 500V, 2A), GFD Test <Relay board>
+					//ShmSysConfigAndInfo->SysInfo.AcContactorStatus == YES &&
+					if (((ShmPsuData->SystemPresentPsuQuantity > 0 &&
+							ShmPsuData->PsuGroup[gun_index].GroupPresentPsuQuantity > 0 &&
+							ShmPsuData->PsuGroup[gun_index].GroupAvailablePower > 10) &&
+							chargingInfo[gun_index]->AvailableChargingPower > 10))
+					{
+						setChargerMode(gun_index, MODE_PREPARE_FOR_EV);
+					}
+
+					if (isEvBoardStopChargeFlag(gun_index) == YES ||
+							OcppRemoteStop(gun_index) == YES)
+					{
+						// 板端或後臺要求停止
+						ChargingTerminalProcess(gun_index);
+					}
+
+					if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
+						ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
+				}
+					break;
+				case S_PREPARING_FOR_EV: // 等待車端的通訊 (EV 小板),待車端回報後,開始樁端的測試
+				{
+					if (isModeChange(gun_index))
+					{
+						PRINTF_FUNC("S_PREPARING_FOR_EV================================== %x \n", gun_index);
+						strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+						StopGunInfoTimeoutDet(gun_index);
+						StartGunInfoTimeoutDet(gun_index, Timeout_EvChargingDet);
+					}
+
+					if (chargingInfo[gun_index]->Type == _Type_Chademo)
+					{
+						// 檢查車端的槍鎖是否為鎖上
+						if (isEvGunLocked_chademo(gun_index) == YES)
+						{
+							setChargerMode(gun_index, MODE_PREPARE_FOR_EVSE);
+						}
+					}
+					else if (chargingInfo[gun_index]->Type == _Type_CCS_2)
+					{
+						// 檢查車端的 charging enable 是否為 1
+						if (isEvGunLocked_ccs(gun_index) == YES)
+						{
+							setChargerMode(gun_index, MODE_PREPARE_FOR_EVSE);
+						}
+					}
+
+					if (isEvBoardStopChargeFlag(gun_index) == YES  ||
+							OcppRemoteStop(gun_index) == YES)
+					{
+						// 板端或後臺要求停止
+						ChargingTerminalProcess(gun_index);
+					}
+
+					// LCM => Pre-charging
+					if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
+						ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
+				}
+					break;
+				case S_PREPARING_FOR_EVSE: // 等待 RB 通訊及測試,並將狀態回報, CSU 確認 Pass 後,開始進入充電
+				{
+					if (isModeChange(gun_index))
+					{
+						PRINTF_FUNC("S_PREPARING_FOR_EVSE================================== %x \n", gun_index);
+						StopGunInfoTimeoutDet(gun_index);
+						StartGunInfoTimeoutDet(gun_index, Timeout_EvseChargingDet);
+					}
+
+					if (chargingInfo[gun_index]->Type == _Type_Chademo)
+					{
+						// 檢查樁端的 GFD 結果
+						if (isPrechargeStatus_chademo(gun_index) > 5 && isPrechargeStatus_chademo(gun_index) < 8)
+						{
+							// 當前操作的槍號,進入 Charging
+							setChargerMode(gun_index, MODE_CHARGING);
+						}
+
+						if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
+						{
+							// GFD 錯誤停止
+							RecordAlarmCode("012234");
+						}
+					}
+					else if (chargingInfo[gun_index]->Type == _Type_CCS_2)
+					{
+						// 檢查樁端的 GFD 結果
+						if (chargingInfo[gun_index]->GroundFaultStatus == GFD_PASS)
+						{
+							setChargerMode(gun_index, MODE_CCS_PRECHARGE_STEP0);
+						}
+
+						if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
+						{
+							// GFD 錯誤停止
+							RecordAlarmCode("012235");
+						}
+					}
+
+					if (isEvBoardStopChargeFlag(gun_index) == YES ||
+							chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL ||
+							OcppRemoteStop(gun_index) == YES)
+					{
+						// 板端或後臺要求停止
+						ChargingTerminalProcess(gun_index);
+					}
+
+					// LCM => Pre-charging
+					if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
+						ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
+				}
+					break;
+				case S_CHARGING: // 剛進入充電狀態,等待 EV 小板要求的輸出電流後開始輸出
+				{
+					if (isModeChange(gun_index))
+					{
+						PRINTF_FUNC("S_CHARGING================================== %x \n", gun_index);
+						StopGunInfoTimeoutDet(gun_index);
+						ftime(&startChargingTime[gun_index]);
+						ChangeStartOrStopDateTime(YES, gun_index);
+						OcppStartTransation(gun_index);
+					}
+					ftime(&endChargingTime[gun_index]);
+					chargingInfo[gun_index]->RemainChargingDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index]);
+
+					if (chargingInfo[gun_index]->Type == _Type_Chademo)
+					{
+						if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
+						{
+							// GFD 錯誤停止
+							RecordAlarmCode("012234");
+						}
+					}
+					else if (chargingInfo[gun_index]->Type == _Type_CCS_2)
+					{
+						if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
+						{
+							// GFD 錯誤停止
+							RecordAlarmCode("012235");
+						}
+					}
+
+					if (isEvBoardStopChargeFlag(gun_index) ||
+							chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL ||
+							OcppRemoteStop(gun_index) ||
+							CheckBackendChargingTimeout(gun_index) ||
+							CheckBackendChargingEnergy(gun_index))
+					{
+						// 板端或後臺要求停止
+						ChargingTerminalProcess(gun_index);
+					}
+
+					// LCM => Charging
+					if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
+						ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_CHARGING;
+				}
+					break;
+				case S_TERMINATING:
+				{
+					if (isModeChange(gun_index))
+					{
+						PRINTF_FUNC ("terminating......................... %x \n", gun_index);
+						StopGunInfoTimeoutDet(gun_index);
+					}
+
+					if (chargingInfo[gun_index]->Type == _Type_Chademo)
+					{
+						// 非車端的停止 : 需等待小板送出停止指令,讓車端解除槍
+						if (isEvStopCharging_chademo(gun_index) == YES ||
+								isPrechargeStatus_chademo(gun_index) <= 0)
+						{
+							setChargerMode(gun_index, MODE_COMPLETE);
+						}
+					}
+					else if (chargingInfo[gun_index]->Type == _Type_CCS_2)
+					{
+						// 非車端的停止 : 需等待小板送出停止指令,讓車端解除槍
+						if (isEvStopCharging_ccs(gun_index) == YES)
+						{
+							setChargerMode(gun_index, MODE_COMPLETE);
+						}
+					}
+					if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
+						ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_COMPLETE;
+				}
+					break;
+				case S_COMPLETE:
+				{
+					if (isModeChange(gun_index))
+					{
+						PRINTF_FUNC ("complete......................... %x \n", gun_index);
+						OcppStopTransation(gun_index);
+						ftime(&endChargingTime[gun_index]);
+						if (chargingInfo[gun_index]->RemainChargingDuration != 0)
+							chargingInfo[gun_index]->RemainChargingDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index]);
+
+						//strcpy((char *)chargingInfo[gun_index]->CardNumber, "");
+						//strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+						StopGunInfoTimeoutDet(gun_index);
+						ChangeStartOrStopDateTime(NO, gun_index);
+						// 單槍或者雙槍單充自動回 idle
+						if (_gunCount == 1 || (_gunCount > 1 && ONE_CONNECTOR_USE == YES))
+							StartGunInfoTimeoutDet(gun_index, Timeout_WaitforCompleteDet);
+					}
+
+					if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
+						ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_COMPLETE;
+				}
+					break;
+				case S_CCS_PRECHARGE_ST0:
+				{
+					if (isModeChange(gun_index))
+					{
+						PRINTF_FUNC("CCS Precharge Processing 1....................%x \n", gun_index);
+						StopGunInfoTimeoutDet(gun_index);
+						StartGunInfoTimeoutDet(gun_index, Timeout_ForCcsPrechargeDet);
+					}
+
+					if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
+					{
+						// GFD 錯誤停止
+						RecordAlarmCode("012235");
+					}
+
+					if (isEvBoardStopChargeFlag(gun_index) == YES ||
+							chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
+					{
+						// 板端要求停止
+						ChargingTerminalProcess(gun_index);
+					}
+
+					// 等待 EV 小板 (CCS) 通知可以開始 Precharge
+					// 切換 D+ Relay to Precharge Relay
+					if (isPrechargeStatus_ccs(gun_index) == 39 || isPrechargeStatus_ccs(gun_index) == 40)
+					{
+						if (chargingInfo[gun_index]->RelayKPK2Status == YES && chargingInfo[gun_index]->PrechargeStatus != PRECHARGE_READY)
+						//if (chargingInfo[gun_index]->PrechargeStatus != PRECHARGE_PRERELAY_PASS)
+						{
+							PRINTF_FUNC("Send precharge ready 1..........%x, status = %d \n", gun_index, isPrechargeStatus_ccs(gun_index));
+							chargingInfo[gun_index]->PrechargeStatus = PRECHARGE_READY;
+						}
+					}
+					else if (isPrechargeStatus_ccs(gun_index) == 45 || isPrechargeStatus_ccs(gun_index) == 46)
+					{
+						setChargerMode(gun_index, MODE_CCS_PRECHARGE_STEP1);
+					}
+
+					break;
+				}
+				case S_CCS_PRECHARGE_ST1:
+				{
+					if (isModeChange(gun_index))
+					{
+						PRINTF_FUNC("CCS Precharge Processing 2....................%x \n", gun_index);
+					}
+
+					if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
+					{
+						// GFD 錯誤停止
+						RecordAlarmCode("012235");
+					}
+
+					if (isEvBoardStopChargeFlag(gun_index) == YES ||
+							chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
+					{
+						// 板端要求停止
+						ChargingTerminalProcess(gun_index);
+					}
+
+					// 等待小板通知進入充電
+					// 切換 D+ Relay to Precharge Relay
+					if (chargingInfo[gun_index]->RelayK1K2Status == YES)
+					{
+						chargingInfo[gun_index]->PrechargeStatus = PRECHARGE_READY;
+						setChargerMode(gun_index, MODE_CHARGING);
+					}
+					break;
+				}
+			}
+		}
+
+		if (ShmSysConfigAndInfo->SysInfo.SystemPage != _LCM_NONE)
+		{
+			ChangeLcmByIndex(ShmSysConfigAndInfo->SysInfo.SystemPage);
+		}
+		else
+		{
+			ChangeLcmByIndex(ShmSysConfigAndInfo->SysInfo.ConnectorPage);
+		}
+
+		write(wtdFd, "a", 1);
+		usleep(whileLoopTime);
+	}
+
+	return FAIL;
+}

+ 5 - 0
EVSE/Projects/PlugIt360/Apps/timeout.c

@@ -0,0 +1,5 @@
+#include "timeout.h"
+
+//===============================================
+// Initial Callback function
+//===============================================

+ 53 - 0
EVSE/Projects/PlugIt360/Apps/timeout.h

@@ -0,0 +1,53 @@
+#ifndef TIMEOUT_H_
+#define TIMEOUT_H_
+
+#include 	<sys/time.h>
+#include 	<sys/timeb.h>
+#include    <sys/types.h>
+#include    <sys/stat.h>
+#include 	<sys/types.h>
+#include 	<sys/ioctl.h>
+#include 	<sys/socket.h>
+#include 	<sys/ipc.h>
+#include 	<sys/shm.h>
+#include 	<sys/shm.h>
+#include 	<sys/mman.h>
+#include 	<linux/wireless.h>
+#include 	<linux/can.h>
+#include 	<linux/can/raw.h>
+#include 	<arpa/inet.h>
+#include 	<netinet/in.h>
+
+#include 	<unistd.h>
+#include 	<stdarg.h>
+#include    <stdio.h>
+#include    <stdlib.h>
+#include    <unistd.h>
+#include    <fcntl.h>
+#include    <termios.h>
+#include    <errno.h>
+#include 	<errno.h>
+#include 	<string.h>
+#include	<time.h>
+#include	<ctype.h>
+#include 	<ifaddrs.h>
+
+enum Timeout_flag
+{
+	Timeout_None =						0,
+	Timeout_SelftestChk = 				1,
+	Timeout_Authorizing = 				2,
+	Timeout_VerifyFail = 				3,
+	Timeout_VerifyComp = 				4,
+	Timeout_WaitPlug = 					5,
+
+	Timeout_Preparing = 				6,
+	Timeout_EvChargingDet = 			7,
+	Timeout_EvseChargingDet = 			8,
+	Timeout_WaitforCompleteDet = 		9,
+
+	Timeout_ForCcsPrechargeDet = 		10,
+	Timeout_ReturnToChargingGunDet = 	11
+};
+
+#endif /* TIMEOUT_H_ */

BIN
EVSE/Projects/PlugIt360/Images/MLO


BIN
EVSE/Projects/PlugIt360/Images/am335x-evm.dtb


BIN
EVSE/Projects/PlugIt360/Images/ramdisk.gz


BIN
EVSE/Projects/PlugIt360/Images/u-boot.img


BIN
EVSE/Projects/PlugIt360/Images/zImage


+ 8 - 0
EVSE/Projects/define.h

@@ -84,6 +84,14 @@ Storage							0x0A200000-0x7FFFFFFF		1886 MB
 	#define AC_QUANTITY             0
 	#define PSU_QUANTITY            2
 	#define ONE_CONNECTOR_USE       0
+#elif PlugIt360
+        #define MAX_PSU_QUANTITY        62
+        #define CHAdeMO_QUANTITY        0
+        #define CCS_QUANTITY            1
+        #define GB_QUANTITY             0
+        #define AC_QUANTITY             0
+        #define PSU_QUANTITY            2
+        #define ONE_CONNECTOR_USE       0
 #else
 	#define MAX_PSU_QUANTITY        62
 	#define CHAdeMO_QUANTITY        1

+ 73 - 0
Makefile

@@ -1167,3 +1167,76 @@ Noodoe-rootfs:
 
 Noodoe-all: Noodoe-uboot Noodoe-linux Noodoe-rootfs
 
+
+PlugIt360-uboot-default: u-boot_clean u-boot
+	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/MLO EVSE/Projects/PlugIt360/Images/
+	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/u-boot.img EVSE/Projects/PlugIt360/Images/
+
+PlugIt360-uboot-menuconfig:
+	@echo ===================================
+	@echo    Building U-boot menuconfig
+	@echo ===================================
+	$(MAKE) -j $(MAKE_JOBS) -C $(TI_SDK_PATH)/board-support/u-boot-* CROSS_COMPILE=$(CROSS_COMPILE) menuconfig
+
+PlugIt360-uboot:
+	@echo ===================================
+	@echo    Building U-boot
+	@echo ===================================
+	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[PlugIt360]am335x-evm.dts board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/am335x-evm.dts
+	$(MAKE) -j $(MAKE_JOBS) -C $(TI_SDK_PATH)/board-support/u-boot-* CROSS_COMPILE=$(CROSS_COMPILE)
+	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/MLO EVSE/Projects/PlugIt360/Images/
+	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/u-boot.img EVSE/Projects/PlugIt360/Images/
+	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/spl/u-boot-spl.bin EVSE/Projects/PlugIt360/Images/
+
+PlugIt360-linux-default: linux_clean linux
+	@cp -f board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/arch/arm/boot/zImage EVSE/Projects/PlugIt360/Images/
+	@cp -f board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/arch/arm/boot/dts/am335x-evm.dtb EVSE/Projects/PlugIt360/Images/
+
+PlugIt360-linux:
+	@echo =====================================
+	@echo     Building the Linux Kernel DTBs
+	@echo =====================================
+	@rm -f board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/arch/arm/boot/dts/am335x-evm.dtb
+	@cp -f board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/arch/arm/boot/dts/[PlugIt360]am335x-evm.dts board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/arch/arm/boot/dts/am335x-evm.dts
+	$(MAKE) -j $(MAKE_JOBS) -C $(LINUXKERNEL_INSTALL_DIR) ARCH=arm CROSS_COMPILE=$(CROSS_COMPILE) am335x-evm.dtb
+	@echo =================================
+	@echo     Building User Linux Kernel
+	@echo =================================
+	@rm -f board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/arch/arm/boot/zImage
+	$(MAKE) -j $(MAKE_JOBS) -C $(LINUXKERNEL_INSTALL_DIR) ARCH=arm CROSS_COMPILE=$(CROSS_COMPILE) zImage
+	$(MAKE) -j $(MAKE_JOBS) -C $(LINUXKERNEL_INSTALL_DIR) ARCH=arm CROSS_COMPILE=$(CROSS_COMPILE) modules
+	@cp -f board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/arch/arm/boot/zImage EVSE/Projects/PlugIt360/Images/
+	@cp -f board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/arch/arm/boot/dts/am335x-evm.dtb EVSE/Projects/PlugIt360/Images/
+	@cp -f board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/drivers/net/ethernet/qualcomm/qcaspi.ko EVSE/rootfs/lib/
+
+PlugIt360-rootfs:
+	@echo =================================
+	@echo     Building User rootfs
+	@echo =================================
+#	@cd EVSE/GPL;make Project=PlugIt360 all
+	@cd EVSE/Modularization;make Project=PlugIt360 all
+	@cd EVSE/Projects/PlugIt360/Apps;make Project=PlugIt360 all
+	@rm -f EVSE/Projects/PlugIt360/Images/ramdisk.gz
+	@dd if=/dev/zero of=/dev/ram0 bs=1k count=131072
+	@mke2fs -vm0 /dev/ram0 131072
+	@tune2fs -c 0 /dev/ram0
+	@dd if=/dev/ram0 bs=1k count=131072 | gzip -v9 > EVSE/Projects/PlugIt360/Images/ramdisk.gz
+	@mkdir -p EVSE/Projects/PlugIt360/Images/mnt
+	@gunzip EVSE/Projects/PlugIt360/Images/ramdisk.gz
+	@sync
+	@mount -o loop EVSE/Projects/PlugIt360/Images/ramdisk EVSE/Projects/PlugIt360/Images/mnt
+	@cp -rfv EVSE/rootfs/* EVSE/Projects/PlugIt360/Images/mnt/
+	@chown www-data:www-data EVSE/Projects/PlugIt360/Images/mnt/var/www -R
+	@chmod 777 EVSE/Projects/PlugIt360/Images/mnt/var/log -R
+	@chmod 777 EVSE/Projects/PlugIt360/Images/mnt/var/run -R
+	@cp -rfv EVSE/Projects/PlugIt360/Images/root/* EVSE/Projects/PlugIt360/Images/mnt/root
+	@sync
+	@sleep 3
+	@umount EVSE/Projects/PlugIt360/Images/mnt
+	@sync
+	@gzip -v9 EVSE/Projects/PlugIt360/Images/ramdisk
+	@rm -rfv EVSE/Projects/PlugIt360/Images/root
+	@rm -rfv EVSE/Projects/PlugIt360/Images/mnt
+
+PlugIt360-all: PlugIt360-uboot PlugIt360-linux PlugIt360-rootfs
+

+ 295 - 295
board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/.tmp_System.map

@@ -34573,301 +34573,301 @@ c0a00000 A __start_rodata_section_aligned
 c0a00000 R _etext
 c0a00010 R linux_proc_banner
 c0a0006c R linux_banner
-c0a00100 r __func__.5825
-c0a00110 r sqrt_oddadjust
-c0a00130 r sqrt_evenadjust
-c0a00150 r __func__.5807
-c0a00160 r cc_map
-c0a00180 r isa_modes
-c0a00190 r processor_modes
-c0a00210 r sigpage_mapping
-c0a00220 r regoffset_table
-c0a002b8 r user_arm_view
-c0a002cc r arm_regsets
-c0a00338 r hwcap_str
-c0a00394 r hwcap2_str
-c0a003ac r proc_arch
-c0a003f0 R cpuinfo_op
-c0a00400 R sigreturn_codes
-c0a0041c r handler
-c0a00430 r atags_fops
-c0a004a8 r pmresrn_table.31150
-c0a004b8 r pmresrn_table.31002
-c0a004c4 r scorpion_perf_cache_map
-c0a0056c r scorpion_perf_map
-c0a00594 r krait_perf_cache_map
-c0a0063c r krait_perf_map
-c0a00664 r krait_perf_map_no_branch
-c0a0068c r armv7_a5_perf_cache_map
-c0a00734 r armv7_a5_perf_map
-c0a0075c r armv7_a7_perf_cache_map
-c0a00804 r armv7_a7_perf_map
-c0a0082c r armv7_a8_perf_cache_map
-c0a008d4 r armv7_a8_perf_map
-c0a008fc r armv7_a9_perf_cache_map
-c0a009a4 r armv7_a9_perf_map
-c0a009cc r armv7_a12_perf_cache_map
-c0a00a74 r armv7_a12_perf_map
-c0a00a9c r armv7_a15_perf_cache_map
-c0a00b44 r armv7_a15_perf_map
-c0a00b6c r armv7_pmu_probe_table
-c0a00b90 r armv7_pmu_of_device_ids
-c0a013fc r usermode_action
-c0a01414 r alignment_proc_fops
-c0a0148c r subset.21772
-c0a014ac r subset.21782
-c0a014bc r __param_str_alignment
-c0a014c8 r cpu_arch_name
-c0a014ce r cpu_elf_name
-c0a014d4 r l2c220_data
-c0a0151c r omap_types
-c0a01530 r __func__.28508
-c0a01548 r __func__.29284
-c0a01568 r __func__.29289
-c0a01588 r am33xx_control_reg_offsets
-c0a01648 r am43xx_control_reg_offsets
-c0a01724 r omap_scrm_dt_match_table
-c0a01ecc r omap2_ctrl_data
-c0a01ed4 r omap_mux_dbg_signal_fops
-c0a01f4c r omap_mux_dbg_board_fops
-c0a01fc4 r __func__.28699
-c0a01fd8 r __func__.28741
-c0a01ff0 r __func__.28758
-c0a02008 r __func__.28788
-c0a0201c r __func__.29075
-c0a02030 r __func__.29089
-c0a02044 r __func__.29126
-c0a02054 r __func__.29002
-c0a0206c r __func__.29015
-c0a02088 r __func__.29102
-c0a0209c r __func__.30036
-c0a020bc r __func__.30084
-c0a020d0 r __func__.30078
-c0a020e0 r __func__.36712
-c0a020f4 r omap_pm_ops
-c0a0211c r reg_map
-c0a021f0 r __func__.31257
-c0a0220c r __func__.27253
-c0a02224 r __func__.27271
-c0a0223c r __func__.28011
-c0a0224c r name
-c0a02258 r __func__.27252
-c0a0226c r __func__.36709
-c0a0227c r modck.36708
-c0a02284 r __func__.37246
-c0a022a0 r __func__.28074
-c0a022b8 r __func__.28070
-c0a022d4 r __func__.28103
-c0a022e8 r __func__.28109
-c0a022fc r __func__.28161
-c0a02314 r __func__.28135
-c0a02334 r __func__.25577
-c0a02348 r __func__.23975
-c0a02368 r __func__.23985
-c0a02384 r __func__.30938
-c0a02394 r debug_fops
-c0a0240c r pm_dbg_option_fops
-c0a02484 r pwrdm_suspend_fops
-c0a024fc r pwrdm_state_names
-c0a0250c r __func__.30154
-c0a02524 r __func__.30166
-c0a02544 r __func__.30177
-c0a02568 r __func__.30189
-c0a02584 r __func__.30203
-c0a025a0 r __func__.30215
-c0a025c0 r __func__.30227
-c0a025d8 r __func__.30239
-c0a025f0 r __func__.30248
-c0a0260c r __func__.30257
-c0a02628 r __func__.19941
-c0a0263c r __func__.19953
-c0a02658 r __func__.19965
-c0a02674 r __func__.19977
-c0a0268c r __func__.19988
-c0a026a4 r __func__.28041
-c0a026b8 r __func__.28049
-c0a026c8 r __func__.28057
-c0a026d8 r __func__.28062
-c0a026f4 r __func__.28068
-c0a02710 r __func__.28076
-c0a0272c r __func__.28081
-c0a02744 r __func__.14518
-c0a02758 r __func__.14345
-c0a0276c r __func__.14379
-c0a02784 r __func__.14532
-c0a0279c r __func__.14512
-c0a027b0 r __func__.27364
-c0a027c0 r __func__.27389
-c0a027dc r __func__.27402
-c0a027ec r __func__.27409
-c0a027fc r __func__.34357
-c0a02814 r __func__.34364
-c0a02834 r __func__.27872
-c0a02848 r __func__.29301
-c0a02858 r __func__.36945
-c0a0286c r __func__.36957
-c0a0287c r __func__.36800
-c0a02890 r __func__.26969
-c0a028a8 r __func__.26938
-c0a028c0 r __func__.26928
-c0a028d4 r omap_timer_match
-c0a02ef4 r __func__.27014
-c0a02f08 r __func__.26797
-c0a02f20 r __func__.26943
-c0a02f3c r __func__.26966
-c0a02f58 r __func__.26977
-c0a02f74 r CSWTCH.92
-c0a02f80 r __func__.26836
-c0a02f9c r __func__.26648
-c0a02fb8 r __func__.26712
-c0a02fd8 r omap3plus_pdata
-c0a02fe8 r execdomains_proc_fops
-c0a03060 r tnts
-c0a03090 r __param_str_crash_kexec_post_notifiers
-c0a030ac r __param_str_panic_on_warn
-c0a030bc r __param_str_pause_on_oops
-c0a030cc r __param_str_panic
-c0a030d4 R cpu_all_bits
-c0a030d8 R cpu_bit_bitmap
-c0a0315c R softirq_to_name
-c0a03184 r resource_op
-c0a03194 r proc_ioports_operations
-c0a0320c r proc_iomem_operations
-c0a03284 r proc_wspace_sep
-c0a03290 r cap_last_cap
-c0a03294 r __func__.47089
-c0a032b0 R __cap_empty_set
-c0a032b8 r __func__.40750
-c0a032d0 r offsets.39360
-c0a032dc r wq_sysfs_group
-c0a032f0 r __param_str_debug_force_rr_cpu
-c0a03310 r __param_str_power_efficient
-c0a0332c r __param_str_disable_numa
-c0a03344 r module_uevent_ops
-c0a03350 r module_sysfs_ops
-c0a03358 R param_ops_string
-c0a03368 R param_array_ops
-c0a03378 R param_ops_bint
-c0a03388 R param_ops_invbool
-c0a03398 R param_ops_bool_enable_only
-c0a033a8 R param_ops_bool
-c0a033b8 R param_ops_charp
-c0a033c8 R param_ops_ullong
-c0a033d8 R param_ops_ulong
-c0a033e8 R param_ops_long
-c0a033f8 R param_ops_uint
-c0a03408 R param_ops_int
-c0a03418 R param_ops_ushort
-c0a03428 R param_ops_short
-c0a03438 R param_ops_byte
-c0a03448 r param.26429
-c0a0344c r reboot_cmd
-c0a0345c r __func__.5705
-c0a03470 R sched_prio_to_weight
-c0a03510 R sched_prio_to_wmult
-c0a035b0 r stat_nam
-c0a035c0 R min_cfs_quota_period
-c0a035c8 R max_cfs_quota_period
-c0a035d0 R idle_sched_class
-c0a03618 R fair_sched_class
-c0a03660 R rt_sched_class
-c0a036a8 R dl_sched_class
-c0a036f0 R stop_sched_class
-c0a03738 r schedstat_sops
-c0a03748 r proc_schedstat_operations
-c0a037c0 r sched_feat_fops
-c0a03838 r sched_feat_names
-c0a03878 r sched_debug_sops
-c0a03888 r sched_debug_fops
-c0a03900 r sched_tunable_scaling_names
-c0a0390c r pm_qos_array
-c0a03920 r pm_qos_power_fops
-c0a03998 r pm_qos_debug_fops
-c0a03a10 r CSWTCH.162
-c0a03a1c r __func__.31252
-c0a03a38 r __func__.31395
-c0a03a58 r suspend_stats_operations
-c0a03ad0 r CSWTCH.48
-c0a03af0 r pm_tests
-c0a03b08 r __param_str_pm_test_delay
-c0a03b20 r trunc_msg
-c0a03b2c r recursion_msg.36570
-c0a03b4c r __param_str_always_kmsg_dump
-c0a03b64 r __param_str_console_suspend
-c0a03b7c r __param_str_time
-c0a03b88 r __param_str_ignore_loglevel
-c0a03ba0 R kmsg_fops
-c0a03c18 r __param_str_irqfixup
-c0a03c2c r __param_str_noirqdebug
-c0a03c40 r __func__.26206
-c0a03c54 R irq_domain_simple_ops
-c0a03c7c r irq_spurious_proc_fops
-c0a03cf4 r msi_domain_ops
-c0a03d1c r __param_str_rcu_cpu_stall_timeout
-c0a03d3c r __param_str_rcu_cpu_stall_suppress
-c0a03d5c r __param_str_rcu_normal_after_boot
-c0a03d7c r __param_str_rcu_normal
-c0a03d90 r __param_str_rcu_expedited
-c0a03da8 r gp_ops
-c0a03dcc r CSWTCH.367
-c0a03dd8 r gp_state_names
-c0a03df4 r __param_str_jiffies_till_sched_qs
-c0a03e14 r __param_str_rcu_kick_kthreads
-c0a03e30 r __param_str_jiffies_till_next_fqs
-c0a03e50 r __param_str_jiffies_till_first_fqs
-c0a03e70 r __param_str_qlowmark
-c0a03e84 r __param_str_qhimark
-c0a03e94 r __param_str_blimit
-c0a03ea4 r __param_str_kthread_prio
-c0a03ebc r __param_str_rcu_fanout_leaf
-c0a03ed4 r __param_str_rcu_fanout_exact
-c0a03ef0 r __param_str_dump_tree
-c0a03f04 r hrtimer_clock_to_base_table
-c0a03f6c r offsets
-c0a03f78 r timer_list_sops
-c0a03f88 r timer_list_fops
-c0a04000 r __mon_yday
-c0a04034 r posix_clock_file_operations
-c0a040ac r alarmtimer_pm_ops
-c0a04108 r __param_str_irqtime
-c0a04110 r tk_debug_sleep_time_fops
-c0a04188 r modules_op
-c0a04198 r proc_modules_operations
-c0a04210 r arr.33985
-c0a0424c r __func__.35164
-c0a0425c r vermagic
-c0a0429c r masks.34837
-c0a042c4 r modinfo_attrs
-c0a042e8 r __param_str_module_blacklist
-c0a042fc r __param_str_nomodule
-c0a04308 r __param_str_sig_enforce
-c0a0431c r kallsyms_op
-c0a0432c r kallsyms_operations
-c0a043a4 r __func__.53625
-c0a043b8 r cgroup_subsys
-c0a043d8 r cgroup_subsys_enabled_key
-c0a043f8 r cgroup_subsys_on_dfl_key
-c0a04418 r cgroup_subsys_name
-c0a04438 r proc_cgroupstats_operations
-c0a044b0 R cgroupns_operations
-c0a044cc R utsns_operations
-c0a044e8 R pidns_operations
-c0a04504 r kernel_config_data
-c0a0bb80 r ikconfig_file_ops
-c0a0bbf8 r mode1_syscalls
-c0a0bc0c r jumptable.45554
-c0a0c00c r __func__.45734
-c0a0c01c R bpf_tail_call_proto
-c0a0c03c r __func__.50754
-c0a0c050 r perf_mmap_vmops
-c0a0c07c r perf_fops
-c0a0c0f4 r if_tokens
-c0a0c134 r pmu_dev_group
-c0a0c148 r __func__.24217
-c0a0c164 r __func__.24230
-c0a0c17c r __func__.24138
-c0a0c190 r __func__.24193
-c0a0c1a4 r __func__.24205
+c0a00104 r __func__.5825
+c0a00114 r sqrt_oddadjust
+c0a00134 r sqrt_evenadjust
+c0a00154 r __func__.5807
+c0a00164 r cc_map
+c0a00184 r isa_modes
+c0a00194 r processor_modes
+c0a00214 r sigpage_mapping
+c0a00224 r regoffset_table
+c0a002bc r user_arm_view
+c0a002d0 r arm_regsets
+c0a0033c r hwcap_str
+c0a00398 r hwcap2_str
+c0a003b0 r proc_arch
+c0a003f4 R cpuinfo_op
+c0a00404 R sigreturn_codes
+c0a00420 r handler
+c0a00434 r atags_fops
+c0a004ac r pmresrn_table.31150
+c0a004bc r pmresrn_table.31002
+c0a004c8 r scorpion_perf_cache_map
+c0a00570 r scorpion_perf_map
+c0a00598 r krait_perf_cache_map
+c0a00640 r krait_perf_map
+c0a00668 r krait_perf_map_no_branch
+c0a00690 r armv7_a5_perf_cache_map
+c0a00738 r armv7_a5_perf_map
+c0a00760 r armv7_a7_perf_cache_map
+c0a00808 r armv7_a7_perf_map
+c0a00830 r armv7_a8_perf_cache_map
+c0a008d8 r armv7_a8_perf_map
+c0a00900 r armv7_a9_perf_cache_map
+c0a009a8 r armv7_a9_perf_map
+c0a009d0 r armv7_a12_perf_cache_map
+c0a00a78 r armv7_a12_perf_map
+c0a00aa0 r armv7_a15_perf_cache_map
+c0a00b48 r armv7_a15_perf_map
+c0a00b70 r armv7_pmu_probe_table
+c0a00b94 r armv7_pmu_of_device_ids
+c0a01400 r usermode_action
+c0a01418 r alignment_proc_fops
+c0a01490 r subset.21772
+c0a014b0 r subset.21782
+c0a014c0 r __param_str_alignment
+c0a014cc r cpu_arch_name
+c0a014d2 r cpu_elf_name
+c0a014d8 r l2c220_data
+c0a01520 r omap_types
+c0a01534 r __func__.28508
+c0a0154c r __func__.29284
+c0a0156c r __func__.29289
+c0a0158c r am33xx_control_reg_offsets
+c0a0164c r am43xx_control_reg_offsets
+c0a01728 r omap_scrm_dt_match_table
+c0a01ed0 r omap2_ctrl_data
+c0a01ed8 r omap_mux_dbg_signal_fops
+c0a01f50 r omap_mux_dbg_board_fops
+c0a01fc8 r __func__.28699
+c0a01fdc r __func__.28741
+c0a01ff4 r __func__.28758
+c0a0200c r __func__.28788
+c0a02020 r __func__.29075
+c0a02034 r __func__.29089
+c0a02048 r __func__.29126
+c0a02058 r __func__.29002
+c0a02070 r __func__.29015
+c0a0208c r __func__.29102
+c0a020a0 r __func__.30036
+c0a020c0 r __func__.30084
+c0a020d4 r __func__.30078
+c0a020e4 r __func__.36712
+c0a020f8 r omap_pm_ops
+c0a02120 r reg_map
+c0a021f4 r __func__.31257
+c0a02210 r __func__.27253
+c0a02228 r __func__.27271
+c0a02240 r __func__.28011
+c0a02250 r name
+c0a0225c r __func__.27252
+c0a02270 r __func__.36709
+c0a02280 r modck.36708
+c0a02288 r __func__.37246
+c0a022a4 r __func__.28074
+c0a022bc r __func__.28070
+c0a022d8 r __func__.28103
+c0a022ec r __func__.28109
+c0a02300 r __func__.28161
+c0a02318 r __func__.28135
+c0a02338 r __func__.25577
+c0a0234c r __func__.23975
+c0a0236c r __func__.23985
+c0a02388 r __func__.30938
+c0a02398 r debug_fops
+c0a02410 r pm_dbg_option_fops
+c0a02488 r pwrdm_suspend_fops
+c0a02500 r pwrdm_state_names
+c0a02510 r __func__.30154
+c0a02528 r __func__.30166
+c0a02548 r __func__.30177
+c0a0256c r __func__.30189
+c0a02588 r __func__.30203
+c0a025a4 r __func__.30215
+c0a025c4 r __func__.30227
+c0a025dc r __func__.30239
+c0a025f4 r __func__.30248
+c0a02610 r __func__.30257
+c0a0262c r __func__.19941
+c0a02640 r __func__.19953
+c0a0265c r __func__.19965
+c0a02678 r __func__.19977
+c0a02690 r __func__.19988
+c0a026a8 r __func__.28041
+c0a026bc r __func__.28049
+c0a026cc r __func__.28057
+c0a026dc r __func__.28062
+c0a026f8 r __func__.28068
+c0a02714 r __func__.28076
+c0a02730 r __func__.28081
+c0a02748 r __func__.14518
+c0a0275c r __func__.14345
+c0a02770 r __func__.14379
+c0a02788 r __func__.14532
+c0a027a0 r __func__.14512
+c0a027b4 r __func__.27364
+c0a027c4 r __func__.27389
+c0a027e0 r __func__.27402
+c0a027f0 r __func__.27409
+c0a02800 r __func__.34357
+c0a02818 r __func__.34364
+c0a02838 r __func__.27872
+c0a0284c r __func__.29301
+c0a0285c r __func__.36945
+c0a02870 r __func__.36957
+c0a02880 r __func__.36800
+c0a02894 r __func__.26969
+c0a028ac r __func__.26938
+c0a028c4 r __func__.26928
+c0a028d8 r omap_timer_match
+c0a02ef8 r __func__.27014
+c0a02f0c r __func__.26797
+c0a02f24 r __func__.26943
+c0a02f40 r __func__.26966
+c0a02f5c r __func__.26977
+c0a02f78 r CSWTCH.92
+c0a02f84 r __func__.26836
+c0a02fa0 r __func__.26648
+c0a02fbc r __func__.26712
+c0a02fdc r omap3plus_pdata
+c0a02ff0 r execdomains_proc_fops
+c0a03068 r tnts
+c0a03098 r __param_str_crash_kexec_post_notifiers
+c0a030b4 r __param_str_panic_on_warn
+c0a030c4 r __param_str_pause_on_oops
+c0a030d4 r __param_str_panic
+c0a030dc R cpu_all_bits
+c0a030e0 R cpu_bit_bitmap
+c0a03164 R softirq_to_name
+c0a0318c r resource_op
+c0a0319c r proc_ioports_operations
+c0a03214 r proc_iomem_operations
+c0a0328c r proc_wspace_sep
+c0a03298 r cap_last_cap
+c0a0329c r __func__.47089
+c0a032b8 R __cap_empty_set
+c0a032c0 r __func__.40750
+c0a032d8 r offsets.39360
+c0a032e4 r wq_sysfs_group
+c0a032f8 r __param_str_debug_force_rr_cpu
+c0a03318 r __param_str_power_efficient
+c0a03334 r __param_str_disable_numa
+c0a0334c r module_uevent_ops
+c0a03358 r module_sysfs_ops
+c0a03360 R param_ops_string
+c0a03370 R param_array_ops
+c0a03380 R param_ops_bint
+c0a03390 R param_ops_invbool
+c0a033a0 R param_ops_bool_enable_only
+c0a033b0 R param_ops_bool
+c0a033c0 R param_ops_charp
+c0a033d0 R param_ops_ullong
+c0a033e0 R param_ops_ulong
+c0a033f0 R param_ops_long
+c0a03400 R param_ops_uint
+c0a03410 R param_ops_int
+c0a03420 R param_ops_ushort
+c0a03430 R param_ops_short
+c0a03440 R param_ops_byte
+c0a03450 r param.26429
+c0a03454 r reboot_cmd
+c0a03464 r __func__.5705
+c0a03478 R sched_prio_to_weight
+c0a03518 R sched_prio_to_wmult
+c0a035b8 r stat_nam
+c0a035c8 R min_cfs_quota_period
+c0a035d0 R max_cfs_quota_period
+c0a035d8 R idle_sched_class
+c0a03620 R fair_sched_class
+c0a03668 R rt_sched_class
+c0a036b0 R dl_sched_class
+c0a036f8 R stop_sched_class
+c0a03740 r schedstat_sops
+c0a03750 r proc_schedstat_operations
+c0a037c8 r sched_feat_fops
+c0a03840 r sched_feat_names
+c0a03880 r sched_debug_sops
+c0a03890 r sched_debug_fops
+c0a03908 r sched_tunable_scaling_names
+c0a03914 r pm_qos_array
+c0a03928 r pm_qos_power_fops
+c0a039a0 r pm_qos_debug_fops
+c0a03a18 r CSWTCH.162
+c0a03a24 r __func__.31252
+c0a03a40 r __func__.31395
+c0a03a60 r suspend_stats_operations
+c0a03ad8 r CSWTCH.48
+c0a03af8 r pm_tests
+c0a03b10 r __param_str_pm_test_delay
+c0a03b28 r trunc_msg
+c0a03b34 r recursion_msg.36570
+c0a03b54 r __param_str_always_kmsg_dump
+c0a03b6c r __param_str_console_suspend
+c0a03b84 r __param_str_time
+c0a03b90 r __param_str_ignore_loglevel
+c0a03ba8 R kmsg_fops
+c0a03c20 r __param_str_irqfixup
+c0a03c34 r __param_str_noirqdebug
+c0a03c48 r __func__.26206
+c0a03c5c R irq_domain_simple_ops
+c0a03c84 r irq_spurious_proc_fops
+c0a03cfc r msi_domain_ops
+c0a03d24 r __param_str_rcu_cpu_stall_timeout
+c0a03d44 r __param_str_rcu_cpu_stall_suppress
+c0a03d64 r __param_str_rcu_normal_after_boot
+c0a03d84 r __param_str_rcu_normal
+c0a03d98 r __param_str_rcu_expedited
+c0a03db0 r gp_ops
+c0a03dd4 r CSWTCH.367
+c0a03de0 r gp_state_names
+c0a03dfc r __param_str_jiffies_till_sched_qs
+c0a03e1c r __param_str_rcu_kick_kthreads
+c0a03e38 r __param_str_jiffies_till_next_fqs
+c0a03e58 r __param_str_jiffies_till_first_fqs
+c0a03e78 r __param_str_qlowmark
+c0a03e8c r __param_str_qhimark
+c0a03e9c r __param_str_blimit
+c0a03eac r __param_str_kthread_prio
+c0a03ec4 r __param_str_rcu_fanout_leaf
+c0a03edc r __param_str_rcu_fanout_exact
+c0a03ef8 r __param_str_dump_tree
+c0a03f0c r hrtimer_clock_to_base_table
+c0a03f74 r offsets
+c0a03f80 r timer_list_sops
+c0a03f90 r timer_list_fops
+c0a04008 r __mon_yday
+c0a0403c r posix_clock_file_operations
+c0a040b4 r alarmtimer_pm_ops
+c0a04110 r __param_str_irqtime
+c0a04118 r tk_debug_sleep_time_fops
+c0a04190 r modules_op
+c0a041a0 r proc_modules_operations
+c0a04218 r arr.33985
+c0a04254 r __func__.35164
+c0a04264 r vermagic
+c0a042a4 r masks.34837
+c0a042cc r modinfo_attrs
+c0a042f0 r __param_str_module_blacklist
+c0a04304 r __param_str_nomodule
+c0a04310 r __param_str_sig_enforce
+c0a04324 r kallsyms_op
+c0a04334 r kallsyms_operations
+c0a043ac r __func__.53625
+c0a043c0 r cgroup_subsys
+c0a043e0 r cgroup_subsys_enabled_key
+c0a04400 r cgroup_subsys_on_dfl_key
+c0a04420 r cgroup_subsys_name
+c0a04440 r proc_cgroupstats_operations
+c0a044b8 R cgroupns_operations
+c0a044d4 R utsns_operations
+c0a044f0 R pidns_operations
+c0a0450c r kernel_config_data
+c0a0bb88 r ikconfig_file_ops
+c0a0bc00 r mode1_syscalls
+c0a0bc14 r jumptable.45554
+c0a0c014 r __func__.45734
+c0a0c024 R bpf_tail_call_proto
+c0a0c044 r __func__.50754
+c0a0c058 r perf_mmap_vmops
+c0a0c084 r perf_fops
+c0a0c0fc r if_tokens
+c0a0c13c r pmu_dev_group
+c0a0c150 r __func__.24217
+c0a0c16c r __func__.24230
+c0a0c184 r __func__.24138
+c0a0c198 r __func__.24193
+c0a0c1ac r __func__.24205
 c0a0c200 R generic_file_vm_ops
 c0a0c22c r __func__.32733
 c0a0c240 r fallbacks

+ 289 - 289
board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/.tmp_kallsyms1.S

@@ -34581,301 +34581,301 @@ kallsyms_offsets:
 	.long	0x9f8000
 	.long	0x9f8010
 	.long	0x9f806c
-	.long	0x9f8100
-	.long	0x9f8110
-	.long	0x9f8130
-	.long	0x9f8150
-	.long	0x9f8160
-	.long	0x9f8180
-	.long	0x9f8190
-	.long	0x9f8210
-	.long	0x9f8220
-	.long	0x9f82b8
-	.long	0x9f82cc
-	.long	0x9f8338
-	.long	0x9f8394
-	.long	0x9f83ac
-	.long	0x9f83f0
-	.long	0x9f8400
-	.long	0x9f841c
-	.long	0x9f8430
-	.long	0x9f84a8
-	.long	0x9f84b8
-	.long	0x9f84c4
-	.long	0x9f856c
-	.long	0x9f8594
-	.long	0x9f863c
-	.long	0x9f8664
-	.long	0x9f868c
-	.long	0x9f8734
-	.long	0x9f875c
-	.long	0x9f8804
-	.long	0x9f882c
-	.long	0x9f88d4
-	.long	0x9f88fc
-	.long	0x9f89a4
-	.long	0x9f89cc
-	.long	0x9f8a74
-	.long	0x9f8a9c
-	.long	0x9f8b44
-	.long	0x9f8b6c
-	.long	0x9f8b90
-	.long	0x9f93fc
-	.long	0x9f9414
-	.long	0x9f948c
-	.long	0x9f94ac
-	.long	0x9f94bc
-	.long	0x9f94c8
-	.long	0x9f94ce
-	.long	0x9f94d4
-	.long	0x9f951c
-	.long	0x9f9530
-	.long	0x9f9548
-	.long	0x9f9568
-	.long	0x9f9588
-	.long	0x9f9648
-	.long	0x9f9724
-	.long	0x9f9ecc
-	.long	0x9f9ed4
-	.long	0x9f9f4c
-	.long	0x9f9fc4
-	.long	0x9f9fd8
-	.long	0x9f9ff0
-	.long	0x9fa008
-	.long	0x9fa01c
-	.long	0x9fa030
-	.long	0x9fa044
-	.long	0x9fa054
-	.long	0x9fa06c
-	.long	0x9fa088
-	.long	0x9fa09c
-	.long	0x9fa0bc
-	.long	0x9fa0d0
-	.long	0x9fa0e0
-	.long	0x9fa0f4
-	.long	0x9fa11c
-	.long	0x9fa1f0
-	.long	0x9fa20c
-	.long	0x9fa224
-	.long	0x9fa23c
-	.long	0x9fa24c
-	.long	0x9fa258
-	.long	0x9fa26c
-	.long	0x9fa27c
-	.long	0x9fa284
-	.long	0x9fa2a0
-	.long	0x9fa2b8
-	.long	0x9fa2d4
-	.long	0x9fa2e8
-	.long	0x9fa2fc
-	.long	0x9fa314
-	.long	0x9fa334
-	.long	0x9fa348
-	.long	0x9fa368
-	.long	0x9fa384
-	.long	0x9fa394
-	.long	0x9fa40c
-	.long	0x9fa484
-	.long	0x9fa4fc
-	.long	0x9fa50c
-	.long	0x9fa524
-	.long	0x9fa544
-	.long	0x9fa568
-	.long	0x9fa584
-	.long	0x9fa5a0
-	.long	0x9fa5c0
-	.long	0x9fa5d8
-	.long	0x9fa5f0
-	.long	0x9fa60c
-	.long	0x9fa628
-	.long	0x9fa63c
-	.long	0x9fa658
-	.long	0x9fa674
-	.long	0x9fa68c
-	.long	0x9fa6a4
-	.long	0x9fa6b8
-	.long	0x9fa6c8
-	.long	0x9fa6d8
-	.long	0x9fa6f4
-	.long	0x9fa710
-	.long	0x9fa72c
-	.long	0x9fa744
-	.long	0x9fa758
-	.long	0x9fa76c
-	.long	0x9fa784
-	.long	0x9fa79c
-	.long	0x9fa7b0
-	.long	0x9fa7c0
-	.long	0x9fa7dc
-	.long	0x9fa7ec
-	.long	0x9fa7fc
-	.long	0x9fa814
-	.long	0x9fa834
-	.long	0x9fa848
-	.long	0x9fa858
-	.long	0x9fa86c
-	.long	0x9fa87c
-	.long	0x9fa890
-	.long	0x9fa8a8
-	.long	0x9fa8c0
-	.long	0x9fa8d4
-	.long	0x9faef4
-	.long	0x9faf08
-	.long	0x9faf20
-	.long	0x9faf3c
-	.long	0x9faf58
-	.long	0x9faf74
-	.long	0x9faf80
-	.long	0x9faf9c
-	.long	0x9fafb8
-	.long	0x9fafd8
-	.long	0x9fafe8
-	.long	0x9fb060
-	.long	0x9fb090
-	.long	0x9fb0ac
-	.long	0x9fb0bc
-	.long	0x9fb0cc
+	.long	0x9f8104
+	.long	0x9f8114
+	.long	0x9f8134
+	.long	0x9f8154
+	.long	0x9f8164
+	.long	0x9f8184
+	.long	0x9f8194
+	.long	0x9f8214
+	.long	0x9f8224
+	.long	0x9f82bc
+	.long	0x9f82d0
+	.long	0x9f833c
+	.long	0x9f8398
+	.long	0x9f83b0
+	.long	0x9f83f4
+	.long	0x9f8404
+	.long	0x9f8420
+	.long	0x9f8434
+	.long	0x9f84ac
+	.long	0x9f84bc
+	.long	0x9f84c8
+	.long	0x9f8570
+	.long	0x9f8598
+	.long	0x9f8640
+	.long	0x9f8668
+	.long	0x9f8690
+	.long	0x9f8738
+	.long	0x9f8760
+	.long	0x9f8808
+	.long	0x9f8830
+	.long	0x9f88d8
+	.long	0x9f8900
+	.long	0x9f89a8
+	.long	0x9f89d0
+	.long	0x9f8a78
+	.long	0x9f8aa0
+	.long	0x9f8b48
+	.long	0x9f8b70
+	.long	0x9f8b94
+	.long	0x9f9400
+	.long	0x9f9418
+	.long	0x9f9490
+	.long	0x9f94b0
+	.long	0x9f94c0
+	.long	0x9f94cc
+	.long	0x9f94d2
+	.long	0x9f94d8
+	.long	0x9f9520
+	.long	0x9f9534
+	.long	0x9f954c
+	.long	0x9f956c
+	.long	0x9f958c
+	.long	0x9f964c
+	.long	0x9f9728
+	.long	0x9f9ed0
+	.long	0x9f9ed8
+	.long	0x9f9f50
+	.long	0x9f9fc8
+	.long	0x9f9fdc
+	.long	0x9f9ff4
+	.long	0x9fa00c
+	.long	0x9fa020
+	.long	0x9fa034
+	.long	0x9fa048
+	.long	0x9fa058
+	.long	0x9fa070
+	.long	0x9fa08c
+	.long	0x9fa0a0
+	.long	0x9fa0c0
+	.long	0x9fa0d4
+	.long	0x9fa0e4
+	.long	0x9fa0f8
+	.long	0x9fa120
+	.long	0x9fa1f4
+	.long	0x9fa210
+	.long	0x9fa228
+	.long	0x9fa240
+	.long	0x9fa250
+	.long	0x9fa25c
+	.long	0x9fa270
+	.long	0x9fa280
+	.long	0x9fa288
+	.long	0x9fa2a4
+	.long	0x9fa2bc
+	.long	0x9fa2d8
+	.long	0x9fa2ec
+	.long	0x9fa300
+	.long	0x9fa318
+	.long	0x9fa338
+	.long	0x9fa34c
+	.long	0x9fa36c
+	.long	0x9fa388
+	.long	0x9fa398
+	.long	0x9fa410
+	.long	0x9fa488
+	.long	0x9fa500
+	.long	0x9fa510
+	.long	0x9fa528
+	.long	0x9fa548
+	.long	0x9fa56c
+	.long	0x9fa588
+	.long	0x9fa5a4
+	.long	0x9fa5c4
+	.long	0x9fa5dc
+	.long	0x9fa5f4
+	.long	0x9fa610
+	.long	0x9fa62c
+	.long	0x9fa640
+	.long	0x9fa65c
+	.long	0x9fa678
+	.long	0x9fa690
+	.long	0x9fa6a8
+	.long	0x9fa6bc
+	.long	0x9fa6cc
+	.long	0x9fa6dc
+	.long	0x9fa6f8
+	.long	0x9fa714
+	.long	0x9fa730
+	.long	0x9fa748
+	.long	0x9fa75c
+	.long	0x9fa770
+	.long	0x9fa788
+	.long	0x9fa7a0
+	.long	0x9fa7b4
+	.long	0x9fa7c4
+	.long	0x9fa7e0
+	.long	0x9fa7f0
+	.long	0x9fa800
+	.long	0x9fa818
+	.long	0x9fa838
+	.long	0x9fa84c
+	.long	0x9fa85c
+	.long	0x9fa870
+	.long	0x9fa880
+	.long	0x9fa894
+	.long	0x9fa8ac
+	.long	0x9fa8c4
+	.long	0x9fa8d8
+	.long	0x9faef8
+	.long	0x9faf0c
+	.long	0x9faf24
+	.long	0x9faf40
+	.long	0x9faf5c
+	.long	0x9faf78
+	.long	0x9faf84
+	.long	0x9fafa0
+	.long	0x9fafbc
+	.long	0x9fafdc
+	.long	0x9faff0
+	.long	0x9fb068
+	.long	0x9fb098
+	.long	0x9fb0b4
+	.long	0x9fb0c4
 	.long	0x9fb0d4
-	.long	0x9fb0d8
-	.long	0x9fb15c
-	.long	0x9fb184
-	.long	0x9fb194
-	.long	0x9fb20c
-	.long	0x9fb284
-	.long	0x9fb290
-	.long	0x9fb294
-	.long	0x9fb2b0
+	.long	0x9fb0dc
+	.long	0x9fb0e0
+	.long	0x9fb164
+	.long	0x9fb18c
+	.long	0x9fb19c
+	.long	0x9fb214
+	.long	0x9fb28c
+	.long	0x9fb298
+	.long	0x9fb29c
 	.long	0x9fb2b8
-	.long	0x9fb2d0
-	.long	0x9fb2dc
-	.long	0x9fb2f0
-	.long	0x9fb310
-	.long	0x9fb32c
-	.long	0x9fb344
-	.long	0x9fb350
+	.long	0x9fb2c0
+	.long	0x9fb2d8
+	.long	0x9fb2e4
+	.long	0x9fb2f8
+	.long	0x9fb318
+	.long	0x9fb334
+	.long	0x9fb34c
 	.long	0x9fb358
-	.long	0x9fb368
-	.long	0x9fb378
-	.long	0x9fb388
-	.long	0x9fb398
-	.long	0x9fb3a8
-	.long	0x9fb3b8
-	.long	0x9fb3c8
-	.long	0x9fb3d8
-	.long	0x9fb3e8
-	.long	0x9fb3f8
-	.long	0x9fb408
-	.long	0x9fb418
-	.long	0x9fb428
-	.long	0x9fb438
-	.long	0x9fb448
-	.long	0x9fb44c
-	.long	0x9fb45c
-	.long	0x9fb470
-	.long	0x9fb510
-	.long	0x9fb5b0
-	.long	0x9fb5c0
+	.long	0x9fb360
+	.long	0x9fb370
+	.long	0x9fb380
+	.long	0x9fb390
+	.long	0x9fb3a0
+	.long	0x9fb3b0
+	.long	0x9fb3c0
+	.long	0x9fb3d0
+	.long	0x9fb3e0
+	.long	0x9fb3f0
+	.long	0x9fb400
+	.long	0x9fb410
+	.long	0x9fb420
+	.long	0x9fb430
+	.long	0x9fb440
+	.long	0x9fb450
+	.long	0x9fb454
+	.long	0x9fb464
+	.long	0x9fb478
+	.long	0x9fb518
+	.long	0x9fb5b8
 	.long	0x9fb5c8
 	.long	0x9fb5d0
-	.long	0x9fb618
-	.long	0x9fb660
-	.long	0x9fb6a8
-	.long	0x9fb6f0
-	.long	0x9fb738
-	.long	0x9fb748
-	.long	0x9fb7c0
-	.long	0x9fb838
-	.long	0x9fb878
-	.long	0x9fb888
-	.long	0x9fb900
-	.long	0x9fb90c
-	.long	0x9fb920
-	.long	0x9fb998
-	.long	0x9fba10
-	.long	0x9fba1c
-	.long	0x9fba38
-	.long	0x9fba58
-	.long	0x9fbad0
-	.long	0x9fbaf0
-	.long	0x9fbb08
-	.long	0x9fbb20
-	.long	0x9fbb2c
-	.long	0x9fbb4c
-	.long	0x9fbb64
-	.long	0x9fbb7c
-	.long	0x9fbb88
-	.long	0x9fbba0
-	.long	0x9fbc18
-	.long	0x9fbc2c
-	.long	0x9fbc40
-	.long	0x9fbc54
-	.long	0x9fbc7c
-	.long	0x9fbcf4
-	.long	0x9fbd1c
-	.long	0x9fbd3c
-	.long	0x9fbd5c
-	.long	0x9fbd7c
-	.long	0x9fbd90
-	.long	0x9fbda8
-	.long	0x9fbdcc
-	.long	0x9fbdd8
-	.long	0x9fbdf4
-	.long	0x9fbe14
-	.long	0x9fbe30
-	.long	0x9fbe50
-	.long	0x9fbe70
-	.long	0x9fbe84
-	.long	0x9fbe94
-	.long	0x9fbea4
-	.long	0x9fbebc
-	.long	0x9fbed4
-	.long	0x9fbef0
-	.long	0x9fbf04
-	.long	0x9fbf6c
-	.long	0x9fbf78
-	.long	0x9fbf88
-	.long	0x9fc000
-	.long	0x9fc034
-	.long	0x9fc0ac
-	.long	0x9fc108
+	.long	0x9fb5d8
+	.long	0x9fb620
+	.long	0x9fb668
+	.long	0x9fb6b0
+	.long	0x9fb6f8
+	.long	0x9fb740
+	.long	0x9fb750
+	.long	0x9fb7c8
+	.long	0x9fb840
+	.long	0x9fb880
+	.long	0x9fb890
+	.long	0x9fb908
+	.long	0x9fb914
+	.long	0x9fb928
+	.long	0x9fb9a0
+	.long	0x9fba18
+	.long	0x9fba24
+	.long	0x9fba40
+	.long	0x9fba60
+	.long	0x9fbad8
+	.long	0x9fbaf8
+	.long	0x9fbb10
+	.long	0x9fbb28
+	.long	0x9fbb34
+	.long	0x9fbb54
+	.long	0x9fbb6c
+	.long	0x9fbb84
+	.long	0x9fbb90
+	.long	0x9fbba8
+	.long	0x9fbc20
+	.long	0x9fbc34
+	.long	0x9fbc48
+	.long	0x9fbc5c
+	.long	0x9fbc84
+	.long	0x9fbcfc
+	.long	0x9fbd24
+	.long	0x9fbd44
+	.long	0x9fbd64
+	.long	0x9fbd84
+	.long	0x9fbd98
+	.long	0x9fbdb0
+	.long	0x9fbdd4
+	.long	0x9fbde0
+	.long	0x9fbdfc
+	.long	0x9fbe1c
+	.long	0x9fbe38
+	.long	0x9fbe58
+	.long	0x9fbe78
+	.long	0x9fbe8c
+	.long	0x9fbe9c
+	.long	0x9fbeac
+	.long	0x9fbec4
+	.long	0x9fbedc
+	.long	0x9fbef8
+	.long	0x9fbf0c
+	.long	0x9fbf74
+	.long	0x9fbf80
+	.long	0x9fbf90
+	.long	0x9fc008
+	.long	0x9fc03c
+	.long	0x9fc0b4
 	.long	0x9fc110
-	.long	0x9fc188
-	.long	0x9fc198
-	.long	0x9fc210
-	.long	0x9fc24c
-	.long	0x9fc25c
-	.long	0x9fc29c
-	.long	0x9fc2c4
-	.long	0x9fc2e8
-	.long	0x9fc2fc
-	.long	0x9fc308
-	.long	0x9fc31c
-	.long	0x9fc32c
-	.long	0x9fc3a4
-	.long	0x9fc3b8
-	.long	0x9fc3d8
-	.long	0x9fc3f8
-	.long	0x9fc418
-	.long	0x9fc438
-	.long	0x9fc4b0
-	.long	0x9fc4cc
-	.long	0x9fc4e8
-	.long	0x9fc504
-	.long	0xa03b80
-	.long	0xa03bf8
-	.long	0xa03c0c
-	.long	0xa0400c
-	.long	0xa0401c
-	.long	0xa0403c
-	.long	0xa04050
-	.long	0xa0407c
-	.long	0xa040f4
-	.long	0xa04134
-	.long	0xa04148
-	.long	0xa04164
-	.long	0xa0417c
-	.long	0xa04190
-	.long	0xa041a4
+	.long	0x9fc118
+	.long	0x9fc190
+	.long	0x9fc1a0
+	.long	0x9fc218
+	.long	0x9fc254
+	.long	0x9fc264
+	.long	0x9fc2a4
+	.long	0x9fc2cc
+	.long	0x9fc2f0
+	.long	0x9fc304
+	.long	0x9fc310
+	.long	0x9fc324
+	.long	0x9fc334
+	.long	0x9fc3ac
+	.long	0x9fc3c0
+	.long	0x9fc3e0
+	.long	0x9fc400
+	.long	0x9fc420
+	.long	0x9fc440
+	.long	0x9fc4b8
+	.long	0x9fc4d4
+	.long	0x9fc4f0
+	.long	0x9fc50c
+	.long	0xa03b88
+	.long	0xa03c00
+	.long	0xa03c14
+	.long	0xa04014
+	.long	0xa04024
+	.long	0xa04044
+	.long	0xa04058
+	.long	0xa04084
+	.long	0xa040fc
+	.long	0xa0413c
+	.long	0xa04150
+	.long	0xa0416c
+	.long	0xa04184
+	.long	0xa04198
+	.long	0xa041ac
 	.long	0xa04200
 	.long	0xa0422c
 	.long	0xa04240

+ 289 - 289
board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/.tmp_kallsyms2.S

@@ -34581,301 +34581,301 @@ kallsyms_offsets:
 	.long	0x9f8000
 	.long	0x9f8010
 	.long	0x9f806c
-	.long	0x9f8100
-	.long	0x9f8110
-	.long	0x9f8130
-	.long	0x9f8150
-	.long	0x9f8160
-	.long	0x9f8180
-	.long	0x9f8190
-	.long	0x9f8210
-	.long	0x9f8220
-	.long	0x9f82b8
-	.long	0x9f82cc
-	.long	0x9f8338
-	.long	0x9f8394
-	.long	0x9f83ac
-	.long	0x9f83f0
-	.long	0x9f8400
-	.long	0x9f841c
-	.long	0x9f8430
-	.long	0x9f84a8
-	.long	0x9f84b8
-	.long	0x9f84c4
-	.long	0x9f856c
-	.long	0x9f8594
-	.long	0x9f863c
-	.long	0x9f8664
-	.long	0x9f868c
-	.long	0x9f8734
-	.long	0x9f875c
-	.long	0x9f8804
-	.long	0x9f882c
-	.long	0x9f88d4
-	.long	0x9f88fc
-	.long	0x9f89a4
-	.long	0x9f89cc
-	.long	0x9f8a74
-	.long	0x9f8a9c
-	.long	0x9f8b44
-	.long	0x9f8b6c
-	.long	0x9f8b90
-	.long	0x9f93fc
-	.long	0x9f9414
-	.long	0x9f948c
-	.long	0x9f94ac
-	.long	0x9f94bc
-	.long	0x9f94c8
-	.long	0x9f94ce
-	.long	0x9f94d4
-	.long	0x9f951c
-	.long	0x9f9530
-	.long	0x9f9548
-	.long	0x9f9568
-	.long	0x9f9588
-	.long	0x9f9648
-	.long	0x9f9724
-	.long	0x9f9ecc
-	.long	0x9f9ed4
-	.long	0x9f9f4c
-	.long	0x9f9fc4
-	.long	0x9f9fd8
-	.long	0x9f9ff0
-	.long	0x9fa008
-	.long	0x9fa01c
-	.long	0x9fa030
-	.long	0x9fa044
-	.long	0x9fa054
-	.long	0x9fa06c
-	.long	0x9fa088
-	.long	0x9fa09c
-	.long	0x9fa0bc
-	.long	0x9fa0d0
-	.long	0x9fa0e0
-	.long	0x9fa0f4
-	.long	0x9fa11c
-	.long	0x9fa1f0
-	.long	0x9fa20c
-	.long	0x9fa224
-	.long	0x9fa23c
-	.long	0x9fa24c
-	.long	0x9fa258
-	.long	0x9fa26c
-	.long	0x9fa27c
-	.long	0x9fa284
-	.long	0x9fa2a0
-	.long	0x9fa2b8
-	.long	0x9fa2d4
-	.long	0x9fa2e8
-	.long	0x9fa2fc
-	.long	0x9fa314
-	.long	0x9fa334
-	.long	0x9fa348
-	.long	0x9fa368
-	.long	0x9fa384
-	.long	0x9fa394
-	.long	0x9fa40c
-	.long	0x9fa484
-	.long	0x9fa4fc
-	.long	0x9fa50c
-	.long	0x9fa524
-	.long	0x9fa544
-	.long	0x9fa568
-	.long	0x9fa584
-	.long	0x9fa5a0
-	.long	0x9fa5c0
-	.long	0x9fa5d8
-	.long	0x9fa5f0
-	.long	0x9fa60c
-	.long	0x9fa628
-	.long	0x9fa63c
-	.long	0x9fa658
-	.long	0x9fa674
-	.long	0x9fa68c
-	.long	0x9fa6a4
-	.long	0x9fa6b8
-	.long	0x9fa6c8
-	.long	0x9fa6d8
-	.long	0x9fa6f4
-	.long	0x9fa710
-	.long	0x9fa72c
-	.long	0x9fa744
-	.long	0x9fa758
-	.long	0x9fa76c
-	.long	0x9fa784
-	.long	0x9fa79c
-	.long	0x9fa7b0
-	.long	0x9fa7c0
-	.long	0x9fa7dc
-	.long	0x9fa7ec
-	.long	0x9fa7fc
-	.long	0x9fa814
-	.long	0x9fa834
-	.long	0x9fa848
-	.long	0x9fa858
-	.long	0x9fa86c
-	.long	0x9fa87c
-	.long	0x9fa890
-	.long	0x9fa8a8
-	.long	0x9fa8c0
-	.long	0x9fa8d4
-	.long	0x9faef4
-	.long	0x9faf08
-	.long	0x9faf20
-	.long	0x9faf3c
-	.long	0x9faf58
-	.long	0x9faf74
-	.long	0x9faf80
-	.long	0x9faf9c
-	.long	0x9fafb8
-	.long	0x9fafd8
-	.long	0x9fafe8
-	.long	0x9fb060
-	.long	0x9fb090
-	.long	0x9fb0ac
-	.long	0x9fb0bc
-	.long	0x9fb0cc
+	.long	0x9f8104
+	.long	0x9f8114
+	.long	0x9f8134
+	.long	0x9f8154
+	.long	0x9f8164
+	.long	0x9f8184
+	.long	0x9f8194
+	.long	0x9f8214
+	.long	0x9f8224
+	.long	0x9f82bc
+	.long	0x9f82d0
+	.long	0x9f833c
+	.long	0x9f8398
+	.long	0x9f83b0
+	.long	0x9f83f4
+	.long	0x9f8404
+	.long	0x9f8420
+	.long	0x9f8434
+	.long	0x9f84ac
+	.long	0x9f84bc
+	.long	0x9f84c8
+	.long	0x9f8570
+	.long	0x9f8598
+	.long	0x9f8640
+	.long	0x9f8668
+	.long	0x9f8690
+	.long	0x9f8738
+	.long	0x9f8760
+	.long	0x9f8808
+	.long	0x9f8830
+	.long	0x9f88d8
+	.long	0x9f8900
+	.long	0x9f89a8
+	.long	0x9f89d0
+	.long	0x9f8a78
+	.long	0x9f8aa0
+	.long	0x9f8b48
+	.long	0x9f8b70
+	.long	0x9f8b94
+	.long	0x9f9400
+	.long	0x9f9418
+	.long	0x9f9490
+	.long	0x9f94b0
+	.long	0x9f94c0
+	.long	0x9f94cc
+	.long	0x9f94d2
+	.long	0x9f94d8
+	.long	0x9f9520
+	.long	0x9f9534
+	.long	0x9f954c
+	.long	0x9f956c
+	.long	0x9f958c
+	.long	0x9f964c
+	.long	0x9f9728
+	.long	0x9f9ed0
+	.long	0x9f9ed8
+	.long	0x9f9f50
+	.long	0x9f9fc8
+	.long	0x9f9fdc
+	.long	0x9f9ff4
+	.long	0x9fa00c
+	.long	0x9fa020
+	.long	0x9fa034
+	.long	0x9fa048
+	.long	0x9fa058
+	.long	0x9fa070
+	.long	0x9fa08c
+	.long	0x9fa0a0
+	.long	0x9fa0c0
+	.long	0x9fa0d4
+	.long	0x9fa0e4
+	.long	0x9fa0f8
+	.long	0x9fa120
+	.long	0x9fa1f4
+	.long	0x9fa210
+	.long	0x9fa228
+	.long	0x9fa240
+	.long	0x9fa250
+	.long	0x9fa25c
+	.long	0x9fa270
+	.long	0x9fa280
+	.long	0x9fa288
+	.long	0x9fa2a4
+	.long	0x9fa2bc
+	.long	0x9fa2d8
+	.long	0x9fa2ec
+	.long	0x9fa300
+	.long	0x9fa318
+	.long	0x9fa338
+	.long	0x9fa34c
+	.long	0x9fa36c
+	.long	0x9fa388
+	.long	0x9fa398
+	.long	0x9fa410
+	.long	0x9fa488
+	.long	0x9fa500
+	.long	0x9fa510
+	.long	0x9fa528
+	.long	0x9fa548
+	.long	0x9fa56c
+	.long	0x9fa588
+	.long	0x9fa5a4
+	.long	0x9fa5c4
+	.long	0x9fa5dc
+	.long	0x9fa5f4
+	.long	0x9fa610
+	.long	0x9fa62c
+	.long	0x9fa640
+	.long	0x9fa65c
+	.long	0x9fa678
+	.long	0x9fa690
+	.long	0x9fa6a8
+	.long	0x9fa6bc
+	.long	0x9fa6cc
+	.long	0x9fa6dc
+	.long	0x9fa6f8
+	.long	0x9fa714
+	.long	0x9fa730
+	.long	0x9fa748
+	.long	0x9fa75c
+	.long	0x9fa770
+	.long	0x9fa788
+	.long	0x9fa7a0
+	.long	0x9fa7b4
+	.long	0x9fa7c4
+	.long	0x9fa7e0
+	.long	0x9fa7f0
+	.long	0x9fa800
+	.long	0x9fa818
+	.long	0x9fa838
+	.long	0x9fa84c
+	.long	0x9fa85c
+	.long	0x9fa870
+	.long	0x9fa880
+	.long	0x9fa894
+	.long	0x9fa8ac
+	.long	0x9fa8c4
+	.long	0x9fa8d8
+	.long	0x9faef8
+	.long	0x9faf0c
+	.long	0x9faf24
+	.long	0x9faf40
+	.long	0x9faf5c
+	.long	0x9faf78
+	.long	0x9faf84
+	.long	0x9fafa0
+	.long	0x9fafbc
+	.long	0x9fafdc
+	.long	0x9faff0
+	.long	0x9fb068
+	.long	0x9fb098
+	.long	0x9fb0b4
+	.long	0x9fb0c4
 	.long	0x9fb0d4
-	.long	0x9fb0d8
-	.long	0x9fb15c
-	.long	0x9fb184
-	.long	0x9fb194
-	.long	0x9fb20c
-	.long	0x9fb284
-	.long	0x9fb290
-	.long	0x9fb294
-	.long	0x9fb2b0
+	.long	0x9fb0dc
+	.long	0x9fb0e0
+	.long	0x9fb164
+	.long	0x9fb18c
+	.long	0x9fb19c
+	.long	0x9fb214
+	.long	0x9fb28c
+	.long	0x9fb298
+	.long	0x9fb29c
 	.long	0x9fb2b8
-	.long	0x9fb2d0
-	.long	0x9fb2dc
-	.long	0x9fb2f0
-	.long	0x9fb310
-	.long	0x9fb32c
-	.long	0x9fb344
-	.long	0x9fb350
+	.long	0x9fb2c0
+	.long	0x9fb2d8
+	.long	0x9fb2e4
+	.long	0x9fb2f8
+	.long	0x9fb318
+	.long	0x9fb334
+	.long	0x9fb34c
 	.long	0x9fb358
-	.long	0x9fb368
-	.long	0x9fb378
-	.long	0x9fb388
-	.long	0x9fb398
-	.long	0x9fb3a8
-	.long	0x9fb3b8
-	.long	0x9fb3c8
-	.long	0x9fb3d8
-	.long	0x9fb3e8
-	.long	0x9fb3f8
-	.long	0x9fb408
-	.long	0x9fb418
-	.long	0x9fb428
-	.long	0x9fb438
-	.long	0x9fb448
-	.long	0x9fb44c
-	.long	0x9fb45c
-	.long	0x9fb470
-	.long	0x9fb510
-	.long	0x9fb5b0
-	.long	0x9fb5c0
+	.long	0x9fb360
+	.long	0x9fb370
+	.long	0x9fb380
+	.long	0x9fb390
+	.long	0x9fb3a0
+	.long	0x9fb3b0
+	.long	0x9fb3c0
+	.long	0x9fb3d0
+	.long	0x9fb3e0
+	.long	0x9fb3f0
+	.long	0x9fb400
+	.long	0x9fb410
+	.long	0x9fb420
+	.long	0x9fb430
+	.long	0x9fb440
+	.long	0x9fb450
+	.long	0x9fb454
+	.long	0x9fb464
+	.long	0x9fb478
+	.long	0x9fb518
+	.long	0x9fb5b8
 	.long	0x9fb5c8
 	.long	0x9fb5d0
-	.long	0x9fb618
-	.long	0x9fb660
-	.long	0x9fb6a8
-	.long	0x9fb6f0
-	.long	0x9fb738
-	.long	0x9fb748
-	.long	0x9fb7c0
-	.long	0x9fb838
-	.long	0x9fb878
-	.long	0x9fb888
-	.long	0x9fb900
-	.long	0x9fb90c
-	.long	0x9fb920
-	.long	0x9fb998
-	.long	0x9fba10
-	.long	0x9fba1c
-	.long	0x9fba38
-	.long	0x9fba58
-	.long	0x9fbad0
-	.long	0x9fbaf0
-	.long	0x9fbb08
-	.long	0x9fbb20
-	.long	0x9fbb2c
-	.long	0x9fbb4c
-	.long	0x9fbb64
-	.long	0x9fbb7c
-	.long	0x9fbb88
-	.long	0x9fbba0
-	.long	0x9fbc18
-	.long	0x9fbc2c
-	.long	0x9fbc40
-	.long	0x9fbc54
-	.long	0x9fbc7c
-	.long	0x9fbcf4
-	.long	0x9fbd1c
-	.long	0x9fbd3c
-	.long	0x9fbd5c
-	.long	0x9fbd7c
-	.long	0x9fbd90
-	.long	0x9fbda8
-	.long	0x9fbdcc
-	.long	0x9fbdd8
-	.long	0x9fbdf4
-	.long	0x9fbe14
-	.long	0x9fbe30
-	.long	0x9fbe50
-	.long	0x9fbe70
-	.long	0x9fbe84
-	.long	0x9fbe94
-	.long	0x9fbea4
-	.long	0x9fbebc
-	.long	0x9fbed4
-	.long	0x9fbef0
-	.long	0x9fbf04
-	.long	0x9fbf6c
-	.long	0x9fbf78
-	.long	0x9fbf88
-	.long	0x9fc000
-	.long	0x9fc034
-	.long	0x9fc0ac
-	.long	0x9fc108
+	.long	0x9fb5d8
+	.long	0x9fb620
+	.long	0x9fb668
+	.long	0x9fb6b0
+	.long	0x9fb6f8
+	.long	0x9fb740
+	.long	0x9fb750
+	.long	0x9fb7c8
+	.long	0x9fb840
+	.long	0x9fb880
+	.long	0x9fb890
+	.long	0x9fb908
+	.long	0x9fb914
+	.long	0x9fb928
+	.long	0x9fb9a0
+	.long	0x9fba18
+	.long	0x9fba24
+	.long	0x9fba40
+	.long	0x9fba60
+	.long	0x9fbad8
+	.long	0x9fbaf8
+	.long	0x9fbb10
+	.long	0x9fbb28
+	.long	0x9fbb34
+	.long	0x9fbb54
+	.long	0x9fbb6c
+	.long	0x9fbb84
+	.long	0x9fbb90
+	.long	0x9fbba8
+	.long	0x9fbc20
+	.long	0x9fbc34
+	.long	0x9fbc48
+	.long	0x9fbc5c
+	.long	0x9fbc84
+	.long	0x9fbcfc
+	.long	0x9fbd24
+	.long	0x9fbd44
+	.long	0x9fbd64
+	.long	0x9fbd84
+	.long	0x9fbd98
+	.long	0x9fbdb0
+	.long	0x9fbdd4
+	.long	0x9fbde0
+	.long	0x9fbdfc
+	.long	0x9fbe1c
+	.long	0x9fbe38
+	.long	0x9fbe58
+	.long	0x9fbe78
+	.long	0x9fbe8c
+	.long	0x9fbe9c
+	.long	0x9fbeac
+	.long	0x9fbec4
+	.long	0x9fbedc
+	.long	0x9fbef8
+	.long	0x9fbf0c
+	.long	0x9fbf74
+	.long	0x9fbf80
+	.long	0x9fbf90
+	.long	0x9fc008
+	.long	0x9fc03c
+	.long	0x9fc0b4
 	.long	0x9fc110
-	.long	0x9fc188
-	.long	0x9fc198
-	.long	0x9fc210
-	.long	0x9fc24c
-	.long	0x9fc25c
-	.long	0x9fc29c
-	.long	0x9fc2c4
-	.long	0x9fc2e8
-	.long	0x9fc2fc
-	.long	0x9fc308
-	.long	0x9fc31c
-	.long	0x9fc32c
-	.long	0x9fc3a4
-	.long	0x9fc3b8
-	.long	0x9fc3d8
-	.long	0x9fc3f8
-	.long	0x9fc418
-	.long	0x9fc438
-	.long	0x9fc4b0
-	.long	0x9fc4cc
-	.long	0x9fc4e8
-	.long	0x9fc504
-	.long	0xa03b80
-	.long	0xa03bf8
-	.long	0xa03c0c
-	.long	0xa0400c
-	.long	0xa0401c
-	.long	0xa0403c
-	.long	0xa04050
-	.long	0xa0407c
-	.long	0xa040f4
-	.long	0xa04134
-	.long	0xa04148
-	.long	0xa04164
-	.long	0xa0417c
-	.long	0xa04190
-	.long	0xa041a4
+	.long	0x9fc118
+	.long	0x9fc190
+	.long	0x9fc1a0
+	.long	0x9fc218
+	.long	0x9fc254
+	.long	0x9fc264
+	.long	0x9fc2a4
+	.long	0x9fc2cc
+	.long	0x9fc2f0
+	.long	0x9fc304
+	.long	0x9fc310
+	.long	0x9fc324
+	.long	0x9fc334
+	.long	0x9fc3ac
+	.long	0x9fc3c0
+	.long	0x9fc3e0
+	.long	0x9fc400
+	.long	0x9fc420
+	.long	0x9fc440
+	.long	0x9fc4b8
+	.long	0x9fc4d4
+	.long	0x9fc4f0
+	.long	0x9fc50c
+	.long	0xa03b88
+	.long	0xa03c00
+	.long	0xa03c14
+	.long	0xa04014
+	.long	0xa04024
+	.long	0xa04044
+	.long	0xa04058
+	.long	0xa04084
+	.long	0xa040fc
+	.long	0xa0413c
+	.long	0xa04150
+	.long	0xa0416c
+	.long	0xa04184
+	.long	0xa04198
+	.long	0xa041ac
 	.long	0xa04200
 	.long	0xa0422c
 	.long	0xa04240

BIN
board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/.tmp_vmlinux1


BIN
board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/.tmp_vmlinux2


+ 1 - 1
board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/.version

@@ -1 +1 @@
-403
+404

+ 98 - 19
board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/arch/arm/boot/dts/.am335x-evm.dtb.dts.tmp

@@ -1199,22 +1199,35 @@
 
 
 
+   0x020 (((1 << 5) | (1 << 3)) | 7)
+   0x024 (((1 << 5) | (1 << 3)) | 7)
+   0x028 (((1 << 5) | (1 << 3)) | 7)
+   0x02C (((1 << 5) | (1 << 3)) | 7)
    0x144 (((1 << 5) | (1 << 3)) | 7)
    0x1B0 (((1 << 3)) | 7)
    0x1B4 (((1 << 5) | (1 << 3)) | 7)
 
 
-   0x08C (((1 << 3)) | 7)
-   0x0A0 (((1 << 3)) | 7)
-   0x0A4 (((1 << 3)) | 7)
-   0x0A8 (((1 << 3)) | 7)
-   0x0AC (((1 << 3)) | 7)
-   0x0B0 (((1 << 3)) | 7)
-   0x0B4 (((1 << 3)) | 7)
+   0x030 (((1 << 5) | (1 << 3)) | 7)
+   0x034 (((1 << 5) | (1 << 3)) | 7)
+   0x038 (((1 << 5) | (1 << 3)) | 7)
+   0x03C (((1 << 5) | (1 << 3)) | 7)
+
+
+   0x0EC (((1 << 3)) | 7)
+   0x0E4 (((1 << 3)) | 7)
    0x0E8 (((1 << 5) | (1 << 3)) | 7)
-   0x0E0 (((1 << 3)) | 7)
+   0x0E0 (((1 << 5) | (1 << 3)) | 7)
+
 
+   0x194 (((1 << 5) | (1 << 3)) | 7)
+   0x1A0 (((1 << 5) | (1 << 3)) | 7)
+   0x19C (((1 << 5) | (1 << 3)) | 7)
+   0x190 (((1 << 3)) | 7)
+   0x1A4 (((1 << 3)) | 7)
+   0x198 (((1 << 3)) | 7)
    0x1A8 (((1 << 3)) | 7)
+
   >;
  };
 
@@ -1259,7 +1272,14 @@
    0x164 (0 | 1)
   >;
  };
-# 136 "arch/arm/boot/dts/am335x-evm.dts"
+
+ uart5_pins: pinmux_uart5_pins {
+  pinctrl-single,pins = <
+   0x0C0 (0 | 4)
+   0x0C4 (((1 << 5) | (1 << 4)) | 4)
+  >;
+ };
+
  clkout2_pin: pinmux_clkout2_pin {
   pinctrl-single,pins = <
    0x1b4 (0 | 3)
@@ -1310,12 +1330,12 @@
   pinctrl-single,pins = <
 
 
-
-
+   0x108 (((1 << 5) | (1 << 4)) | 0)
+   0x10C(((1 << 5) | (1 << 4)) | 0)
    0x110 (((1 << 5) | (1 << 4)) | 0)
-   0x118 (((1 << 5) | (1 << 4)) | 0)
    0x12c (((1 << 5) | (1 << 4)) | 0)
    0x130 (((1 << 5) | (1 << 4)) | 0)
+   0x118 (((1 << 5) | (1 << 4)) | 0)
    0x134 (((1 << 5) | (1 << 4)) | 0)
    0x138 (((1 << 5) | (1 << 4)) | 0)
    0x13c (((1 << 5) | (1 << 4)) | 0)
@@ -1326,6 +1346,23 @@
    0x124 (0 | 0)
    0x128 (0 | 0)
 
+
+   ((((0x878)) & 0xffff) - (0x0800)) (((1 << 5) | (1 << 4)) | 1)
+   ((((0x888)) & 0xffff) - (0x0800)) (((1 << 5) | (1 << 4)) | 2)
+
+   ((((0x858)) & 0xffff) - (0x0800)) (((1 << 5) | (1 << 4)) | 1)
+   ((((0x85c)) & 0xffff) - (0x0800)) (((1 << 5) | (1 << 4)) | 1)
+   ((((0x844)) & 0xffff) - (0x0800)) (((1 << 5) | (1 << 4)) | 1)
+   ((((0x860)) & 0xffff) - (0x0800)) (((1 << 5) | (1 << 4)) | 1)
+   ((((0x864)) & 0xffff) - (0x0800)) (((1 << 5) | (1 << 4)) | 1)
+   ((((0x868)) & 0xffff) - (0x0800)) (((1 << 5) | (1 << 4)) | 1)
+   ((((0x86c)) & 0xffff) - (0x0800)) (((1 << 5) | (1 << 4)) | 1)
+   ((((0x840)) & 0xffff) - (0x0800)) (0 | 1)
+   ((((0x848)) & 0xffff) - (0x0800)) (0 | 1)
+   ((((0x84c)) & 0xffff) - (0x0800)) (0 | 1)
+   ((((0x850)) & 0xffff) - (0x0800)) (0 | 1)
+   ((((0x854)) & 0xffff) - (0x0800)) (0 | 1)
+
   >;
  };
 
@@ -1345,6 +1382,23 @@
    0x13c (((1 << 5)) | 7)
    0x140 (((1 << 5)) | 7)
 
+
+   ((((0x888)) & 0xffff) - (0x0800)) (((1 << 5)) | 7)
+   ((((0x840)) & 0xffff) - (0x0800)) (((1 << 5)) | 7)
+   ((((0x844)) & 0xffff) - (0x0800)) (((1 << 5)) | 7)
+   ((((0x848)) & 0xffff) - (0x0800)) (((1 << 5)) | 7)
+   ((((0x84c)) & 0xffff) - (0x0800)) (((1 << 5)) | 7)
+   ((((0x850)) & 0xffff) - (0x0800)) (((1 << 5)) | 7)
+   ((((0x854)) & 0xffff) - (0x0800)) (((1 << 5)) | 7)
+   ((((0x858)) & 0xffff) - (0x0800)) (((1 << 5)) | 7)
+   ((((0x85c)) & 0xffff) - (0x0800)) (((1 << 5)) | 7)
+   ((((0x860)) & 0xffff) - (0x0800)) (((1 << 5)) | 7)
+   ((((0x864)) & 0xffff) - (0x0800)) (((1 << 5)) | 7)
+   ((((0x868)) & 0xffff) - (0x0800)) (((1 << 5)) | 7)
+   ((((0x86c)) & 0xffff) - (0x0800)) (((1 << 5)) | 7)
+
+   ((((0x878)) & 0xffff) - (0x0800)) (((1 << 5)) | 7)
+
   >;
  };
 
@@ -1383,7 +1437,14 @@
    0x17C (((1 << 5)) | 2)
   >;
  };
-# 280 "arch/arm/boot/dts/am335x-evm.dts"
+
+ dcan1_pins_default: dcan1_pins_default {
+  pinctrl-single,pins = <
+   0x168 (((1 << 4)) | 2)
+   0x16C (((1 << 5)) | 2)
+  >;
+ };
+# 327 "arch/arm/boot/dts/am335x-evm.dts"
 };
 
 
@@ -1415,7 +1476,14 @@
 
  status = "okay";
 };
-# 319 "arch/arm/boot/dts/am335x-evm.dts"
+
+&uart5 {
+ pinctrl-names = "default";
+ pinctrl-0 = <&uart5_pins>;
+
+ status = "okay";
+};
+
 &i2c0 {
  pinctrl-names = "default";
  pinctrl-0 = <&i2c0_pins>;
@@ -1444,7 +1512,6 @@
                 compatible = "nxp,pcf85063";
                 reg = <0x51>;
         };
-
 };
 
 &usb {
@@ -1479,7 +1546,7 @@
 &elm {
  status = "okay";
 };
-# 403 "arch/arm/boot/dts/am335x-evm.dts"
+# 449 "arch/arm/boot/dts/am335x-evm.dts"
 &gpmc {
  status = "okay";
  pinctrl-names = "default", "sleep";
@@ -1665,7 +1732,7 @@
   };
  };
 };
-# 509 "arch/arm/boot/dts/am335x-evm.dts" 2
+# 555 "arch/arm/boot/dts/am335x-evm.dts" 2
 
 &tps {
  vcc1-supply = <&vbat>;
@@ -1748,6 +1815,7 @@
  pinctrl-names = "default", "sleep";
  pinctrl-0 = <&cpsw_default>;
  pinctrl-1 = <&cpsw_sleep>;
+ dual_emac = <1>;
  status = "okay";
 };
 
@@ -1756,15 +1824,20 @@
  pinctrl-0 = <&davinci_mdio_default>;
  pinctrl-1 = <&davinci_mdio_sleep>;
  status = "okay";
-
 };
 
 &cpsw_emac0 {
  phy_id = <&davinci_mdio>, <1>;
   phy-mode = "mii";
+  dual_emac_res_vlan = <1>;
+};
 
+&cpsw_emac1 {
+ phy_id = <&davinci_mdio>, <2>;
+  phy-mode = "mii";
+  dual_emac_res_vlan = <2>;
 };
-# 615 "arch/arm/boot/dts/am335x-evm.dts"
+
 &tscadc {
  status = "okay";
 
@@ -1811,3 +1884,9 @@
  pinctrl-names = "default";
  pinctrl-0 = <&dcan0_pins_default>;
 };
+
+&dcan1 {
+ status = "okay";
+ pinctrl-names = "default";
+ pinctrl-0 = <&dcan1_pins_default>;
+};

+ 711 - 0
board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/arch/arm/boot/dts/[PlugIt360]am335x-evm.dts

@@ -0,0 +1,711 @@
+/*
+ * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ 
+#define PIN_OUTPUT		(PULL_DISABLE)
+#define PIN_OUTPUT_PULLUP	(PULL_UP)
+#define PIN_OUTPUT_PULLDOWN	0
+#define PIN_INPUT		(INPUT_EN | PULL_DISABLE)
+#define PIN_INPUT_PULLUP	(INPUT_EN | PULL_UP)
+#define PIN_INPUT_PULLDOWN	(INPUT_EN)
+
+
+ */
+/dts-v1/;
+
+#include "am33xx.dtsi"
+#include <dt-bindings/interrupt-controller/irq.h>
+
+/ {
+	model = "TI AM335x EVM";
+	compatible = "ti,am335x-evm", "ti,am33xx";
+
+	cpus {
+		cpu@0 {
+			cpu0-supply = <&vdd1_reg>;
+		};
+	};
+
+	memory {
+		device_type = "memory";
+		/*reg = <0x80000000 0x10000000>;*/ /* 256 MB */
+		reg = <0x80000000 0x20000000>; /* 512 MB */ /* +++ vern,512MB DDR ,20181030 ---*/
+	};
+	/* +++ vern,ramdisk,20181030 +++*/
+	chosen {  
+		bootargs = "console=ttyS0,115200n8 root=/dev/ram0";  
+	};  
+	/* --- vern,ramdisk ,20181030 ---*/
+	vbat: fixedregulator@0 {
+		compatible = "regulator-fixed";
+		regulator-name = "vbat";
+		regulator-min-microvolt = <5000000>;
+		regulator-max-microvolt = <5000000>;
+		regulator-boot-on;
+	};
+
+	lis3_reg: fixedregulator@1 {
+		compatible = "regulator-fixed";
+		regulator-name = "lis3_reg";
+		regulator-boot-on;
+	};
+};
+
+/******************** Pin Mux ********************/
+&am33xx_pinmux {
+	pinctrl-names = "default";
+	pinctrl-0 = <&InitialGPIO>; 
+	pinctrl-1 = <&clkout2_pin>;
+	
+	InitialGPIO: InitialGPIO {
+		pinctrl-single,pins = <
+		
+			/** Offset: 0x800 */
+			/** GPIO 0 */   
+			0x020 (PIN_INPUT | MUX_MODE7)			/* GPMC_AD8			=> 	GPIO0_22 */	/*ID BD1_1*/
+			0x024 (PIN_INPUT | MUX_MODE7)    			/* GPMC_AD9			=>	GPIO0_23 */	/*ID BD1_2*/
+			0x028 (PIN_INPUT | MUX_MODE7)    			/* GPMC_AD10		=>	GPIO0_26 */	/*IO BD1_1*/
+			0x02C (PIN_INPUT | MUX_MODE7)    		/* GPMC_AD11		=>	GPIO0_27 */	/*IO BD1_2*/
+			0x144 (PIN_INPUT | MUX_MODE7)    			/* RMII1_REF_CLK		=>	GPIO0_29 */	/*USB 0 OCP detection*/
+			0x1B0 (PIN_OUTPUT | MUX_MODE7)			/*XDMA_EVENT_INTR0	=>	GPIO0_19 */	/*AM_RFID_RST*/
+			0x1B4 (PIN_INPUT | MUX_MODE7)			/*XDMA_EVENT_INTR1	=>	GPIO0_20 */	/*AM_RFID_ICC*/
+			
+			/** GPIO 1 */
+			0x030 (PIN_INPUT | MUX_MODE7)			/* GPMC_AD12	=> 	GPIO1_12 */	/*ID BD2_1*/
+			0x034 (PIN_INPUT | MUX_MODE7)    			/* GPMC_AD13	=>	GPIO1_13 */	/*ID BD2_2*/
+			0x038 (PIN_INPUT | MUX_MODE7)    			/* GPMC_AD14	=>	GPIO1_14 */	/*IO BD2_1*/
+			0x03C (PIN_INPUT | MUX_MODE7)    		/* GPMC_AD15	=>	GPIO1_15 */	/*IO BD2_2*/
+			
+			/** GPIO 2 */
+			0x0EC (PIN_OUTPUT | MUX_MODE7)			/*LCD_AC_BIAS_EN	=>	GPIO2_25*/	/*RS-485 for module DE control*/
+			0x0E4 (PIN_OUTPUT | MUX_MODE7)			/*LCD_HSYNC		=>	GPIO2_23*/	/*RS-485 for module RE control*/
+			0x0E8 (PIN_INPUT | MUX_MODE7)			/*LCD_PCLK		=>	GPIO2_24*/	/*CCS communication board 1 proximity*/
+			0x0E0 (PIN_INPUT | MUX_MODE7)			/*LCD_VSYNC		=>	GPIO2_22*/	/*CCS communication board 2 proximity*/
+			
+			/** GPIO 3 */
+			0x194 (PIN_INPUT | MUX_MODE7)			/*MCASP0_FSX		=>	GPIO3_15*/	/*Emergency Stop button detect*/
+			0x1A0 (PIN_INPUT | MUX_MODE7)			/*MCASP0_ACLKR	=>	GPIO3_18*/	/*USB1 OCP detect*/
+			0x19C (PIN_INPUT | MUX_MODE7)			/*MCASP0_AHCLKR	=>	GPIO3_17*/	/*Emergency IO for AM3352 and STM32F407*/
+			0x190 (PIN_OUTPUT | MUX_MODE7)			/*MCASP0_ACLKX	=>	GPIO3_14*/	/*Ethernet PHY reset*/
+			0x1A4 (PIN_OUTPUT | MUX_MODE7)			/* MCASP0_FSR		=>	GPIO3_19 */	/*SMR Enable control_1*/
+			0x198 (PIN_OUTPUT | MUX_MODE7)			/* MCASP0_AXR0	=>	GPIO3_16 */	/*CSU board function OK indicator.*/
+			0x1A8 (PIN_OUTPUT | MUX_MODE7)			/* MCASP0_AXR1	=>	GPIO3_20 */	/*SMR Enable control_2*/
+			
+		>;
+	};
+	
+	i2c0_pins: pinmux_i2c0_pins {
+		pinctrl-single,pins = <
+			0x188 (PIN_INPUT_PULLUP | MUX_MODE0)	/* i2c0_sda.i2c0_sda */
+			0x18c (PIN_INPUT_PULLUP | MUX_MODE0)	/* i2c0_scl.i2c0_scl */
+		>;
+	};
+#if 1
+	i2c1_pins: pinmux_i2c1_pins {
+		pinctrl-single,pins = <
+			0x158 (PIN_INPUT_PULLUP | MUX_MODE2)	/* spi0_d1.i2c1_sda */
+			0x15c (PIN_INPUT_PULLUP | MUX_MODE2)	/* spi0_cs0.i2c1_scl */
+		>;
+	};
+#endif
+	uart0_pins: pinmux_uart0_pins {
+		pinctrl-single,pins = <
+			0x170 (PIN_INPUT_PULLUP | MUX_MODE0)		/* uart0_rxd	=>	uart0_rxd */
+			0x174 (PIN_OUTPUT_PULLDOWN | MUX_MODE0)	/* uart0_txd	=>	uart0_txd */
+		>;
+	};
+	
+	uart1_pins: pinmux_uart1_pins {
+		pinctrl-single,pins = <
+			0x184 (PIN_OUTPUT_PULLDOWN | MUX_MODE0) 		/* uart1_txd	=>	uart1_txd */
+			0x180 (PIN_INPUT_PULLUP | MUX_MODE0)			/* uart1_rxd	=>	uart1_rxd */
+		>;
+	};
+
+	uart2_pins: pinmux_uart2_pins {
+		pinctrl-single,pins = <
+			0x150 (PIN_INPUT_PULLUP | MUX_MODE1)			/* SPI0_SCLK	=>	UART2_RXD */
+			0x154 (PIN_OUTPUT_PULLDOWN | MUX_MODE1)		/* SPI0_D0	=>	UART2_TXD */
+		>;
+	};
+	
+	uart3_pins: pinmux_uart3_pins {
+		pinctrl-single,pins = <
+			0x160 (PIN_INPUT_PULLUP | MUX_MODE1)		/* SPI0_CS1				=>	uart3_rxd */
+			0x164 (PIN_OUTPUT_PULLDOWN | MUX_MODE1)	/* ECAP0_IN_PWM0_OUT		=>	uart3_txd */
+		>;
+	};
+
+	uart5_pins: pinmux_uart5_pins {
+		pinctrl-single,pins = <
+			0x0C0 (PIN_OUTPUT_PULLDOWN | MUX_MODE4)		/* LCD_DATA8	=>	DUART5_TX*/
+			0x0C4 (PIN_INPUT_PULLUP | MUX_MODE4)			/* LCD_DATA9	=>	UART5_RX*/
+		>;
+	};
+	
+	clkout2_pin: pinmux_clkout2_pin {
+		pinctrl-single,pins = <
+			0x1b4 (PIN_OUTPUT_PULLDOWN | MUX_MODE3)	/* xdma_event_intr1.clkout2 */
+		>;
+	};
+
+	nandflash_pins_default: nandflash_pins_default {
+		pinctrl-single,pins = <
+			0x0 (PIN_INPUT_PULLUP | MUX_MODE0)	/* gpmc_ad0.gpmc_ad0 */
+			0x4 (PIN_INPUT_PULLUP | MUX_MODE0)	/* gpmc_ad1.gpmc_ad1 */
+			0x8 (PIN_INPUT_PULLUP | MUX_MODE0)	/* gpmc_ad2.gpmc_ad2 */
+			0xc (PIN_INPUT_PULLUP | MUX_MODE0)	/* gpmc_ad3.gpmc_ad3 */
+			0x10 (PIN_INPUT_PULLUP | MUX_MODE0)	/* gpmc_ad4.gpmc_ad4 */
+			0x14 (PIN_INPUT_PULLUP | MUX_MODE0)	/* gpmc_ad5.gpmc_ad5 */
+			0x18 (PIN_INPUT_PULLUP | MUX_MODE0)	/* gpmc_ad6.gpmc_ad6 */
+			0x1c (PIN_INPUT_PULLUP | MUX_MODE0)	/* gpmc_ad7.gpmc_ad7 */
+			0x70 (PIN_INPUT_PULLUP | MUX_MODE0)	/* gpmc_wait0.gpmc_wait0 */
+			0x74 (PIN_INPUT_PULLUP | MUX_MODE7)	/* gpmc_wpn.gpio0_31 */
+			0x7c (PIN_OUTPUT | MUX_MODE0)		/* gpmc_csn0.gpmc_csn0  */
+			0x90 (PIN_OUTPUT | MUX_MODE0)		/* gpmc_advn_ale.gpmc_advn_ale */
+			0x94 (PIN_OUTPUT | MUX_MODE0)		/* gpmc_oen_ren.gpmc_oen_ren */
+			0x98 (PIN_OUTPUT | MUX_MODE0)		/* gpmc_wen.gpmc_wen */
+			0x9c (PIN_OUTPUT | MUX_MODE0)		/* gpmc_be0n_cle.gpmc_be0n_cle */
+		>;
+	};
+
+	nandflash_pins_sleep: nandflash_pins_sleep {
+		pinctrl-single,pins = <
+			0x0 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x4 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x8 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0xc (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x10 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x14 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x18 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x1c (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x70 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x74 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x7c (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x90 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x94 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x98 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x9c (PIN_INPUT_PULLDOWN | MUX_MODE7)
+		>;
+	};
+
+	cpsw_default: cpsw_default {
+		pinctrl-single,pins = <					
+		
+			/* Slave 1 */
+			0x108 (PIN_INPUT_PULLUP | MUX_MODE0)		/* MII1_COL.gmii1_col */
+			0x10C(PIN_INPUT_PULLUP | MUX_MODE0)		/* MII1_CRS.MII1_CRS */
+			0x110 (PIN_INPUT_PULLUP | MUX_MODE0)		/* MII1_RX_ER.gmii1_rxerr */
+			0x12c (PIN_INPUT_PULLUP | MUX_MODE0)		/* mii1_txclk.mii1_txclk */
+			0x130 (PIN_INPUT_PULLUP | MUX_MODE0)		/* mii1_rxclk.mii1_rxclk */
+			0x118 (PIN_INPUT_PULLUP | MUX_MODE0)		/* mii1_rxdv.mii1_rxdv */
+			0x134 (PIN_INPUT_PULLUP | MUX_MODE0)		/* mii1_rxd3.rgmii1_rd3 */
+			0x138 (PIN_INPUT_PULLUP | MUX_MODE0)		/* mii1_rxd2.rgmii1_rd2 */
+			0x13c (PIN_INPUT_PULLUP | MUX_MODE0)		/* mii1_rxd1.rgmii1_rd1 */
+			0x140 (PIN_INPUT_PULLUP | MUX_MODE0)		/* mii1_rxd0.rgmii1_rd0 */	
+			0x114 (PIN_OUTPUT_PULLDOWN | MUX_MODE0)		/* mii1_txen.mii1_txen */
+			0x11c (PIN_OUTPUT_PULLDOWN | MUX_MODE0)		/* mii1_txd3.rgmii1_td3 */
+			0x120 (PIN_OUTPUT_PULLDOWN | MUX_MODE0)		/* mii1_txd2.rgmii1_td2 */
+			0x124 (PIN_OUTPUT_PULLDOWN | MUX_MODE0)		/* mii1_txd1.rgmii1_td1 */
+			0x128 (PIN_OUTPUT_PULLDOWN | MUX_MODE0)		/* mii1_txd0.rgmii1_td0 */      	
+			
+			/* Slave 2 */
+			AM33XX_IOPAD(0x878, PIN_INPUT_PULLUP | MUX_MODE1)					/* gpmc_ben1.mii2_col */
+			AM33XX_IOPAD(0x888, PIN_INPUT_PULLUP | MUX_MODE2)					/* GPMC_CSn3.rmii2_crs_dv*/								
+			/*AM33XX_IOPAD(0x874, PIN_INPUT_PULLUP | MUX_MODE1)*/					/* gpmc_wpn.mii2_rxerr */
+			AM33XX_IOPAD(0x858, PIN_INPUT_PULLUP | MUX_MODE1)					/* gpmc_a6.mii2_txclk */
+			AM33XX_IOPAD(0x85c, PIN_INPUT_PULLUP | MUX_MODE1)					/* gpmc_a7.mii2_rxclk */
+			AM33XX_IOPAD(0x844, PIN_INPUT_PULLUP | MUX_MODE1)					/* gpmc_a1.mii2_rxdv */
+			AM33XX_IOPAD(0x860, PIN_INPUT_PULLUP | MUX_MODE1)					/* gpmc_a8.mii2_rxd3 */
+			AM33XX_IOPAD(0x864, PIN_INPUT_PULLUP | MUX_MODE1)					/* gpmc_a9.mii2_rxd2 */
+			AM33XX_IOPAD(0x868, PIN_INPUT_PULLUP | MUX_MODE1)					/* gpmc_a10.mii2_rxd1 */
+			AM33XX_IOPAD(0x86c, PIN_INPUT_PULLUP | MUX_MODE1)					/* gpmc_a11.mii2_rxd0 */
+			AM33XX_IOPAD(0x840, PIN_OUTPUT_PULLDOWN | MUX_MODE1)				/* gpmc_a0.mii2_txen */
+			AM33XX_IOPAD(0x848, PIN_OUTPUT_PULLDOWN | MUX_MODE1)				/* gpmc_a2.mii2_txd3 */
+			AM33XX_IOPAD(0x84c, PIN_OUTPUT_PULLDOWN | MUX_MODE1)				/* gpmc_a3.mii2_txd2 */
+			AM33XX_IOPAD(0x850, PIN_OUTPUT_PULLDOWN | MUX_MODE1)				/* gpmc_a4.mii2_txd1 */
+			AM33XX_IOPAD(0x854, PIN_OUTPUT_PULLDOWN | MUX_MODE1)				/* gpmc_a5.mii2_txd0 */
+
+		>;
+	};
+
+	cpsw_sleep: cpsw_sleep {
+		pinctrl-single,pins = <
+			/* Slave 1 reset value */
+			0x114 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x118 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x11c (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x120 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x124 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x128 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x12c (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x130 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x134 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x138 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x13c (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x140 (PIN_INPUT_PULLDOWN | MUX_MODE7)		
+			
+			/* Slave 2 */
+			AM33XX_IOPAD(0x888, PIN_INPUT_PULLDOWN | MUX_MODE7)					/* GPMC_CSn3.rmii2_crs_dv*/	
+			AM33XX_IOPAD(0x840, PIN_INPUT_PULLDOWN | MUX_MODE7)				/* gpmc_a0.mii2_txen */
+			AM33XX_IOPAD(0x844, PIN_INPUT_PULLDOWN | MUX_MODE7)	/* gpmc_a1.mii2_rxdv */
+			AM33XX_IOPAD(0x848, PIN_INPUT_PULLDOWN | MUX_MODE7)				/* gpmc_a2.mii2_txd3 */
+			AM33XX_IOPAD(0x84c, PIN_INPUT_PULLDOWN | MUX_MODE7)			/* gpmc_a3.mii2_txd2 */
+			AM33XX_IOPAD(0x850, PIN_INPUT_PULLDOWN | MUX_MODE7)				/* gpmc_a4.mii2_txd1 */
+			AM33XX_IOPAD(0x854, PIN_INPUT_PULLDOWN | MUX_MODE7)				/* gpmc_a5.mii2_txd0 */
+			AM33XX_IOPAD(0x858, PIN_INPUT_PULLDOWN | MUX_MODE7)	/* gpmc_a6.mii2_txclk */
+			AM33XX_IOPAD(0x85c, PIN_INPUT_PULLDOWN | MUX_MODE7)	/* gpmc_a7.mii2_rxclk */
+			AM33XX_IOPAD(0x860, PIN_INPUT_PULLDOWN | MUX_MODE7)	/* gpmc_a8.mii2_rxd3 */
+			AM33XX_IOPAD(0x864, PIN_INPUT_PULLDOWN | MUX_MODE7)	/* gpmc_a9.mii2_rxd2 */
+			AM33XX_IOPAD(0x868, PIN_INPUT_PULLDOWN | MUX_MODE7)	/* gpmc_a10.mii2_rxd1 */
+			AM33XX_IOPAD(0x86c, PIN_INPUT_PULLDOWN | MUX_MODE7)	/* gpmc_a11.mii2_rxd0 */
+			/*AM33XX_IOPAD(0x874, PIN_INPUT_PULLDOWN | MUX_MODE7)*/	/* gpmc_wpn.mii2_rxerr */
+			AM33XX_IOPAD(0x878, PIN_INPUT_PULLDOWN | MUX_MODE7)	/* gpmc_ben1.mii2_col */
+			
+		>;
+	};
+
+
+	davinci_mdio_default: davinci_mdio_default {
+		pinctrl-single,pins = <
+			/* MDIO */
+			0x148 (PIN_INPUT_PULLUP | SLEWCTRL_FAST | MUX_MODE0)	/* mdio_data.mdio_data */
+			0x14c (PIN_OUTPUT_PULLUP | MUX_MODE0)			/* mdio_clk.mdio_clk */
+		>;
+	};
+
+	davinci_mdio_sleep: davinci_mdio_sleep {
+		pinctrl-single,pins = <
+			/* MDIO reset value */
+			0x148 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x14c (PIN_INPUT_PULLDOWN | MUX_MODE7)
+		>;
+	};
+
+	mmc1_pins_default: pinmux_mmc1_pins {
+		pinctrl-single,pins = <
+			0x0F0 (PIN_INPUT_PULLUP | MUX_MODE0)    	/* mmc0_dat3.mmc0_dat3 */
+			0x0F4 (PIN_INPUT_PULLUP | MUX_MODE0)    	/* mmc0_dat2.mmc0_dat2 */
+			0x0F8 (PIN_INPUT_PULLUP | MUX_MODE0)    	/* mmc0_dat1.mmc0_dat1 */
+			0x0FC (PIN_INPUT_PULLUP | MUX_MODE0)    	/* mmc0_dat0.mmc0_dat0 */
+			0x100 (PIN_INPUT_PULLUP | MUX_MODE0)    	/* mmc0_clk.mmc0_clk */
+			0x104 (PIN_INPUT_PULLUP | MUX_MODE0)    	/* mmc0_cmd.mmc0_cmd */
+			0x1AC (PIN_INPUT_PULLUP | MUX_MODE7)	/* MCASP0_AHCLKX.GPIO3_21 */
+		>;
+	};
+
+	dcan0_pins_default: dcan0_pins_default {
+		pinctrl-single,pins = <		
+			0x178 (PIN_OUTPUT_PULLUP | MUX_MODE2)			/* uart1_ctsn	=>	d_can0_tx */
+			0x17C (PIN_INPUT_PULLDOWN | MUX_MODE2)		/* uart1_rtsn	=>	d_can0_rx */
+		>;
+	};
+	
+	dcan1_pins_default: dcan1_pins_default {
+		pinctrl-single,pins = <
+			0x168 (PIN_OUTPUT_PULLUP | MUX_MODE2)		/* UART0_CTSn		=>	d_can1_tx */
+			0x16C (PIN_INPUT_PULLDOWN | MUX_MODE2)	/* UART0_RTSn		=>	d_can1_rx */
+		>;
+	};
+#if 0
+	ehrpwm1_pins: ehrpwm1_pins {
+		pinctrl-single,pins = <			
+			0x0C8 (PIN_OUTPUT | MUX_MODE2) /* LCD_DATA10.eHRPWM1A */
+		>;
+	};
+	
+	ehrpwm2_pins: ehrpwm2_pins {
+		pinctrl-single,pins =< 
+			0x0A4 (PIN_OUTPUT | MUX_MODE3)	/* LCD_DATA1.eHRPWM2B */
+		>;                
+    };	
+	 
+#endif  
+};
+
+
+/******************** Peripheral Init ********************/			
+&uart0 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&uart0_pins>;
+
+	status = "okay";
+};
+
+&uart1 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&uart1_pins>;
+
+	status = "okay";
+};
+
+&uart2 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&uart2_pins>;
+
+	status = "okay";
+};
+
+&uart3 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&uart3_pins>;
+
+	status = "okay";
+};
+
+&uart5 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&uart5_pins>;
+
+	status = "okay";
+};
+
+&i2c0 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&i2c0_pins>;
+
+	status = "okay";
+	clock-frequency = <400000>;
+
+	tps: tps@2d {
+		reg = <0x2d>;
+	};
+	
+/*	rtc0: rtc@51 {
+                compatible = "nxp,pcf85063";
+                reg = <0x51>;
+        };*/	
+};
+#if 1
+&i2c1 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&i2c1_pins>;
+
+	status = "okay";
+	clock-frequency = <400000>;
+
+	rtc0: rtc@51 {
+                compatible = "nxp,pcf85063";
+                reg = <0x51>;
+        };
+};
+#endif
+&usb {
+	status = "okay";
+};
+
+&usb_ctrl_mod {
+	status = "okay";
+};
+
+&usb0_phy {
+	status = "okay";
+};
+
+&usb1_phy {
+	status = "okay";
+};
+
+&usb0 {
+	status = "okay";
+};
+
+&usb1 {
+	status = "okay";
+	dr_mode = "host";
+};
+
+&cppi41dma  {
+	status = "okay";
+};
+
+&elm {
+	status = "okay";
+};
+#if 0
+&epwmss1 {
+	status = "okay";      
+
+	ehrpwm1: pwm@48302200 {
+		status = "okay";
+		pinctrl-names = "default";
+		pinctrl-0 = <&ehrpwm1_pins>;
+	};
+};
+
+&epwmss2 {
+	status = "okay";   
+
+	ehrpwm2: pwm@48304200 {
+		status = "okay";
+		pinctrl-names = "default";
+		pinctrl-0 = <&ehrpwm2_pins>;
+	};	   
+};
+#endif
+&gpmc {
+	status = "okay";
+	pinctrl-names = "default", "sleep";
+	pinctrl-0 = <&nandflash_pins_default>;
+	pinctrl-1 = <&nandflash_pins_sleep>;
+	/*ranges = <0 0 0x08000000 0x10000000>;*/	/* CS0: NAND */
+	ranges = <0 0 0x08000000 0x80000000>;	/*+++ vern,NAND,20181030 ---*/
+	nand@0,0 {
+		compatible = "ti,omap2-nand";
+		reg = <0 0 4>; /* CS0, offset 0, IO size 4 */
+		interrupt-parent = <&gpmc>;
+		interrupts = <0 IRQ_TYPE_NONE>, /* fifoevent */
+                    <1 IRQ_TYPE_NONE>;	/* termcount */
+		rb-gpios = <&gpmc 0 GPIO_ACTIVE_HIGH>; /* gpmc_wait0 */
+		ti,nand-ecc-opt = "bch8";
+		ti,elm-id = <&elm>;
+		nand-bus-width = <8>;
+		gpmc,device-width = <1>;
+		gpmc,sync-clk-ps = <0>;
+		gpmc,cs-on-ns = <0>;
+		gpmc,cs-rd-off-ns = <44>;
+		gpmc,cs-wr-off-ns = <44>;
+		gpmc,adv-on-ns = <6>;
+		gpmc,adv-rd-off-ns = <34>;
+		gpmc,adv-wr-off-ns = <44>;
+		gpmc,we-on-ns = <0>;
+		gpmc,we-off-ns = <40>;
+		gpmc,oe-on-ns = <0>;
+		gpmc,oe-off-ns = <54>;
+		gpmc,access-ns = <64>;
+		gpmc,rd-cycle-ns = <82>;
+		gpmc,wr-cycle-ns = <82>;
+		gpmc,wait-on-read = "true";
+		gpmc,wait-on-write = "true";
+		gpmc,bus-turnaround-ns = <0>;
+		gpmc,cycle2cycle-delay-ns = <0>;
+		gpmc,clk-activation-ns = <0>;
+		gpmc,wait-monitoring-ns = <0>;
+		gpmc,wr-access-ns = <40>;
+		gpmc,wr-data-mux-bus-ns = <0>;
+		/* MTD partition table */
+		/* All SPL-* partitions are sized to minimal length
+		 * which can be independently programmable. For
+		 * NAND flash this is equal to size of erase-block */
+		#address-cells = <1>;
+		#size-cells = <1>;
+		partition@0 {
+			label = "SPL";
+			reg = <0x00000000 0x00080000>;
+		};
+		partition@1 {
+			label = "Primary u-boot";
+			reg = <0x00080000 0x00100000>;
+		};
+		partition@2 {
+			label = "u-boot-env";
+			reg = <0x00180000 0x00080000>;
+		};
+		partition@3 {
+			label = "Secondary u-boot";
+			reg = <0x00200000 0x00100000>;
+		};
+		partition@4 {
+			label = "Primary dtb";
+			reg = <0x00300000 0x00080000>;
+		};
+		partition@5 {
+			label = "Secondary dtb";
+			reg = <0x00380000 0x00080000>;
+		};
+		partition@6 {
+			label = "Primary kernel";
+			reg = <0x00400000 0x00A00000>;
+		};
+		partition@7 {
+			label = "Secondary kernel";
+			reg = <0x00E00000 0x00A00000>;
+		};
+		partition@8 {
+			label = "Primary rootfs";
+			reg = <0x03000000 0x03000000>;
+		};
+		partition@9 {
+			label = "Secondary rootfs";
+			reg = <0x06000000 0x03000000>;
+		};
+		partition@10 {
+			label = "Primary user configuration";
+			reg = <0x09000000 0x00600000>;
+		};
+		partition@11 {
+			label = "Secondary user configuration";
+			reg = <0x09600000 0x00600000>;
+		};
+		partition@12 {
+			label = "Factory default configuration";
+			reg = <0x09C00000 0x00600000>;
+		};
+		partition@13 {
+			label = "Storage";
+			reg = <0x0A200000 0x75E00000>;
+		};
+	};
+};
+
+#include "tps65910.dtsi"
+
+&tps {
+	vcc1-supply = <&vbat>;
+	vcc2-supply = <&vbat>;
+	vcc3-supply = <&vbat>;
+	vcc4-supply = <&vbat>;
+	vcc5-supply = <&vbat>;
+	vcc6-supply = <&vbat>;
+	vcc7-supply = <&vbat>;
+	vccio-supply = <&vbat>;
+
+	regulators {
+		vrtc_reg: regulator@0 {
+			regulator-always-on;
+		};
+
+		vio_reg: regulator@1 {
+			regulator-always-on;
+		};
+
+		vdd1_reg: regulator@2 {
+			/* VDD_MPU voltage limits 0.95V - 1.325V with +/-4% tolerance */
+			regulator-name = "vdd_mpu";
+			regulator-min-microvolt = <912500>;
+			regulator-max-microvolt = <1378000>;
+			regulator-boot-on;
+			regulator-always-on;
+		};
+
+		vdd2_reg: regulator@3 {
+			/* VDD_CORE voltage limits 0.95V - 1.1V with +/-4% tolerance */
+			regulator-name = "vdd_core";
+			regulator-min-microvolt = <912500>;
+			regulator-max-microvolt = <1150000>;
+			regulator-boot-on;
+			regulator-always-on;
+		};
+
+		vdd3_reg: regulator@4 {
+			regulator-always-on;
+		};
+
+		vdig1_reg: regulator@5 {
+			regulator-always-on;
+		};
+
+		vdig2_reg: regulator@6 {
+			regulator-always-on;
+		};
+
+		vpll_reg: regulator@7 {
+			regulator-always-on;
+		};
+
+		vdac_reg: regulator@8 {
+			regulator-always-on;
+		};
+
+		vaux1_reg: regulator@9 {
+			regulator-always-on;
+		};
+
+		vaux2_reg: regulator@10 {
+			regulator-always-on;
+		};
+
+		vaux33_reg: regulator@11 {
+			regulator-always-on;
+		};
+
+		vmmc_reg: regulator@12 {
+			regulator-min-microvolt = <1800000>;
+			regulator-max-microvolt = <3300000>;
+			regulator-always-on;
+		};
+	};
+};
+
+&mac {
+	pinctrl-names = "default", "sleep";
+	pinctrl-0 = <&cpsw_default>;
+	pinctrl-1 = <&cpsw_sleep>;
+	dual_emac = <1>;
+	status = "okay";
+};
+
+&davinci_mdio {
+	pinctrl-names = "default", "sleep";
+	pinctrl-0 = <&davinci_mdio_default>;
+	pinctrl-1 = <&davinci_mdio_sleep>;
+	status = "okay";
+};
+
+&cpsw_emac0 {
+	phy_id = <&davinci_mdio>, <1>;
+ 	phy-mode = "mii";
+ 	dual_emac_res_vlan = <1>;
+};
+
+&cpsw_emac1 {
+	phy_id = <&davinci_mdio>, <2>;
+ 	phy-mode = "mii";
+ 	dual_emac_res_vlan = <2>;
+};
+
+&tscadc {
+	status = "okay";
+	/*tsc {
+		ti,wires = <4>;
+		ti,x-plate-resistance = <200>;
+		ti,coordinate-readouts = <5>;
+		ti,wire-config = <0x00 0x11 0x22 0x33>;
+	};*/
+
+	adc {
+		ti,adc-channels = <0 1 2 3 4 5 6 7>;
+	};
+};
+
+&mmc1 {
+	status = "okay";
+	vmmc-supply = <&vmmc_reg>;
+	bus-width = <4>;
+	pinctrl-names = "default";
+	pinctrl-0 = <&mmc1_pins_default>;
+	cd-gpios = <&gpio3 21 GPIO_ACTIVE_LOW>;
+};
+
+&edma {
+	ti,edma-xbar-event-map = /bits/ 16 <1 12
+					    2 13>;
+};
+
+
+&sham {
+	status = "okay";
+};
+
+&aes {
+	status = "okay";
+};
+
+&wkup_m3 {
+	ti,scale-data-fw = "am335x-evm-scale-data.bin";
+};
+
+&dcan0 {
+	status = "okay";	
+	pinctrl-names = "default";
+	pinctrl-0 = <&dcan0_pins_default>;
+};
+
+&dcan1 {
+	status = "okay";	
+	pinctrl-names = "default";
+	pinctrl-0 = <&dcan1_pins_default>;
+};

+ 80 - 36
board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/arch/arm/boot/dts/am335x-evm.dts

@@ -64,23 +64,36 @@
 		pinctrl-single,pins = <
 		
 			/** Offset: 0x800 */
-			/** GPIO 0 */ 
+			/** GPIO 0 */   
+			0x020 (PIN_INPUT | MUX_MODE7)			/* GPMC_AD8			=> 	GPIO0_22 */	/*ID BD1_1*/
+			0x024 (PIN_INPUT | MUX_MODE7)    			/* GPMC_AD9			=>	GPIO0_23 */	/*ID BD1_2*/
+			0x028 (PIN_INPUT | MUX_MODE7)    			/* GPMC_AD10		=>	GPIO0_26 */	/*IO BD1_1*/
+			0x02C (PIN_INPUT | MUX_MODE7)    		/* GPMC_AD11		=>	GPIO0_27 */	/*IO BD1_2*/
 			0x144 (PIN_INPUT | MUX_MODE7)    			/* RMII1_REF_CLK		=>	GPIO0_29 */	/*USB 0 OCP detection*/
 			0x1B0 (PIN_OUTPUT | MUX_MODE7)			/*XDMA_EVENT_INTR0	=>	GPIO0_19 */	/*AM_RFID_RST*/
 			0x1B4 (PIN_INPUT | MUX_MODE7)			/*XDMA_EVENT_INTR1	=>	GPIO0_20 */	/*AM_RFID_ICC*/
-			/** GPIO 1 */			
+			
+			/** GPIO 1 */
+			0x030 (PIN_INPUT | MUX_MODE7)			/* GPMC_AD12	=> 	GPIO1_12 */	/*ID BD2_1*/
+			0x034 (PIN_INPUT | MUX_MODE7)    			/* GPMC_AD13	=>	GPIO1_13 */	/*ID BD2_2*/
+			0x038 (PIN_INPUT | MUX_MODE7)    			/* GPMC_AD14	=>	GPIO1_14 */	/*IO BD2_1*/
+			0x03C (PIN_INPUT | MUX_MODE7)    		/* GPMC_AD15	=>	GPIO1_15 */	/*IO BD2_2*/
+			
 			/** GPIO 2 */
-			0x08C (PIN_OUTPUT | MUX_MODE7)			/*GPMC_CLK	=>	GPIO2_1*/	/*Speaker*/
-			0x0A0 (PIN_OUTPUT | MUX_MODE7)			/*LCD_DATA0	=>	GPIO2_6*/	/*Panel LED control-BB_LEDR1*/
-			0x0A4 (PIN_OUTPUT | MUX_MODE7)			/*LCD_DATA1	=>	GPIO2_7*/	/*Panel LED control-BB_LEDG1*/
-			0x0A8 (PIN_OUTPUT | MUX_MODE7)			/*LCD_DATA2	=>	GPIO2_8*/	/*Panel LED control-BB_LEDB1*/
-			0x0AC (PIN_OUTPUT | MUX_MODE7)			/*LCD_DATA3	=>	GPIO2_9*/	/*Panel LED control-BB_LEDR2*/
-			0x0B0 (PIN_OUTPUT | MUX_MODE7)			/*LCD_DATA4	=>	GPIO2_10*/	/*Panel LED control-BB_LEDG2*/
-			0x0B4 (PIN_OUTPUT | MUX_MODE7)			/*LCD_DATA5	=>	GPIO2_11*/	/*Panel LED control-BB_LEDB2*/
-			0x0E8 (PIN_INPUT | MUX_MODE7)			/*LCD_PCLK	=>	GPIO2_24*/	/*communication board proximity*/
-			0x0E0 (PIN_OUTPUT | MUX_MODE7)			/*LCD_VSYNC	=>	GPIO2_22*/	/*Breath LED*/
+			0x0EC (PIN_OUTPUT | MUX_MODE7)			/*LCD_AC_BIAS_EN	=>	GPIO2_25*/	/*RS-485 for module DE control*/
+			0x0E4 (PIN_OUTPUT | MUX_MODE7)			/*LCD_HSYNC		=>	GPIO2_23*/	/*RS-485 for module RE control*/
+			0x0E8 (PIN_INPUT | MUX_MODE7)			/*LCD_PCLK		=>	GPIO2_24*/	/*CCS communication board 1 proximity*/
+			0x0E0 (PIN_INPUT | MUX_MODE7)			/*LCD_VSYNC		=>	GPIO2_22*/	/*CCS communication board 2 proximity*/
+			
 			/** GPIO 3 */
-			0x1A8 (PIN_OUTPUT | MUX_MODE7)			/* MCASP0_AXR1	=>	GPIO3_20 */	/*control MCU to output CP PWM*/
+			0x194 (PIN_INPUT | MUX_MODE7)			/*MCASP0_FSX		=>	GPIO3_15*/	/*Emergency Stop button detect*/
+			0x1A0 (PIN_INPUT | MUX_MODE7)			/*MCASP0_ACLKR	=>	GPIO3_18*/	/*USB1 OCP detect*/
+			0x19C (PIN_INPUT | MUX_MODE7)			/*MCASP0_AHCLKR	=>	GPIO3_17*/	/*Emergency IO for AM3352 and STM32F407*/
+			0x190 (PIN_OUTPUT | MUX_MODE7)			/*MCASP0_ACLKX	=>	GPIO3_14*/	/*Ethernet PHY reset*/
+			0x1A4 (PIN_OUTPUT | MUX_MODE7)			/* MCASP0_FSR		=>	GPIO3_19 */	/*SMR Enable control_1*/
+			0x198 (PIN_OUTPUT | MUX_MODE7)			/* MCASP0_AXR0	=>	GPIO3_16 */	/*CSU board function OK indicator.*/
+			0x1A8 (PIN_OUTPUT | MUX_MODE7)			/* MCASP0_AXR1	=>	GPIO3_20 */	/*SMR Enable control_2*/
+			
 		>;
 	};
 	
@@ -125,14 +138,14 @@
 			0x164 (PIN_OUTPUT_PULLDOWN | MUX_MODE1)	/* ECAP0_IN_PWM0_OUT		=>	uart3_txd */
 		>;
 	};
-#if 0
+
 	uart5_pins: pinmux_uart5_pins {
 		pinctrl-single,pins = <
-			0x0C0 (PIN_INPUT_PULLUP | MUX_MODE4)		/* LCD_DATA8	=>	UART5_RXD*/
-			0x0C4 (PIN_OUTPUT_PULLDOWN | MUX_MODE4)	/* LCD_DATA9	=>	UART5_TXD*/
+			0x0C0 (PIN_OUTPUT_PULLDOWN | MUX_MODE4)		/* LCD_DATA8	=>	DUART5_TX*/
+			0x0C4 (PIN_INPUT_PULLUP | MUX_MODE4)			/* LCD_DATA9	=>	UART5_RX*/
 		>;
 	};
-#endif	
+	
 	clkout2_pin: pinmux_clkout2_pin {
 		pinctrl-single,pins = <
 			0x1b4 (PIN_OUTPUT_PULLDOWN | MUX_MODE3)	/* xdma_event_intr1.clkout2 */
@@ -183,12 +196,12 @@
 		pinctrl-single,pins = <					
 		
 			/* Slave 1 */
-			//0x108 (PIN_INPUT_PULLDOWN | MUX_MODE0)		/* MII1_COL.gmii1_col */
-			//0x10C(PIN_INPUT_PULLDOWN | MUX_MODE0)		/* MII1_CRS.MII1_CRS */
+			0x108 (PIN_INPUT_PULLUP | MUX_MODE0)		/* MII1_COL.gmii1_col */
+			0x10C(PIN_INPUT_PULLUP | MUX_MODE0)		/* MII1_CRS.MII1_CRS */
 			0x110 (PIN_INPUT_PULLUP | MUX_MODE0)		/* MII1_RX_ER.gmii1_rxerr */
-			0x118 (PIN_INPUT_PULLUP | MUX_MODE0)		/* mii1_rxdv.mii1_rxdv */
 			0x12c (PIN_INPUT_PULLUP | MUX_MODE0)		/* mii1_txclk.mii1_txclk */
 			0x130 (PIN_INPUT_PULLUP | MUX_MODE0)		/* mii1_rxclk.mii1_rxclk */
+			0x118 (PIN_INPUT_PULLUP | MUX_MODE0)		/* mii1_rxdv.mii1_rxdv */
 			0x134 (PIN_INPUT_PULLUP | MUX_MODE0)		/* mii1_rxd3.rgmii1_rd3 */
 			0x138 (PIN_INPUT_PULLUP | MUX_MODE0)		/* mii1_rxd2.rgmii1_rd2 */
 			0x13c (PIN_INPUT_PULLUP | MUX_MODE0)		/* mii1_rxd1.rgmii1_rd1 */
@@ -197,7 +210,24 @@
 			0x11c (PIN_OUTPUT_PULLDOWN | MUX_MODE0)		/* mii1_txd3.rgmii1_td3 */
 			0x120 (PIN_OUTPUT_PULLDOWN | MUX_MODE0)		/* mii1_txd2.rgmii1_td2 */
 			0x124 (PIN_OUTPUT_PULLDOWN | MUX_MODE0)		/* mii1_txd1.rgmii1_td1 */
-			0x128 (PIN_OUTPUT_PULLDOWN | MUX_MODE0)		/* mii1_txd0.rgmii1_td0 */      
+			0x128 (PIN_OUTPUT_PULLDOWN | MUX_MODE0)		/* mii1_txd0.rgmii1_td0 */      	
+			
+			/* Slave 2 */
+			AM33XX_IOPAD(0x878, PIN_INPUT_PULLUP | MUX_MODE1)					/* gpmc_ben1.mii2_col */
+			AM33XX_IOPAD(0x888, PIN_INPUT_PULLUP | MUX_MODE2)					/* GPMC_CSn3.rmii2_crs_dv*/								
+			/*AM33XX_IOPAD(0x874, PIN_INPUT_PULLUP | MUX_MODE1)*/					/* gpmc_wpn.mii2_rxerr */
+			AM33XX_IOPAD(0x858, PIN_INPUT_PULLUP | MUX_MODE1)					/* gpmc_a6.mii2_txclk */
+			AM33XX_IOPAD(0x85c, PIN_INPUT_PULLUP | MUX_MODE1)					/* gpmc_a7.mii2_rxclk */
+			AM33XX_IOPAD(0x844, PIN_INPUT_PULLUP | MUX_MODE1)					/* gpmc_a1.mii2_rxdv */
+			AM33XX_IOPAD(0x860, PIN_INPUT_PULLUP | MUX_MODE1)					/* gpmc_a8.mii2_rxd3 */
+			AM33XX_IOPAD(0x864, PIN_INPUT_PULLUP | MUX_MODE1)					/* gpmc_a9.mii2_rxd2 */
+			AM33XX_IOPAD(0x868, PIN_INPUT_PULLUP | MUX_MODE1)					/* gpmc_a10.mii2_rxd1 */
+			AM33XX_IOPAD(0x86c, PIN_INPUT_PULLUP | MUX_MODE1)					/* gpmc_a11.mii2_rxd0 */
+			AM33XX_IOPAD(0x840, PIN_OUTPUT_PULLDOWN | MUX_MODE1)				/* gpmc_a0.mii2_txen */
+			AM33XX_IOPAD(0x848, PIN_OUTPUT_PULLDOWN | MUX_MODE1)				/* gpmc_a2.mii2_txd3 */
+			AM33XX_IOPAD(0x84c, PIN_OUTPUT_PULLDOWN | MUX_MODE1)				/* gpmc_a3.mii2_txd2 */
+			AM33XX_IOPAD(0x850, PIN_OUTPUT_PULLDOWN | MUX_MODE1)				/* gpmc_a4.mii2_txd1 */
+			AM33XX_IOPAD(0x854, PIN_OUTPUT_PULLDOWN | MUX_MODE1)				/* gpmc_a5.mii2_txd0 */
 
 		>;
 	};
@@ -218,6 +248,23 @@
 			0x13c (PIN_INPUT_PULLDOWN | MUX_MODE7)
 			0x140 (PIN_INPUT_PULLDOWN | MUX_MODE7)		
 			
+			/* Slave 2 */
+			AM33XX_IOPAD(0x888, PIN_INPUT_PULLDOWN | MUX_MODE7)					/* GPMC_CSn3.rmii2_crs_dv*/	
+			AM33XX_IOPAD(0x840, PIN_INPUT_PULLDOWN | MUX_MODE7)				/* gpmc_a0.mii2_txen */
+			AM33XX_IOPAD(0x844, PIN_INPUT_PULLDOWN | MUX_MODE7)	/* gpmc_a1.mii2_rxdv */
+			AM33XX_IOPAD(0x848, PIN_INPUT_PULLDOWN | MUX_MODE7)				/* gpmc_a2.mii2_txd3 */
+			AM33XX_IOPAD(0x84c, PIN_INPUT_PULLDOWN | MUX_MODE7)			/* gpmc_a3.mii2_txd2 */
+			AM33XX_IOPAD(0x850, PIN_INPUT_PULLDOWN | MUX_MODE7)				/* gpmc_a4.mii2_txd1 */
+			AM33XX_IOPAD(0x854, PIN_INPUT_PULLDOWN | MUX_MODE7)				/* gpmc_a5.mii2_txd0 */
+			AM33XX_IOPAD(0x858, PIN_INPUT_PULLDOWN | MUX_MODE7)	/* gpmc_a6.mii2_txclk */
+			AM33XX_IOPAD(0x85c, PIN_INPUT_PULLDOWN | MUX_MODE7)	/* gpmc_a7.mii2_rxclk */
+			AM33XX_IOPAD(0x860, PIN_INPUT_PULLDOWN | MUX_MODE7)	/* gpmc_a8.mii2_rxd3 */
+			AM33XX_IOPAD(0x864, PIN_INPUT_PULLDOWN | MUX_MODE7)	/* gpmc_a9.mii2_rxd2 */
+			AM33XX_IOPAD(0x868, PIN_INPUT_PULLDOWN | MUX_MODE7)	/* gpmc_a10.mii2_rxd1 */
+			AM33XX_IOPAD(0x86c, PIN_INPUT_PULLDOWN | MUX_MODE7)	/* gpmc_a11.mii2_rxd0 */
+			/*AM33XX_IOPAD(0x874, PIN_INPUT_PULLDOWN | MUX_MODE7)*/	/* gpmc_wpn.mii2_rxerr */
+			AM33XX_IOPAD(0x878, PIN_INPUT_PULLDOWN | MUX_MODE7)	/* gpmc_ben1.mii2_col */
+			
 		>;
 	};
 
@@ -256,14 +303,14 @@
 			0x17C (PIN_INPUT_PULLDOWN | MUX_MODE2)		/* uart1_rtsn	=>	d_can0_rx */
 		>;
 	};
-#if 0	
+	
 	dcan1_pins_default: dcan1_pins_default {
 		pinctrl-single,pins = <
 			0x168 (PIN_OUTPUT_PULLUP | MUX_MODE2)		/* UART0_CTSn		=>	d_can1_tx */
 			0x16C (PIN_INPUT_PULLDOWN | MUX_MODE2)	/* UART0_RTSn		=>	d_can1_rx */
 		>;
 	};
-
+#if 0
 	ehrpwm1_pins: ehrpwm1_pins {
 		pinctrl-single,pins = <			
 			0x0C8 (PIN_OUTPUT | MUX_MODE2) /* LCD_DATA10.eHRPWM1A */
@@ -308,14 +355,14 @@
 
 	status = "okay";
 };
-#if 0
+
 &uart5 {
 	pinctrl-names = "default";
 	pinctrl-0 = <&uart5_pins>;
 
 	status = "okay";
 };
-#endif
+
 &i2c0 {
 	pinctrl-names = "default";
 	pinctrl-0 = <&i2c0_pins>;
@@ -326,11 +373,11 @@
 	tps: tps@2d {
 		reg = <0x2d>;
 	};
-
+	
 /*	rtc0: rtc@51 {
-		compatible = "nxp,pcf85063";
-		reg = <0x51>;
-	};*/
+                compatible = "nxp,pcf85063";
+                reg = <0x51>;
+        };*/	
 };
 #if 1
 &i2c1 {
@@ -344,7 +391,6 @@
                 compatible = "nxp,pcf85063";
                 reg = <0x51>;
         };
-
 };
 #endif
 &usb {
@@ -588,6 +634,7 @@
 	pinctrl-names = "default", "sleep";
 	pinctrl-0 = <&cpsw_default>;
 	pinctrl-1 = <&cpsw_sleep>;
+	dual_emac = <1>;
 	status = "okay";
 };
 
@@ -596,21 +643,19 @@
 	pinctrl-0 = <&davinci_mdio_default>;
 	pinctrl-1 = <&davinci_mdio_sleep>;
 	status = "okay";
-	//reset-gpios = <&gpio3 14 GPIO_ACTIVE_LOW>;
 };
 
 &cpsw_emac0 {
 	phy_id = <&davinci_mdio>, <1>;
  	phy-mode = "mii";
-
+ 	dual_emac_res_vlan = <1>;
 };
-#if 0
+
 &cpsw_emac1 {
 	phy_id = <&davinci_mdio>, <2>;
  	phy-mode = "mii";
-
+ 	dual_emac_res_vlan = <2>;
 };
-#endif
 
 &tscadc {
 	status = "okay";
@@ -658,10 +703,9 @@
 	pinctrl-names = "default";
 	pinctrl-0 = <&dcan0_pins_default>;
 };
-#if 0
+
 &dcan1 {
 	status = "okay";	
 	pinctrl-names = "default";
 	pinctrl-0 = <&dcan1_pins_default>;
 };
-#endif

+ 802 - 0
board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[PlugIt360]am335x-evm.dts

@@ -0,0 +1,802 @@
+/*
+ * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+/dts-v1/;
+
+#include "am33xx.dtsi"
+#include <dt-bindings/interrupt-controller/irq.h>
+
+/ {
+	model = "TI AM335x EVM";
+	compatible = "ti,am335x-evm", "ti,am33xx";
+
+	chosen {
+		stdout-path = &uart0;
+		tick-timer = &timer2;
+	};
+
+	cpus {
+		cpu@0 {
+			cpu0-supply = <&vdd1_reg>;
+		};
+	};
+
+	memory {
+		device_type = "memory";
+		reg = <0x80000000 0x10000000>; /* 256 MB */
+		reg = <0x80000000 0x20000000>; /* 512 MB */ /* +++ vern,512MB DDR ,20181030 ---*/
+	};
+
+	vbat: fixedregulator@0 {
+		compatible = "regulator-fixed";
+		regulator-name = "vbat";
+		regulator-min-microvolt = <5000000>;
+		regulator-max-microvolt = <5000000>;
+		regulator-boot-on;
+	};
+
+	lis3_reg: fixedregulator@1 {
+		compatible = "regulator-fixed";
+		regulator-name = "lis3_reg";
+		regulator-boot-on;
+	};
+
+	wlan_en_reg: fixedregulator@2 {
+		compatible = "regulator-fixed";
+		regulator-name = "wlan-en-regulator";
+		regulator-min-microvolt = <1800000>;
+		regulator-max-microvolt = <1800000>;
+
+		/* WLAN_EN GPIO for this board - Bank1, pin16 */
+		gpio = <&gpio1 16 0>;
+
+		/* WLAN card specific delay */
+		startup-delay-us = <70000>;
+		enable-active-high;
+	};
+
+	matrix_keypad: matrix_keypad@0 {
+		compatible = "gpio-matrix-keypad";
+		debounce-delay-ms = <5>;
+		col-scan-delay-us = <2>;
+
+		row-gpios = <&gpio1 25 GPIO_ACTIVE_HIGH		/* Bank1, pin25 */
+			     &gpio1 26 GPIO_ACTIVE_HIGH		/* Bank1, pin26 */
+			     &gpio1 27 GPIO_ACTIVE_HIGH>;	/* Bank1, pin27 */
+
+		col-gpios = <&gpio1 21 GPIO_ACTIVE_HIGH		/* Bank1, pin21 */
+			     &gpio1 22 GPIO_ACTIVE_HIGH>;	/* Bank1, pin22 */
+
+		linux,keymap = <0x0000008b	/* MENU */
+				0x0100009e	/* BACK */
+				0x02000069	/* LEFT */
+				0x0001006a	/* RIGHT */
+				0x0101001c	/* ENTER */
+				0x0201006c>;	/* DOWN */
+	};
+
+	gpio_keys: volume_keys@0 {
+		compatible = "gpio-keys";
+		#address-cells = <1>;
+		#size-cells = <0>;
+		autorepeat;
+
+		switch@9 {
+			label = "volume-up";
+			linux,code = <115>;
+			gpios = <&gpio0 2 GPIO_ACTIVE_LOW>;
+			gpio-key,wakeup;
+		};
+
+		switch@10 {
+			label = "volume-down";
+			linux,code = <114>;
+			gpios = <&gpio0 3 GPIO_ACTIVE_LOW>;
+			gpio-key,wakeup;
+		};
+	};
+
+	backlight {
+		compatible = "pwm-backlight";
+		pwms = <&ecap0 0 50000 0>;
+		brightness-levels = <0 51 53 56 62 75 101 152 255>;
+		default-brightness-level = <8>;
+	};
+
+	panel {
+		compatible = "ti,tilcdc,panel";
+		status = "okay";
+		pinctrl-names = "default";
+		pinctrl-0 = <&lcd_pins_s0>;
+		panel-info {
+			ac-bias           = <255>;
+			ac-bias-intrpt    = <0>;
+			dma-burst-sz      = <16>;
+			bpp               = <32>;
+			fdd               = <0x80>;
+			sync-edge         = <0>;
+			sync-ctrl         = <1>;
+			raster-order      = <0>;
+			fifo-th           = <0>;
+		};
+
+		display-timings {
+			800x480p62 {
+				clock-frequency = <30000000>;
+				hactive = <800>;
+				vactive = <480>;
+				hfront-porch = <39>;
+				hback-porch = <39>;
+				hsync-len = <47>;
+				vback-porch = <29>;
+				vfront-porch = <13>;
+				vsync-len = <2>;
+				hsync-active = <1>;
+				vsync-active = <1>;
+			};
+		};
+	};
+
+	sound {
+		compatible = "ti,da830-evm-audio";
+		ti,model = "AM335x-EVM";
+		ti,audio-codec = <&tlv320aic3106>;
+		ti,mcasp-controller = <&mcasp1>;
+		ti,codec-clock-rate = <12000000>;
+		ti,audio-routing =
+			"Headphone Jack",       "HPLOUT",
+			"Headphone Jack",       "HPROUT",
+			"LINE1L",               "Line In",
+			"LINE1R",               "Line In";
+	};
+};
+
+&am33xx_pinmux {
+	pinctrl-names = "default";
+	pinctrl-0 = <&matrix_keypad_s0 &volume_keys_s0 &clkout2_pin>;
+
+	matrix_keypad_s0: matrix_keypad_s0 {
+		pinctrl-single,pins = <
+			0x54 (PIN_OUTPUT_PULLDOWN | MUX_MODE7)	/* gpmc_a5.gpio1_21 */
+			0x58 (PIN_OUTPUT_PULLDOWN | MUX_MODE7)	/* gpmc_a6.gpio1_22 */
+			0x64 (PIN_INPUT_PULLDOWN | MUX_MODE7)	/* gpmc_a9.gpio1_25 */
+			0x68 (PIN_INPUT_PULLDOWN | MUX_MODE7)	/* gpmc_a10.gpio1_26 */
+			0x6c (PIN_INPUT_PULLDOWN | MUX_MODE7)	/* gpmc_a11.gpio1_27 */
+		>;
+	};
+
+	volume_keys_s0: volume_keys_s0 {
+		pinctrl-single,pins = <
+			0x150 (PIN_INPUT_PULLDOWN | MUX_MODE7)	/* spi0_sclk.gpio0_2 */
+			0x154 (PIN_INPUT_PULLDOWN | MUX_MODE7)	/* spi0_d0.gpio0_3 */
+		>;
+	};
+
+	i2c0_pins: pinmux_i2c0_pins {
+		pinctrl-single,pins = <
+			0x188 (PIN_INPUT_PULLUP | MUX_MODE0)	/* i2c0_sda.i2c0_sda */
+			0x18c (PIN_INPUT_PULLUP | MUX_MODE0)	/* i2c0_scl.i2c0_scl */
+		>;
+	};
+
+	i2c1_pins: pinmux_i2c1_pins {
+		pinctrl-single,pins = <
+			0x158 (PIN_INPUT_PULLUP | MUX_MODE2)	/* spi0_d1.i2c1_sda */
+			0x15c (PIN_INPUT_PULLUP | MUX_MODE2)	/* spi0_cs0.i2c1_scl */
+		>;
+	};
+
+	uart0_pins: pinmux_uart0_pins {
+		pinctrl-single,pins = <
+			0x170 (PIN_INPUT_PULLUP | MUX_MODE0)	/* uart0_rxd.uart0_rxd */
+			0x174 (PIN_OUTPUT_PULLDOWN | MUX_MODE0)	/* uart0_txd.uart0_txd */
+		>;
+	};
+
+	uart1_pins: pinmux_uart1_pins {
+		pinctrl-single,pins = <
+			0x178 (PIN_INPUT | MUX_MODE0)		/* uart1_ctsn.uart1_ctsn */
+			0x17C (PIN_OUTPUT_PULLDOWN | MUX_MODE0)	/* uart1_rtsn.uart1_rtsn */
+			0x180 (PIN_INPUT_PULLUP | MUX_MODE0)	/* uart1_rxd.uart1_rxd */
+			0x184 (PIN_OUTPUT_PULLDOWN | MUX_MODE0)	/* uart1_txd.uart1_txd */
+		>;
+	};
+
+	clkout2_pin: pinmux_clkout2_pin {
+		pinctrl-single,pins = <
+			0x1b4 (PIN_OUTPUT_PULLDOWN | MUX_MODE3)	/* xdma_event_intr1.clkout2 */
+		>;
+	};
+
+	nandflash_pins_s0: nandflash_pins_s0 {
+		pinctrl-single,pins = <
+			0x0 (PIN_INPUT_PULLUP | MUX_MODE0)	/* gpmc_ad0.gpmc_ad0 */
+			0x4 (PIN_INPUT_PULLUP | MUX_MODE0)	/* gpmc_ad1.gpmc_ad1 */
+			0x8 (PIN_INPUT_PULLUP | MUX_MODE0)	/* gpmc_ad2.gpmc_ad2 */
+			0xc (PIN_INPUT_PULLUP | MUX_MODE0)	/* gpmc_ad3.gpmc_ad3 */
+			0x10 (PIN_INPUT_PULLUP | MUX_MODE0)	/* gpmc_ad4.gpmc_ad4 */
+			0x14 (PIN_INPUT_PULLUP | MUX_MODE0)	/* gpmc_ad5.gpmc_ad5 */
+			0x18 (PIN_INPUT_PULLUP | MUX_MODE0)	/* gpmc_ad6.gpmc_ad6 */
+			0x1c (PIN_INPUT_PULLUP | MUX_MODE0)	/* gpmc_ad7.gpmc_ad7 */
+			0x70 (PIN_INPUT_PULLUP | MUX_MODE0)	/* gpmc_wait0.gpmc_wait0 */
+			0x74 (PIN_INPUT_PULLUP | MUX_MODE7)	/* gpmc_wpn.gpio0_30 */
+			0x7c (PIN_OUTPUT | MUX_MODE0)		/* gpmc_csn0.gpmc_csn0  */
+			0x90 (PIN_OUTPUT | MUX_MODE0)		/* gpmc_advn_ale.gpmc_advn_ale */
+			0x94 (PIN_OUTPUT | MUX_MODE0)		/* gpmc_oen_ren.gpmc_oen_ren */
+			0x98 (PIN_OUTPUT | MUX_MODE0)		/* gpmc_wen.gpmc_wen */
+			0x9c (PIN_OUTPUT | MUX_MODE0)		/* gpmc_be0n_cle.gpmc_be0n_cle */
+		>;
+	};
+
+	ecap0_pins: backlight_pins {
+		pinctrl-single,pins = <
+			0x164 0x0	/* eCAP0_in_PWM0_out.eCAP0_in_PWM0_out MODE0 */
+		>;
+	};
+
+	cpsw_default: cpsw_default {
+		pinctrl-single,pins = <
+			/* Slave 1 */
+			0x110 (PIN_INPUT_PULLDOWN | MUX_MODE0)		/* MII1_RX_ER.gmii1_rxerr */
+			0x118 (PIN_INPUT_PULLDOWN | MUX_MODE0)		/* mii1_rxdv.mii1_rxdv */
+			0x12c (PIN_INPUT_PULLDOWN | MUX_MODE0)		/* mii1_txclk.mii1_txclk */
+			0x130 (PIN_INPUT_PULLDOWN | MUX_MODE0)		/* mii1_rxclk.mii1_rxclk */
+			0x134 (PIN_INPUT_PULLDOWN | MUX_MODE0)		/* mii1_rxd3.rgmii1_rd3 */
+			0x138 (PIN_INPUT_PULLDOWN | MUX_MODE0)		/* mii1_rxd2.rgmii1_rd2 */
+			0x13c (PIN_INPUT_PULLDOWN | MUX_MODE0)		/* mii1_rxd1.rgmii1_rd1 */
+			0x140 (PIN_INPUT_PULLDOWN | MUX_MODE0)		/* mii1_rxd0.rgmii1_rd0 */	
+			0x114 (PIN_OUTPUT_PULLDOWN | MUX_MODE0)		/* mii1_txen.mii1_txen */
+			0x11c (PIN_OUTPUT_PULLDOWN | MUX_MODE0)		/* mii1_txd3.rgmii1_td3 */
+			0x120 (PIN_OUTPUT_PULLDOWN | MUX_MODE0)		/* mii1_txd2.rgmii1_td2 */
+			0x124 (PIN_OUTPUT_PULLDOWN | MUX_MODE0)		/* mii1_txd1.rgmii1_td1 */
+			0x128 (PIN_OUTPUT_PULLDOWN | MUX_MODE0)		/* mii1_txd0.rgmii1_td0 */      
+		>;
+	};
+
+	cpsw_sleep: cpsw_sleep {
+		pinctrl-single,pins = <
+			/* Slave 1 reset value */
+			0x110 (PIN_INPUT_PULLDOWN | MUX_MODE7)		/* MII1_RX_ER.gmii1_rxerr */
+			//0x108 (PIN_INPUT_PULLDOWN | MUX_MODE7)		/* MII1_COL.gmii1_col */
+			//0x10C (PIN_INPUT_PULLDOWN | MUX_MODE7)	/* MII1_CRS.gmii1_crs */
+			0x114 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x118 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x11c (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x120 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x124 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x128 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x12c (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x130 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x134 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x138 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x13c (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x140 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+		>;
+	};
+
+	davinci_mdio_default: davinci_mdio_default {
+		pinctrl-single,pins = <
+			/* MDIO */
+			0x148 (PIN_INPUT_PULLUP | SLEWCTRL_FAST | MUX_MODE0)	/* mdio_data.mdio_data */
+			0x14c (PIN_OUTPUT_PULLUP | MUX_MODE0)			/* mdio_clk.mdio_clk */
+		>;
+	};
+
+	davinci_mdio_sleep: davinci_mdio_sleep {
+		pinctrl-single,pins = <
+			/* MDIO reset value */
+			0x148 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x14c (PIN_INPUT_PULLDOWN | MUX_MODE7)
+		>;
+	};
+
+	#if 0
+	mmc1_pins: pinmux_mmc1_pins {
+		pinctrl-single,pins = <
+			0x160 (PIN_INPUT | MUX_MODE7) /* spi0_cs1.gpio0_6 */
+		>;
+	};
+	#endif
+	mmc1_pins_default: pinmux_mmc1_pins {
+		pinctrl-single,pins = <
+			0x0F0 (PIN_INPUT_PULLUP | MUX_MODE0)    /* mmc0_dat3.mmc0_dat3 */
+			0x0F4 (PIN_INPUT_PULLUP | MUX_MODE0)    /* mmc0_dat2.mmc0_dat2 */
+			0x0F8 (PIN_INPUT_PULLUP | MUX_MODE0)    /* mmc0_dat1.mmc0_dat1 */
+			0x0FC (PIN_INPUT_PULLUP | MUX_MODE0)    /* mmc0_dat0.mmc0_dat0 */
+			0x100 (PIN_INPUT_PULLUP | MUX_MODE0)    /* mmc0_clk.mmc0_clk */
+			0x104 (PIN_INPUT_PULLUP | MUX_MODE0)    /* mmc0_cmd.mmc0_cmd */
+			/*0x0A8 (PIN_INPUT | MUX_MODE7)*/	        /* LCD_DATA2.GPIO2_8 */
+			0x08C (PIN_INPUT | MUX_MODE7)	        /* GPMC_CLK.GPIO2_1 */
+		>;
+	};
+	mmc3_pins: pinmux_mmc3_pins {
+		pinctrl-single,pins = <
+			0x44 (PIN_INPUT_PULLUP | MUX_MODE3)	/* gpmc_a1.mmc2_dat0, INPUT_PULLUP | MODE3 */
+			0x48 (PIN_INPUT_PULLUP | MUX_MODE3)	/* gpmc_a2.mmc2_dat1, INPUT_PULLUP | MODE3 */
+			0x4C (PIN_INPUT_PULLUP | MUX_MODE3)	/* gpmc_a3.mmc2_dat2, INPUT_PULLUP | MODE3 */
+			0x78 (PIN_INPUT_PULLUP | MUX_MODE3)	/* gpmc_ben1.mmc2_dat3, INPUT_PULLUP | MODE3 */
+			0x88 (PIN_INPUT_PULLUP | MUX_MODE3)	/* gpmc_csn3.mmc2_cmd, INPUT_PULLUP | MODE3 */
+			0x8C (PIN_INPUT_PULLUP | MUX_MODE3)	/* gpmc_clk.mmc2_clk, INPUT_PULLUP | MODE3 */
+		>;
+	};
+
+	wlan_pins: pinmux_wlan_pins {
+		pinctrl-single,pins = <
+			0x40 (PIN_OUTPUT_PULLDOWN | MUX_MODE7)	/* gpmc_a0.gpio1_16 */
+			0x19C (PIN_INPUT | MUX_MODE7)		/* mcasp0_ahclkr.gpio3_17 */
+			0x1AC (PIN_OUTPUT_PULLDOWN | MUX_MODE7)	/* mcasp0_ahclkx.gpio3_21 */
+		>;
+	};
+
+	lcd_pins_s0: lcd_pins_s0 {
+		pinctrl-single,pins = <
+			0x20 (PIN_OUTPUT | MUX_MODE1)		/* gpmc_ad8.lcd_data23 */
+			0x24 (PIN_OUTPUT | MUX_MODE1)		/* gpmc_ad9.lcd_data22 */
+			0x28 (PIN_OUTPUT | MUX_MODE1)		/* gpmc_ad10.lcd_data21 */
+			0x2c (PIN_OUTPUT | MUX_MODE1)		/* gpmc_ad11.lcd_data20 */
+			0x30 (PIN_OUTPUT | MUX_MODE1)		/* gpmc_ad12.lcd_data19 */
+			0x34 (PIN_OUTPUT | MUX_MODE1)		/* gpmc_ad13.lcd_data18 */
+			0x38 (PIN_OUTPUT | MUX_MODE1)		/* gpmc_ad14.lcd_data17 */
+			0x3c (PIN_OUTPUT | MUX_MODE1)		/* gpmc_ad15.lcd_data16 */
+			0xa0 (PIN_OUTPUT | MUX_MODE0)		/* lcd_data0.lcd_data0 */
+			0xa4 (PIN_OUTPUT | MUX_MODE0)		/* lcd_data1.lcd_data1 */
+			0xa8 (PIN_OUTPUT | MUX_MODE0)		/* lcd_data2.lcd_data2 */
+			0xac (PIN_OUTPUT | MUX_MODE0)		/* lcd_data3.lcd_data3 */
+			0xb0 (PIN_OUTPUT | MUX_MODE0)		/* lcd_data4.lcd_data4 */
+			0xb4 (PIN_OUTPUT | MUX_MODE0)		/* lcd_data5.lcd_data5 */
+			0xb8 (PIN_OUTPUT | MUX_MODE0)		/* lcd_data6.lcd_data6 */
+			0xbc (PIN_OUTPUT | MUX_MODE0)		/* lcd_data7.lcd_data7 */
+			0xc0 (PIN_OUTPUT | MUX_MODE0)		/* lcd_data8.lcd_data8 */
+			0xc4 (PIN_OUTPUT | MUX_MODE0)		/* lcd_data9.lcd_data9 */
+			0xc8 (PIN_OUTPUT | MUX_MODE0)		/* lcd_data10.lcd_data10 */
+			0xcc (PIN_OUTPUT | MUX_MODE0)		/* lcd_data11.lcd_data11 */
+			0xd0 (PIN_OUTPUT | MUX_MODE0)		/* lcd_data12.lcd_data12 */
+			0xd4 (PIN_OUTPUT | MUX_MODE0)		/* lcd_data13.lcd_data13 */
+			0xd8 (PIN_OUTPUT | MUX_MODE0)		/* lcd_data14.lcd_data14 */
+			0xdc (PIN_OUTPUT | MUX_MODE0)		/* lcd_data15.lcd_data15 */
+			0xe0 (PIN_OUTPUT | MUX_MODE0)		/* lcd_vsync.lcd_vsync */
+			0xe4 (PIN_OUTPUT | MUX_MODE0)		/* lcd_hsync.lcd_hsync */
+			0xe8 (PIN_OUTPUT | MUX_MODE0)		/* lcd_pclk.lcd_pclk */
+			0xec (PIN_OUTPUT | MUX_MODE0)		/* lcd_ac_bias_en.lcd_ac_bias_en */
+		>;
+	};
+#if 0
+	am335x_evm_audio_pins: am335x_evm_audio_pins {
+		pinctrl-single,pins = <
+			0x10c (PIN_INPUT_PULLDOWN | MUX_MODE4) /* mii1_crs.mcasp1_aclkx */
+			0x110 (PIN_INPUT_PULLDOWN | MUX_MODE4) /* mii1_rxerr.mcasp1_fsx */
+			0x108 (PIN_OUTPUT_PULLDOWN | MUX_MODE4) /* mii1_col.mcasp1_axr2 */
+			0x144 (PIN_INPUT_PULLDOWN | MUX_MODE4) /* rmii1_ref_clk.mcasp1_axr3 */
+		>;
+	};
+#endif
+	dcan1_pins_default: dcan1_pins_default {
+		pinctrl-single,pins = <
+			0x168 (PIN_OUTPUT | MUX_MODE2) /* uart0_ctsn.d_can1_tx */
+			0x16c (PIN_INPUT_PULLDOWN | MUX_MODE2) /* uart0_rtsn.d_can1_rx */
+		>;
+	};
+};
+
+&uart0 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&uart0_pins>;
+
+	status = "okay";
+};
+
+&uart1 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&uart1_pins>;
+
+	status = "okay";
+};
+
+&i2c0 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&i2c0_pins>;
+
+	status = "okay";
+	clock-frequency = <400000>;
+
+	tps: tps@2d {
+		reg = <0x2d>;
+	};
+};
+
+&usb {
+	status = "okay";
+};
+
+&usb_ctrl_mod {
+	status = "okay";
+};
+
+&usb0_phy {
+	status = "okay";
+};
+
+&usb1_phy {
+	status = "okay";
+};
+
+&usb0 {
+	status = "okay";
+};
+
+&usb1 {
+	status = "okay";
+	dr_mode = "host";
+};
+
+&cppi41dma  {
+	status = "okay";
+};
+
+&i2c1 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&i2c1_pins>;
+
+	status = "okay";
+	clock-frequency = <100000>;
+
+	lis331dlh: lis331dlh@18 {
+		compatible = "st,lis331dlh", "st,lis3lv02d";
+		reg = <0x18>;
+		Vdd-supply = <&lis3_reg>;
+		Vdd_IO-supply = <&lis3_reg>;
+
+		st,click-single-x;
+		st,click-single-y;
+		st,click-single-z;
+		st,click-thresh-x = <10>;
+		st,click-thresh-y = <10>;
+		st,click-thresh-z = <10>;
+		st,irq1-click;
+		st,irq2-click;
+		st,wakeup-x-lo;
+		st,wakeup-x-hi;
+		st,wakeup-y-lo;
+		st,wakeup-y-hi;
+		st,wakeup-z-lo;
+		st,wakeup-z-hi;
+		st,min-limit-x = <120>;
+		st,min-limit-y = <120>;
+		st,min-limit-z = <140>;
+		st,max-limit-x = <550>;
+		st,max-limit-y = <550>;
+		st,max-limit-z = <750>;
+	};
+
+	tsl2550: tsl2550@39 {
+		compatible = "taos,tsl2550";
+		reg = <0x39>;
+	};
+
+	tmp275: tmp275@48 {
+		compatible = "ti,tmp275";
+		reg = <0x48>;
+	};
+
+	tlv320aic3106: tlv320aic3106@1b {
+		compatible = "ti,tlv320aic3106";
+		reg = <0x1b>;
+		status = "okay";
+
+		/* Regulators */
+		AVDD-supply = <&vaux2_reg>;
+		IOVDD-supply = <&vaux2_reg>;
+		DRVDD-supply = <&vaux2_reg>;
+		DVDD-supply = <&vbat>;
+	};
+};
+
+&lcdc {
+	status = "okay";
+};
+
+&elm {
+	status = "okay";
+};
+
+&epwmss0 {
+	status = "okay";
+
+	ecap0: ecap@48300100 {
+		status = "okay";
+		pinctrl-names = "default";
+		pinctrl-0 = <&ecap0_pins>;
+	};
+};
+
+&gpmc {
+	status = "okay";
+	pinctrl-names = "default";
+	pinctrl-0 = <&nandflash_pins_s0>;
+	/*ranges = <0 0 0x08000000 0x1000000>;*/	/* CS0: 16MB for NAND */
+	ranges = <0 0 0x08000000 0x80000000>;	/*+++ vern,NAND,20181030 ---*/
+	nand@0,0 {
+		reg = <0 0 4>; /* CS0, offset 0, IO size 4 */
+		ti,nand-ecc-opt = "bch8";
+		ti,elm-id = <&elm>;
+		nand-bus-width = <8>;
+		gpmc,device-width = <1>;
+		gpmc,sync-clk-ps = <0>;
+		gpmc,cs-on-ns = <0>;
+		gpmc,cs-rd-off-ns = <44>;
+		gpmc,cs-wr-off-ns = <44>;
+		gpmc,adv-on-ns = <6>;
+		gpmc,adv-rd-off-ns = <34>;
+		gpmc,adv-wr-off-ns = <44>;
+		gpmc,we-on-ns = <0>;
+		gpmc,we-off-ns = <40>;
+		gpmc,oe-on-ns = <0>;
+		gpmc,oe-off-ns = <54>;
+		gpmc,access-ns = <64>;
+		gpmc,rd-cycle-ns = <82>;
+		gpmc,wr-cycle-ns = <82>;
+		gpmc,wait-on-read = "true";
+		gpmc,wait-on-write = "true";
+		gpmc,bus-turnaround-ns = <0>;
+		gpmc,cycle2cycle-delay-ns = <0>;
+		gpmc,clk-activation-ns = <0>;
+		gpmc,wait-monitoring-ns = <0>;
+		gpmc,wr-access-ns = <40>;
+		gpmc,wr-data-mux-bus-ns = <0>;
+		/* MTD partition table */
+		/* All SPL-* partitions are sized to minimal length
+		 * which can be independently programmable. For
+		 * NAND flash this is equal to size of erase-block */
+		#address-cells = <1>;
+		#size-cells = <1>;
+		partition@0 {
+			label = "SPL";
+			reg = <0x00000000 0x00080000>;
+		};
+		partition@1 {
+			label = "Primary u-boot";
+			reg = <0x00080000 0x00100000>;
+		};
+		partition@2 {
+			label = "u-boot-env";
+			reg = <0x00180000 0x00080000>;
+		};
+		partition@3 {
+			label = "Secondary u-boot";
+			reg = <0x00200000 0x00100000>;
+		};
+		partition@4 {
+			label = "Primary dtb";
+			reg = <0x00300000 0x00080000>;
+		};
+		partition@5 {
+			label = "Secondary dtb";
+			reg = <0x00380000 0x00080000>;
+		};
+		partition@6 {
+			label = "Primary kernel";
+			reg = <0x00400000 0x00A00000>;
+		};
+		partition@7 {
+			label = "Secondary kernel";
+			reg = <0x00E00000 0x00A00000>;
+		};
+		partition@8 {
+			label = "Primary rootfs";
+			reg = <0x03000000 0x03000000>;
+		};
+		partition@9 {
+			label = "Secondary rootfs";
+			reg = <0x06000000 0x03000000>;
+		};
+		partition@10 {
+			label = "Primary user configuration";
+			reg = <0x09000000 0x00600000>;
+		};
+		partition@11 {
+			label = "Secondary user configuration";
+			reg = <0x09600000 0x00600000>;
+		};
+		partition@12 {
+			label = "Factory default configuration";
+			reg = <0x09C00000 0x00600000>;
+		};
+		partition@13 {
+			label = "Storage";
+			reg = <0x0A200000 0x75E00000>;
+		};
+	};
+};
+
+#include "tps65910.dtsi"
+#if 0
+&mcasp1 {
+		pinctrl-names = "default";
+		pinctrl-0 = <&am335x_evm_audio_pins>;
+
+		status = "okay";
+
+		op-mode = <0>;          /* MCASP_IIS_MODE */
+		tdm-slots = <2>;
+		/* 4 serializers */
+		serial-dir = <  /* 0: INACTIVE, 1: TX, 2: RX */
+			0 0 1 2
+		>;
+		tx-num-evt = <32>;
+		rx-num-evt = <32>;
+};
+#endif
+&tps {
+	vcc1-supply = <&vbat>;
+	vcc2-supply = <&vbat>;
+	vcc3-supply = <&vbat>;
+	vcc4-supply = <&vbat>;
+	vcc5-supply = <&vbat>;
+	vcc6-supply = <&vbat>;
+	vcc7-supply = <&vbat>;
+	vccio-supply = <&vbat>;
+
+	regulators {
+		vrtc_reg: regulator@0 {
+			regulator-always-on;
+		};
+
+		vio_reg: regulator@1 {
+			regulator-always-on;
+		};
+
+		vdd1_reg: regulator@2 {
+			/* VDD_MPU voltage limits 0.95V - 1.26V with +/-4% tolerance */
+			regulator-name = "vdd_mpu";
+			regulator-min-microvolt = <912500>;
+			regulator-max-microvolt = <1312500>;
+			regulator-boot-on;
+			regulator-always-on;
+		};
+
+		vdd2_reg: regulator@3 {
+			/* VDD_CORE voltage limits 0.95V - 1.1V with +/-4% tolerance */
+			regulator-name = "vdd_core";
+			regulator-min-microvolt = <912500>;
+			regulator-max-microvolt = <1150000>;
+			regulator-boot-on;
+			regulator-always-on;
+		};
+
+		vdd3_reg: regulator@4 {
+			regulator-always-on;
+		};
+
+		vdig1_reg: regulator@5 {
+			regulator-always-on;
+		};
+
+		vdig2_reg: regulator@6 {
+			regulator-always-on;
+		};
+
+		vpll_reg: regulator@7 {
+			regulator-always-on;
+		};
+
+		vdac_reg: regulator@8 {
+			regulator-always-on;
+		};
+
+		vaux1_reg: regulator@9 {
+			regulator-always-on;
+		};
+
+		vaux2_reg: regulator@10 {
+			regulator-always-on;
+		};
+
+		vaux33_reg: regulator@11 {
+			regulator-always-on;
+		};
+
+		vmmc_reg: regulator@12 {
+			regulator-min-microvolt = <1800000>;
+			regulator-max-microvolt = <3300000>;
+			regulator-always-on;
+		};
+	};
+};
+
+&mac {
+	pinctrl-names = "default", "sleep";
+	pinctrl-0 = <&cpsw_default>;
+	pinctrl-1 = <&cpsw_sleep>;
+	status = "okay";
+};
+
+&davinci_mdio {
+	pinctrl-names = "default", "sleep";
+	pinctrl-0 = <&davinci_mdio_default>;
+	pinctrl-1 = <&davinci_mdio_sleep>;
+	status = "okay";
+};
+
+&cpsw_emac0 {
+	phy_id = <&davinci_mdio>, <1>;
+	phy-mode = "mii";
+};
+
+&cpsw_emac1 {
+	phy_id = <&davinci_mdio>, <2>;
+	phy-mode = "mii";
+};
+
+&tscadc {
+	status = "okay";
+	tsc {
+		ti,wires = <4>;
+		ti,x-plate-resistance = <200>;
+		ti,coordinate-readouts = <5>;
+		ti,wire-config = <0x00 0x11 0x22 0x33>;
+		ti,charge-delay = <0x400>;
+	};
+
+	adc {
+		ti,adc-channels = <4 5 6 7>;
+	};
+};
+
+&mmc1 {
+	status = "okay";
+	vmmc-supply = <&vmmc_reg>;
+	bus-width = <4>;
+	pinctrl-names = "default";
+	pinctrl-0 = <&mmc1_pins_default>;
+	cd-gpios = <&gpio2 1 GPIO_ACTIVE_LOW>;
+};
+
+
+&mmc3 {
+	/* these are on the crossbar and are outlined in the
+	   xbar-event-map element */
+	dmas = <&edma 12
+		&edma 13>;
+	dma-names = "tx", "rx";
+	status = "okay";
+	vmmc-supply = <&wlan_en_reg>;
+	bus-width = <4>;
+	pinctrl-names = "default";
+	pinctrl-0 = <&mmc3_pins &wlan_pins>;
+	ti,non-removable;
+	ti,needs-special-hs-handling;
+	cap-power-off-card;
+	keep-power-in-suspend;
+
+	#address-cells = <1>;
+	#size-cells = <0>;
+	wlcore: wlcore@0 {
+		compatible = "ti,wl1835";
+		reg = <2>;
+		interrupt-parent = <&gpio3>;
+		interrupts = <17 IRQ_TYPE_LEVEL_HIGH>;
+	};
+};
+
+&edma {
+	ti,edma-xbar-event-map = /bits/ 16 <1 12
+					    2 13>;
+};
+
+&sham {
+	status = "okay";
+};
+
+&aes {
+	status = "okay";
+};
+
+&dcan1 {
+	status = "disabled";	/* Enable only if Profile 1 is selected */
+	pinctrl-names = "default";
+	pinctrl-0 = <&dcan1_pins_default>;
+};