Browse Source

2020.03.06 / Folus Wen

Actions:
1. EVSE/Projects/ Add Noodoe.

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 years ago
parent
commit
0075b50058
36 changed files with 45351 additions and 35726 deletions
  1. 78 0
      EVSE/Projects/Noodoe/Apps/Makefile
  2. 1070 0
      EVSE/Projects/Noodoe/Apps/Module_AlarmDetect.c
  3. 13 0
      EVSE/Projects/Noodoe/Apps/Module_AlarmDetect.h
  4. 358 0
      EVSE/Projects/Noodoe/Apps/Module_EventLogging.c
  5. 435 0
      EVSE/Projects/Noodoe/Apps/Module_FactoryConfig.c
  6. 2434 0
      EVSE/Projects/Noodoe/Apps/Module_InternalComm.c
  7. 67 0
      EVSE/Projects/Noodoe/Apps/Module_InternalComm.h
  8. 298 0
      EVSE/Projects/Noodoe/Apps/Module_Speaker.c
  9. 2710 0
      EVSE/Projects/Noodoe/Apps/main.c
  10. 415 0
      EVSE/Projects/Noodoe/Apps/main.h
  11. BIN
      EVSE/Projects/Noodoe/Images/MLO
  12. BIN
      EVSE/Projects/Noodoe/Images/am335x-evm.dtb
  13. BIN
      EVSE/Projects/Noodoe/Images/ramdisk.gz
  14. BIN
      EVSE/Projects/Noodoe/Images/u-boot.img
  15. BIN
      EVSE/Projects/Noodoe/Images/zImage
  16. 73 0
      Makefile
  17. 32723 32723
      board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/.tmp_System.map
  18. 1398 1412
      board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/.tmp_kallsyms1.S
  19. 1398 1412
      board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/.tmp_kallsyms2.S
  20. BIN
      board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/.tmp_vmlinux1
  21. BIN
      board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/.tmp_vmlinux2
  22. 1 1
      board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/.version
  23. 667 0
      board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/arch/arm/boot/dts/[Noodoe]am335x-evm.dts
  24. 31 13
      board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/scripts/.conmakehash.cmd
  25. 33 15
      board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/scripts/.kallsyms.cmd
  26. 36 13
      board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/scripts/.sortextable.cmd
  27. 10 5
      board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/scripts/basic/.bin2c.cmd
  28. 38 20
      board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/scripts/basic/.fixdep.cmd
  29. 33 14
      board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/scripts/mod/.mk_elfconfig.cmd
  30. 39 16
      board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/usr/.gen_init_cpio.cmd
  31. 802 0
      board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[Noodoe]am335x-evm.dts
  32. 38 20
      board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/scripts/basic/.fixdep.cmd
  33. 45 19
      board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/tools/.gen_eth_addr.cmd
  34. 45 19
      board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/tools/.img2srec.cmd
  35. 62 23
      board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/tools/.proftool.cmd
  36. 1 1
      run_gen_make_script.sh

+ 78 - 0
EVSE/Projects/Noodoe/Apps/Makefile

@@ -0,0 +1,78 @@
+-include ../../../../Rules.make
+export PATH=/bin:/sbin:/usr/bin:$(SDK_PATH_TARGET)/usr/bin:$PATH
+
+#define library variable
+Lib_Module_RFID = "-L../../../Modularization" -lModule_RFID
+Lib_Module_Upgrade = "-L../../../Modularization" -lModule_Upgrade
+Lib_SQLite3 = "-L../../../Modularization/ocppfiles" -lsqlite3
+
+all: CopyFile apps
+apps: Module_InternalComm_Task Module_FactoryConfig_Task Module_EventLogging_Task Module_AlarmDetect_Task Module_CSU_Task Module_Speaker_Task
+
+
+Module_InternalComm_Task:
+	@echo "===== Module_InternalComm_Task ==================================="
+	rm -f Module_InternalComm 
+	$(CC) -D $(Project) "-I../../" "-include../../../Modularization/Module_Upgrade.h" -O0 -g3 -Wall -c -fmessage-length=0 -o Module_InternalComm.o "./Module_InternalComm.c"
+	$(CC) -o Module_InternalComm Module_InternalComm.o ${Lib_Module_Upgrade}
+	rm -f *.o
+	mv -f Module_InternalComm ../Images/root
+	@echo \ 
+	
+Module_FactoryConfig_Task:
+	@echo "===== Module_FactoryConfig_Task =================================="
+	rm -f Module_FactoryConfig
+	gcc -D $(Project) "-I../../" -o Module_FactoryConfig "./Module_FactoryConfig.c"
+	mkdir -p /Storage/SystemLog	
+	./Module_FactoryConfig -f;true
+	cp /mnt/FactoryDefaultConfig.bin ../Images 
+	rm -f Module_FactoryConfig 
+	$(CC) -D $(Project) "-I../../" -O0 -g3 -Wall -c -fmessage-length=0 -o Module_FactoryConfig.o "./Module_FactoryConfig.c"
+	$(CC) -o Module_FactoryConfig Module_FactoryConfig.o 
+	rm -f *.o
+	mv -f Module_FactoryConfig ../Images/root
+	@echo \ 
+	
+Module_EventLogging_Task:
+	@echo "===== Module_EventLogging_Task ==================================="
+	rm -f Module_EventLogging 
+	$(CC) -D $(Project) "-I../../" -O0 -g3 -Wall -c -fmessage-length=0 -o Module_EventLogging.o "./Module_EventLogging.c"
+	$(CC) -o Module_EventLogging Module_EventLogging.o 
+	rm -f *.o
+	mv -f Module_EventLogging ../Images/root
+	@echo \ 
+	
+Module_AlarmDetect_Task:
+	@echo "===== Module_AlarmDetect_Task ===================================="
+	rm -f Module_AlarmDetect 
+	$(CC) -D $(Project) "-I../../" -O0 -g3 -Wall -c -fmessage-length=0 -o Module_AlarmDetect.o "./Module_AlarmDetect.c"
+	$(CC) -o Module_AlarmDetect Module_AlarmDetect.o 
+	rm -f *.o
+	mv -f Module_AlarmDetect ../Images/root	
+	@echo \ 
+	
+Module_CSU_Task:
+	@echo "===== Module_CSU_Task ============================================"
+	rm -f main 
+	$(CC) -D $(Project) "-I../../" "-include../../../Modularization/ocppfiles/sqlite3.h" "-include../../../Modularization/Module_Upgrade.h" "-include../../../Modularization/Module_RFID.h" -O0 -g3 -Wall -c -fmessage-length=0 -o main.o "./main.c"
+	$(CC) -o main main.o ${Lib_Module_RFID} ${Lib_Module_Upgrade} ${Lib_SQLite3}
+	rm -f *.o
+	mv -f main ../Images/root		
+	@echo \
+
+Module_Speaker_Task:
+	@echo "===== Module_Speaker_Task ===================================="
+	rm -f Module_Speaker
+	$(CC) -D $(Project) "-I../../"  -O0 -g3 -Wall -c -fmessage-length=0 -o Module_Speaker.o  "./Module_Speaker.c"
+	$(CC) -o Module_Speaker Module_Speaker.o 
+	rm -f *.o
+	mv -f Module_Speaker ../Images/root	
+	@echo \ 
+
+CopyFile: 
+	rm -rfv ../Images/root
+	mkdir -p ../Images/root
+
+
+
+	

+ 1070 - 0
EVSE/Projects/Noodoe/Apps/Module_AlarmDetect.c

@@ -0,0 +1,1070 @@
+/*
+ * Module_AlarmDetect.c
+ *
+ *  Created on: 2020年01月15日
+ *      Author: Eason Yang
+ */
+#include    <sys/types.h>
+#include    <sys/stat.h>
+#include 	<sys/time.h>
+#include 	<sys/timeb.h>
+#include 	<sys/ipc.h>
+#include 	<sys/shm.h>
+#include 	<sys/mman.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	"define.h"
+#include	"main.h"
+
+#define FILTER_SPEC			2
+
+#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)
+
+#define Debug
+#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
+#define PASS				1
+#define FAIL				0
+#define ON					1
+#define OFF					0
+
+#define SPEC_OV				275
+#define SPEC_UV				160
+#define SPEC_OC				(32*1.1)
+#define SPEC_OT				85
+
+#define HYSTERETIC_OUV		10
+#define HYSTERETIC_OT		10
+#define HYSTERETIC_OC		10
+
+struct{
+	unsigned short int	OV[3];
+	unsigned short int	UV[3];
+	unsigned short int	OC;
+	unsigned short int	OT_AMB;
+	unsigned short int	GMI;
+	unsigned short int	Short;
+	unsigned short int	Leakage;
+	unsigned short int	HandShakingTimeout;
+	unsigned short int	EmrgencyBTN;
+	unsigned short int	Relay_Welding;
+	unsigned short int	Relay_DrivingFault;
+	unsigned short int	CP_LevelFail;
+	unsigned short int	MCU_SelfTestFail;
+}Alarm_Counter[2];
+
+void trim(char *s);
+void substr(char *dest, const char* src, unsigned int start, unsigned int cnt);
+
+struct SysConfigAndInfo			*ShmSysConfigAndInfo;
+struct StatusCodeData 			*ShmStatusCodeData;
+struct OCPP16Data				*ShmOCPP16Data;
+struct Charger					*ShmCharger;
+
+
+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);
+
+	if((ShmSysConfigAndInfo->SysConfig.ModelName != NULL) && (ShmSysConfigAndInfo->SysConfig.SerialNumber != NULL) && (strlen((char*)ShmSysConfigAndInfo->SysConfig.ModelName) >= 14))
+	{
+		sprintf(Buf,"echo \"[%04d.%02d.%02d %02d:%02d:%02d] - %s\" >> /Storage/SystemLog/[%04d.%02d]%s_%s_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,
+					ShmSysConfigAndInfo->SysConfig.ModelName,
+					ShmSysConfigAndInfo->SysConfig.SerialNumber);
+	}
+	else
+	{
+		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);
+	}
+
+#ifdef SystemLogMessage
+	system(Buf);
+#endif
+
+#ifdef ConsloePrintLog
+	printf("[%04d.%02d.%02d %02d:%02d:%02d] - %s", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec, buffer);
+#endif
+
+	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;
+}
+
+//==========================================
+// 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
+    {}
+
+   	//creat ShmStatusCodeData
+   	if ((MeterSMId = shmget(ShmChargerKey, sizeof(struct Charger), 0777)) < 0)
+	{
+
+		DEBUG_ERROR("shmget ShmCharger NG\r\n");
+
+		result = FAIL;
+	}
+	else if ((ShmCharger = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+
+		DEBUG_ERROR("shmat ShmCharger NG\r\n");
+
+		result = FAIL;
+	}
+	else
+	{}
+
+   	//creat ShmOCPP16Data
+	if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
+	{
+
+		DEBUG_ERROR("shmget ShmOCPP16Data NG\r\n");
+
+		result = FAIL;
+	}
+	else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+
+		DEBUG_ERROR("shmat ShmOCPP16Data NG\r\n");
+
+		result = FAIL;
+	}
+	else
+	{}
+
+    return result;
+}
+
+//==========================================
+// Common routine
+//==========================================
+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';
+    }
+}
+
+void substr(char *dest, const char* src, unsigned int start, unsigned int cnt)
+{
+	strncpy(dest, src + start, cnt);
+	dest[cnt] = 0;
+}
+
+//==========================================
+// Main process
+//==========================================
+int main(void)
+{
+
+	if(InitShareMemory() == FAIL)
+	{
+		DEBUG_ERROR("InitShareMemory NG\n");
+
+		if(ShmStatusCodeData!=NULL)
+		{
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
+		}
+		sleep(5);
+		return FAIL;
+	}
+
+	for(;;)
+	{
+		for(int gun_index = 0;gun_index<AC_QUANTITY;gun_index++)
+		{
+			//=====================================
+			// Over voltage detection
+			//=====================================
+			if((ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_VOLTAGE))
+			{
+				if(Alarm_Counter[gun_index].OV[0] > FILTER_SPEC)
+				{
+					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == OFF))
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = ON;
+						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_VOLTAGE;
+						DEBUG_INFO("ALARM_OVER_VOLTAGE : alarm \r\n");
+					}
+				}
+				else
+				{
+					Alarm_Counter[gun_index].OV[0]++;
+				}
+			}
+			else if((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_VOLTAGE)))
+			{
+				Alarm_Counter[gun_index].OV[0] = 0;
+				if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == ON))
+				{
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = OFF;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_VOLTAGE;
+					DEBUG_INFO("ALARM_OVER_VOLTAGE : recover \r\n");
+				}
+			}
+
+			if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
+			{
+				if((ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_VOLTAGE))
+				{
+					if(Alarm_Counter[gun_index].OV[1] > FILTER_SPEC)
+					{
+						if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == OFF))
+						{
+							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = ON;
+							ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_VOLTAGE;
+							DEBUG_INFO("ALARM_OVER_VOLTAGE : alarm \r\n");
+						}
+					}
+					else
+					{
+						Alarm_Counter[gun_index].OV[1]++;
+					}
+				}
+				else if((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_VOLTAGE)))
+				{
+					Alarm_Counter[gun_index].OV[1] = 0;
+					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == ON))
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = OFF;
+						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_VOLTAGE;
+						DEBUG_INFO("ALARM_OVER_VOLTAGE : recover \r\n");
+					}
+				}
+
+				if((ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_VOLTAGE))
+				{
+					if(Alarm_Counter[gun_index].OV[2] > FILTER_SPEC)
+					{
+						if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == OFF))
+						{
+							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = ON;
+							ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_VOLTAGE;
+							DEBUG_INFO("ALARM_OVER_VOLTAGE : alarm \r\n");
+						}
+					}
+					else
+					{
+						Alarm_Counter[gun_index].OV[2]++;
+					}
+				}
+				else if((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_VOLTAGE)))
+				{
+					Alarm_Counter[gun_index].OV[2] = 0;
+					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == ON))
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = OFF;
+						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_VOLTAGE;
+						DEBUG_INFO("ALARM_OVER_VOLTAGE : recover \r\n");
+					}
+				}
+			}
+
+			//=====================================
+			// Under voltage detection
+			//=====================================
+			if((ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_UNDER_VOLTAGE))
+			{
+				if(Alarm_Counter[gun_index].UV[0] > FILTER_SPEC)
+				{
+					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == OFF))
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = ON;
+						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_UNDER_VOLTAGE;
+						DEBUG_INFO("ALARM_UNDER_VOLTAGE : alarm \r\n");
+					}
+				}
+				else
+				{
+					Alarm_Counter[gun_index].UV[0]++;
+				}
+			}
+			else if((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_UNDER_VOLTAGE)))
+			{
+				Alarm_Counter[gun_index].UV[0] = 0;
+				if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == ON))
+				{
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = OFF;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_UNDER_VOLTAGE;
+					DEBUG_INFO("ALARM_UNDER_VOLTAGE : recover \r\n");
+				}
+			}
+
+			if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
+			{
+				if((ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_UNDER_VOLTAGE))
+				{
+					if(Alarm_Counter[gun_index].UV[1] > FILTER_SPEC)
+					{
+						if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == OFF))
+						{
+							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = ON;
+							ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_UNDER_VOLTAGE;
+							DEBUG_INFO("ALARM_UNDER_VOLTAGE : alarm \r\n");
+						}
+					}
+					else
+					{
+						Alarm_Counter[gun_index].UV[1]++;
+					}
+				}
+				else if((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_UNDER_VOLTAGE)))
+				{
+					Alarm_Counter[gun_index].UV[1] = 0;
+					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == ON))
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = OFF;
+						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_UNDER_VOLTAGE;
+						DEBUG_INFO("ALARM_UNDER_VOLTAGE : recover \r\n");
+					}
+				}
+
+				if((ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_UNDER_VOLTAGE))
+				{
+					if(Alarm_Counter[gun_index].UV[2] > FILTER_SPEC)
+					{
+						if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == OFF))
+						{
+							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = ON;
+							ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_UNDER_VOLTAGE;
+							DEBUG_INFO("ALARM_UNDER_VOLTAGE : alarm \r\n");
+						}
+					}
+					else
+					{
+						Alarm_Counter[gun_index].UV[2]++;
+					}
+				}
+				else if((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_UNDER_VOLTAGE)))
+				{
+					Alarm_Counter[gun_index].UV[2] = 0;
+					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == ON))
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = OFF;
+						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_UNDER_VOLTAGE;
+						DEBUG_INFO("ALARM_UNDER_VOLTAGE : recover \r\n");
+					}
+				}
+			}
+
+			//=====================================
+			// Over current detection
+			//=====================================
+			if((ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_CURRENT))
+			{
+				if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == OFF))
+				{
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = ON;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_CURRENT;
+					DEBUG_INFO("ALARM_OVER_CURRENT : alarm \r\n");
+				}
+			}
+			else if ((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_CURRENT)))
+			{
+				if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == ON))
+				{
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = OFF;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_CURRENT;
+					DEBUG_INFO("ALARM_OVER_CURRENT : recover \r\n");
+				}
+			}
+
+			if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
+			{
+				if((ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_CURRENT))
+				{
+					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == OFF))
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = ON;
+						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_CURRENT;
+						DEBUG_INFO("ALARM_OVER_CURRENT : alarm \r\n");
+					}
+				}
+				else if ((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_CURRENT)))
+				{
+					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == ON))
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = OFF;
+						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_CURRENT;
+						DEBUG_INFO("ALARM_OVER_CURRENT : recover \r\n");
+					}
+				}
+
+				if((ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_CURRENT))
+				{
+					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == OFF))
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = ON;
+						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_CURRENT;
+						DEBUG_INFO("ALARM_OVER_CURRENT : alarm \r\n");
+					}
+				}
+				else if ((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_CURRENT)))
+				{
+					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == ON))
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = OFF;
+						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_CURRENT;
+						DEBUG_INFO("ALARM_OVER_CURRENT : recover \r\n");
+					}
+				}
+			}
+
+			//=====================================
+			// Over temperature detection
+			//=====================================
+			if((ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_TEMPERATURE))
+			{
+				if(Alarm_Counter[gun_index].OT_AMB > FILTER_SPEC)
+				{
+					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAmbientOTP == OFF))
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAmbientOTP = ON;
+						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_TEMPERATURE;
+						DEBUG_INFO("ALARM_OVER_TEMPERATURE : alarm \r\n");
+					}
+				}
+				else
+				{
+					Alarm_Counter[gun_index].OT_AMB++;
+				}
+			}
+			else if((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_TEMPERATURE)))
+			{
+				Alarm_Counter[gun_index].OT_AMB = 0;
+				if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAmbientOTP == ON))
+				{
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAmbientOTP = OFF;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_TEMPERATURE;
+					DEBUG_INFO("ALARM_OVER_TEMPERATURE : recover \r\n");
+				}
+			}
+
+			//=====================================
+			// Ground fault detection
+			//=====================================
+			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_GROUND_FAIL)
+			{
+				if(Alarm_Counter[gun_index].GMI > FILTER_SPEC)
+				{
+					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip == OFF))
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip = ON;
+						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_GROUND_FAIL;
+						DEBUG_INFO("ALARM_GROUND_FAIL : alarm \r\n");
+					}
+				}
+				else
+				{
+					Alarm_Counter[gun_index].GMI++;
+				}
+			}
+			else if (!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_GROUND_FAIL))
+			{
+				Alarm_Counter[gun_index].GMI = 0;
+				if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip == ON ))
+				{
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip = OFF;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_GROUND_FAIL;
+					DEBUG_INFO("ALARM_GROUND_FAIL : recover \r\n");
+				}
+			}
+
+			//=====================================
+			// CP level fail detection
+			//=====================================
+			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CP_ERROR)
+			{
+				if(Alarm_Counter[gun_index].CP_LevelFail > FILTER_SPEC)
+				{
+					if(ShmStatusCodeData->InfoCode.InfoEvents.bits.PilotFault == OFF)
+					{
+						ShmStatusCodeData->InfoCode.InfoEvents.bits.PilotFault = ON;
+						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_CP_ERROR;
+						DEBUG_INFO("ALARM_CP_ERROR : alarm \r\n");
+					}
+				}
+				else
+				{
+					Alarm_Counter[gun_index].CP_LevelFail++;
+				}
+			}
+			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CP_ERROR))
+			{
+				Alarm_Counter[gun_index].CP_LevelFail= 0;
+				if(ShmStatusCodeData->InfoCode.InfoEvents.bits.PilotFault == ON)
+				{
+					ShmStatusCodeData->InfoCode.InfoEvents.bits.PilotFault = OFF;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_CP_ERROR;
+					DEBUG_INFO("ALARM_CP_ERROR : recover \r\n");
+				}
+			}
+
+			//=====================================
+			// Current AC/DC leak detection
+			//=====================================
+			if((ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_LEAK_AC) ||
+			   (ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_LEAK_DC))
+			{
+				if(Alarm_Counter[gun_index].Leakage > FILTER_SPEC)
+				{
+					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip == OFF))
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip = ON;
+
+						if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_LEAK_AC)
+						{
+							ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_CURRENT_LEAK_AC;
+							ShmCharger->gun_info[gun_index].otherAlarmCode.isACLeakage = ON;
+							DEBUG_INFO("ALARM_CURRENT_LEAK_AC : alarm \r\n");
+						}
+						else if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_LEAK_DC)
+						{
+							ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_CURRENT_LEAK_DC;
+							ShmCharger->gun_info[gun_index].otherAlarmCode.isDcLeakage = ON;
+							DEBUG_INFO("ALARM_CURRENT_LEAK_DC : alarm \r\n");
+						}
+					}
+				}
+				else
+				{
+					Alarm_Counter[gun_index].Leakage++;
+				}
+			}
+			else if((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_LEAK_AC)) ||
+					(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_LEAK_DC)))
+			{
+				Alarm_Counter[gun_index].Leakage = 0;
+				if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip == ON))
+				{
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip = OFF;
+
+					if(ShmCharger->gun_info[gun_index].otherAlarmCode.isACLeakage == ON)
+					{
+						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_CURRENT_LEAK_AC;
+						ShmCharger->gun_info[gun_index].otherAlarmCode.isACLeakage = OFF;
+						DEBUG_INFO("ALARM_CURRENT_LEAK_AC : recover \r\n");
+					}
+					else if(ShmCharger->gun_info[gun_index].otherAlarmCode.isDcLeakage == ON)
+					{
+						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_CURRENT_LEAK_DC;
+						ShmCharger->gun_info[gun_index].otherAlarmCode.isDcLeakage = OFF;
+						DEBUG_INFO("ALARM_CURRENT_LEAK_DC : recover \r\n");
+					}
+				}
+			}
+
+			//=====================================
+			// MCU self test fail detection
+			//=====================================
+			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_MCU_TESTFAIL)
+			{
+				if(Alarm_Counter[gun_index].MCU_SelfTestFail > FILTER_SPEC)
+				{
+					if(ShmCharger->gun_info[gun_index].otherAlarmCode.isMcuSelfTest == OFF)
+					{
+						ShmCharger->gun_info[gun_index].otherAlarmCode.isMcuSelfTest = ON;
+						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_MCU_TESTFAIL;
+						DEBUG_INFO("ALARM_MCU_TESTFAIL : alarm \r\n");
+					}
+				}
+				else
+				{
+					Alarm_Counter[gun_index].MCU_SelfTestFail++;
+				}
+			}
+			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_MCU_TESTFAIL))
+			{
+				Alarm_Counter[gun_index].MCU_SelfTestFail = 0;
+				if(ShmCharger->gun_info[gun_index].otherAlarmCode.isMcuSelfTest == ON)
+				{
+					ShmCharger->gun_info[gun_index].otherAlarmCode.isMcuSelfTest = OFF;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_MCU_TESTFAIL;
+					DEBUG_INFO("ALARM_MCU_TESTFAIL : recover \r\n");
+				}
+			}
+
+			//=====================================
+			// Hand shaking timeout detection
+			//=====================================
+			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_HANDSHAKE_TIMEOUT)
+			{
+				if(ShmCharger->gun_info[gun_index].otherAlarmCode.isHandshakingTimeOut == OFF)
+				{
+					ShmCharger->gun_info[gun_index].otherAlarmCode.isHandshakingTimeOut  = ON;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_HANDSHAKE_TIMEOUT;
+					DEBUG_INFO("ALARM_HANDSHAKE_TIMEOUT : alarm \r\n");
+				}
+
+			}
+			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_HANDSHAKE_TIMEOUT))
+			{
+				if(ShmCharger->gun_info[gun_index].otherAlarmCode.isHandshakingTimeOut  == ON)
+				{
+					ShmCharger->gun_info[gun_index].otherAlarmCode.isHandshakingTimeOut  = OFF;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_HANDSHAKE_TIMEOUT;
+					DEBUG_INFO("ALARM_HANDSHAKE_TIMEOUT : recover \r\n");
+				}
+			}
+
+			//=====================================
+			// Emergency stop detection
+			//=====================================
+			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_EMERGENCY_STOP)
+			{
+				if(Alarm_Counter[gun_index].EmrgencyBTN > FILTER_SPEC)
+				{
+					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == OFF))
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = ON;
+						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_EMERGENCY_STOP;
+						DEBUG_INFO("ALARM_EMERGENCY_STOP : alarm \r\n");
+					}
+				}
+				else
+				{
+					Alarm_Counter[gun_index].EmrgencyBTN++;
+				}
+			}
+			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_EMERGENCY_STOP))
+			{
+				Alarm_Counter[gun_index].EmrgencyBTN = 0;
+				if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == ON))
+				{
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = OFF;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_EMERGENCY_STOP;
+					DEBUG_INFO("ALARM_EMERGENCY_STOP : recover \r\n");
+				}
+			}
+
+			//=====================================
+			// Relay welding detection
+			//=====================================
+			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_RELAY_WELDING)
+			{
+				if(Alarm_Counter[gun_index].Relay_Welding > FILTER_SPEC)
+				{
+					if((ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayWelding == OFF))
+					{
+						ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayWelding = ON;
+						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_RELAY_WELDING;
+						DEBUG_INFO("ALARM_RELAY_STATUS : alarm \r\n");
+					}
+				}
+				else
+				{
+					Alarm_Counter[gun_index].Relay_Welding++;
+				}
+			}
+			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_RELAY_WELDING))
+			{
+				Alarm_Counter[gun_index].Relay_Welding = 0;
+				if((ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayWelding == ON))
+				{
+					ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayWelding = OFF;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_RELAY_WELDING;
+					DEBUG_INFO("ALARM_RELAY_STATUS : recover \r\n");
+				}
+			}
+
+			//=====================================
+			// Relay driving fault detection
+			//=====================================
+			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_RELAY_DRIVE_FAULT)
+			{
+				if(Alarm_Counter[gun_index].Relay_DrivingFault > FILTER_SPEC)
+				{
+					if((ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayDrivingFault == OFF))
+					{
+						ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayDrivingFault = ON;
+						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_RELAY_DRIVE_FAULT;
+						DEBUG_INFO("ALARM_RELAY_DRIVE_FAULT : alarm \r\n");
+					}
+				}
+				else
+				{
+					Alarm_Counter[gun_index].Relay_DrivingFault++;
+				}
+			}
+			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_RELAY_DRIVE_FAULT))
+			{
+				Alarm_Counter[gun_index].Relay_DrivingFault = 0;
+				if((ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayDrivingFault == ON))
+				{
+					ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayDrivingFault = OFF;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_RELAY_DRIVE_FAULT;
+					DEBUG_INFO("ALARM_RELAY_DRIVE_FAULT : recover \r\n");
+				}
+			}
+
+			//=====================================
+			// Current short detection
+			//=====================================
+			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_SHORT)
+			{
+				if(Alarm_Counter[gun_index].Short > FILTER_SPEC)
+				{
+					if(ShmCharger->gun_info[gun_index].otherAlarmCode.isCurrentShort == OFF)
+					{
+						ShmCharger->gun_info[gun_index].otherAlarmCode.isCurrentShort = ON;
+						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_CURRENT_SHORT;
+						DEBUG_INFO("ALARM_CIRCUIT_SHORT : alarm \r\n");
+					}
+				}
+				else
+				{
+					Alarm_Counter[gun_index].Short++;
+				}
+			}
+			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_SHORT))
+			{
+				Alarm_Counter[gun_index].Short = 0;
+
+				if(ShmCharger->gun_info[gun_index].otherAlarmCode.isCurrentShort == ON)
+				{
+					ShmCharger->gun_info[gun_index].otherAlarmCode.isCurrentShort = OFF;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_CURRENT_SHORT;
+					DEBUG_INFO("ALARM_CIRCUIT_SHORT : recover \r\n");
+				}
+			}
+
+			//=====================================
+			// Rotatory switch detection
+			//=====================================
+			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_ROTATORY_SWITCH_FAULT)
+			{
+				if(ShmCharger->gun_info[gun_index].otherAlarmCode.isRotatorySwitch == OFF)
+				{
+					ShmCharger->gun_info[gun_index].otherAlarmCode.isRotatorySwitch = ON;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_ROTATORY_SWITCH_FAULT;
+					DEBUG_INFO("ALARM_ROTATORY_SWITCH_FAULT : alarm \r\n");
+				}
+			}
+			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_ROTATORY_SWITCH_FAULT))
+			{
+				if(ShmCharger->gun_info[gun_index].otherAlarmCode.isRotatorySwitch == ON)
+				{
+					ShmCharger->gun_info[gun_index].otherAlarmCode.isRotatorySwitch = OFF;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_ROTATORY_SWITCH_FAULT;
+					DEBUG_INFO("ALARM_ROTATORY_SWITCH_FAULT : recover \r\n");
+				}
+			}
+
+			//=====================================
+			// Leakage module detection
+			//=====================================
+			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_LEAK_MODULE_FAIL)
+			{
+				if(ShmCharger->gun_info[gun_index].otherAlarmCode.isLeakageModule == OFF)
+				{
+					ShmCharger->gun_info[gun_index].otherAlarmCode.isLeakageModule = ON;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_LEAK_MODULE_FAIL;
+
+					DEBUG_INFO("ALARM_LEAK_MODULE_FAIL : alarm \r\n");
+				}
+			}
+			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_LEAK_MODULE_FAIL))
+			{
+				if(ShmCharger->gun_info[gun_index].otherAlarmCode.isLeakageModule == ON)
+				{
+					ShmCharger->gun_info[gun_index].otherAlarmCode.isLeakageModule = OFF;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_LEAK_MODULE_FAIL;
+
+					DEBUG_INFO("ALARM_LEAK_MODULE_FAIL : recover \r\n");
+				}
+			}
+
+			//=====================================
+			// Shutter detection
+			//=====================================
+			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_SHUTTER_FAULT)
+			{
+				if(ShmCharger->gun_info[gun_index].otherAlarmCode.isShutterFail == OFF)
+				{
+					ShmCharger->gun_info[gun_index].otherAlarmCode.isShutterFail = ON;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_SHUTTER_FAULT;
+
+					DEBUG_INFO("ALARM_SHUTTER_FAULT : alarm \r\n");
+				}
+			}
+			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_SHUTTER_FAULT))
+			{
+				if(ShmCharger->gun_info[gun_index].otherAlarmCode.isShutterFail == ON)
+				{
+					ShmCharger->gun_info[gun_index].otherAlarmCode.isShutterFail = OFF;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_SHUTTER_FAULT;
+
+					DEBUG_INFO("ALARM_SHUTTER_FAULT : recover \r\n");
+				}
+			}
+
+			//=====================================
+			// Locker detection
+			//=====================================
+			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_LOCKER_FAULT)
+			{
+				if(ShmCharger->gun_info[gun_index].otherAlarmCode.isLockerFault == OFF)
+				{
+					ShmCharger->gun_info[gun_index].otherAlarmCode.isLockerFault = ON;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_LOCKER_FAULT;
+
+					DEBUG_INFO("ALARM_LOCKER_FAULT : alarm \r\n");
+				}
+			}
+			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_LOCKER_FAULT))
+			{
+				if(ShmCharger->gun_info[gun_index].otherAlarmCode.isLockerFault== ON)
+				{
+					ShmCharger->gun_info[gun_index].otherAlarmCode.isLockerFault = OFF;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_LOCKER_FAULT;
+
+					DEBUG_INFO("ALARM_LOCKER_FAULT : recover \r\n");
+				}
+			}
+
+			//=====================================
+			// Power drop detection
+			//=====================================
+			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_POWER_DROP)
+			{
+				if(ShmCharger->gun_info[gun_index].otherAlarmCode.isPowerDrop == OFF)
+				{
+					ShmCharger->gun_info[gun_index].otherAlarmCode.isPowerDrop = ON;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_POWER_DROP;
+
+					DEBUG_INFO("ALARM_POWER_DROP : alarm \r\n");
+				}
+			}
+			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_POWER_DROP))
+			{
+				if(ShmCharger->gun_info[gun_index].otherAlarmCode.isPowerDrop == ON)
+				{
+					ShmCharger->gun_info[gun_index].otherAlarmCode.isPowerDrop = OFF;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_POWER_DROP;
+
+					DEBUG_INFO("ALARM_POWER_DROP : recover \r\n");
+				}
+			}
+
+			//=====================================
+			// OCPP error code message
+			//=====================================
+			if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_OVER_VOLTAGE)
+			{
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OverVoltage");
+			}
+			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_UNDER_VOLTAGE)
+			{
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "UnderVoltage");
+			}
+			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_OVER_CURRENT)
+			{
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OverCurrentFailure");
+			}
+			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_OVER_TEMPERATURE)
+			{
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "HighTemperature");
+			}
+			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_GROUND_FAIL)
+			{
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "GroundFailure");
+			}
+			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CP_ERROR)
+			{
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "CpError");
+			}
+			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CURRENT_LEAK_AC)
+			{
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "ACLeakage");
+			}
+			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CURRENT_LEAK_DC)
+			{
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "DCLeakage");
+			}
+			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_MCU_TESTFAIL)
+			{
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "McuTestFail");
+			}
+			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_HANDSHAKE_TIMEOUT)
+			{
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "HandshakeTimeout");
+			}
+			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_EMERGENCY_STOP)
+			{
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "EmergencyStop");
+			}
+			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_RELAY_WELDING)
+			{
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "RelayWelding");
+			}
+			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_LEAK_MODULE_FAIL)
+			{
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "LeakageModuleFail");
+			}
+			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_SHUTTER_FAULT)
+			{
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "ShutterFault");
+			}
+			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_LOCKER_FAULT)
+			{
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "ConnectorLockFailure");
+			}
+			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_POWER_DROP)
+			{
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "PowerDrop");
+			}
+			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CURRENT_SHORT)
+			{
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "CircuitShort");
+			}
+			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_ROTATORY_SWITCH_FAULT)
+			{
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "RotatorySwitchFault");
+			}
+			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_RELAY_DRIVE_FAULT)
+			{
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "RelayDriveFault");
+			}
+			else
+			{
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "NoError");
+				memset(ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, 0x00, ARRAY_SIZE(ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode));
+			}
+
+			//=====================================
+			// Latch alarm recover in state A
+			//=====================================
+			if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == 1))
+			{
+				/*
+				  TODO: Recover latch alarm here
+				*/
+			}
+
+			//=====================================
+			// Latch alarm recover in state B1 and B2
+			//=====================================
+			if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == 2) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == 3))
+			{
+				/*
+				TODO: Recover latch alarm here
+				*/
+			}
+
+			//=====================================
+			// Latch alarm recover in state C
+			//=====================================
+			if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == 4))
+			{
+				/*
+				  TODO: Recover latch alarm here
+				*/
+			}
+		}
+
+		usleep(100000);
+	}
+
+	return FAIL;
+}

+ 13 - 0
EVSE/Projects/Noodoe/Apps/Module_AlarmDetect.h

@@ -0,0 +1,13 @@
+/*
+ * Module_AlarmDetect.h
+ *
+ *  Created on: 2020¦~01¤ë15¤é
+ *      Author: Eason Yang
+ */
+
+#ifndef MODULE_ALARMDETECT_H_
+#define MODULE_ALARMDETECT_H_
+
+
+
+#endif /* MODULE_ALARMDETECT_H_ */

+ 358 - 0
EVSE/Projects/Noodoe/Apps/Module_EventLogging.c

@@ -0,0 +1,358 @@
+#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 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)
+#define EVENT_INFO(format, args...) StoreEventLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+
+
+#define Debug
+#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
+#define PASS				1
+#define FAIL				-1
+
+struct SysConfigAndInfo			*ShmSysConfigAndInfo;
+struct StatusCodeData 			*ShmStatusCodeData;
+
+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);
+
+
+#ifdef SystemLogMessage
+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/Eventlog/[%04d.%02d]EventLog",
+			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);
+#ifdef SystemLogMessage
+	system(Buf);
+#endif
+
+	printf("[%04d.%02d.%02d %02d:%02d:%02d] - %s", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec, buffer);
+
+	return rc;
+}
+#endif
+
+int StoreEventLogMsg(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);
+
+	if((ShmSysConfigAndInfo->SysConfig.ModelName != NULL) && (ShmSysConfigAndInfo->SysConfig.SerialNumber != NULL) && (strlen((char*)ShmSysConfigAndInfo->SysConfig.ModelName) >= 14))
+	{
+		sprintf(Buf,"echo \"[%04d.%02d.%02d %02d:%02d:%02d] - %s\" >> /Storage/EventLog/[%04d.%02d]%s_%s_EventLog",
+					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,
+					ShmSysConfigAndInfo->SysConfig.ModelName,
+					ShmSysConfigAndInfo->SysConfig.SerialNumber);
+	}
+	else
+	{
+		sprintf(Buf,"echo \"[%04d.%02d.%02d %02d:%02d:%02d] - %s\" >> /Storage/EventLog/[%04d.%02d]EventLog",
+					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);
+	}
+
+#ifdef SystemLogMessage
+	system(Buf);
+#endif
+
+#ifdef ConsloePrintLog
+	printf("[%04d.%02d.%02d %02d:%02d:%02d] - %s", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec, buffer);
+#endif
+
+	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;
+}
+
+//=================================
+// Common routine
+//=================================
+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;
+   	 }
+    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 ShmStatusCodeData
+	if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmget ShmStatusCodeData NG");
+		#endif
+		result = FAIL;
+	}
+	else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmat ShmStatusCodeData NG");
+		#endif
+		result = FAIL;
+	}
+	else
+	{}
+	memset(ShmStatusCodeData,0,sizeof(struct StatusCodeData));
+
+    return result;
+}
+
+//================================================
+// Main process
+//================================================
+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';
+							ShmStatusCodeData->FaultCode.PreviousFaultVal[ByteCount]&=~(1<<BitCount);
+						}
+						else
+							ShmStatusCodeData->FaultCode.PreviousFaultVal[ByteCount]|=(1<<BitCount);
+						EVENT_INFO("%s\n", 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';
+							ShmStatusCodeData->AlarmCode.PreviousAlarmVal[ByteCount]&=(0<<BitCount);
+						}
+						else
+							ShmStatusCodeData->AlarmCode.PreviousAlarmVal[ByteCount]|=(1<<BitCount);
+						EVENT_INFO("%s\n", 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';
+							ShmStatusCodeData->InfoCode.PreviousInfoVal[ByteCount]&=(0<<BitCount);
+						}
+						else
+							ShmStatusCodeData->InfoCode.PreviousInfoVal[ByteCount]|=(1<<BitCount);
+						EVENT_INFO("%s\n", EventCodeTmp);
+					}
+				}
+			}
+		}
+
+		usleep(100000);
+	}
+
+	return FAIL;
+}

+ 435 - 0
EVSE/Projects/Noodoe/Apps/Module_FactoryConfig.c

@@ -0,0 +1,435 @@
+#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 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)
+
+#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;
+struct SysConfigAndInfo			*ShmSysConfigAndInfo;
+struct StatusCodeData 			*ShmStatusCodeData;
+struct FanModuleData			*ShmFanModuleData;
+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 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_%s_%s_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,
+			SysConfig.ModelName,
+			SysConfig.SerialNumber);
+#ifdef SystemLogMessage
+	system(Buf);
+#endif
+
+	printf("[%04d.%02d.%02d %02d:%02d:%02d] - %s", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec, buffer);
+
+	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;
+}
+
+//=================================
+// Common routine
+//=================================
+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)
+    {
+		DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
+
+		result = FAIL;
+	}
+    else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+    {
+    	DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
+
+    	result = FAIL;
+   	 }
+    else
+    {}
+
+   	 //creat ShmStatusCodeData
+   	 if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0)
+    {
+   		DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
+
+   		result = FAIL;
+	}
+    else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+    {
+    	DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
+
+    	result = FAIL;
+   	}
+    else
+    {}
+
+    return result;
+}
+
+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");
+}
+
+//================================================
+// Main process
+//================================================
+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 configuration
+	time_t t = time(NULL);
+	struct tm tm = *localtime(&t);
+	
+	// Initial Share Memory
+	if(InitShareMemory() == FAIL)
+	{
+		DEBUG_ERROR("InitShareMemory NG\n");
+
+		strcpy((char*)SysConfig.ModelName,"");
+		strcpy((char*)SysConfig.SerialNumber,"");
+		sleep(5);
+	}
+	else
+	{
+		memcpy((char*)SysConfig.ModelName,ShmSysConfigAndInfo->SysConfig.ModelName,ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ModelName));
+		memcpy((char*)SysConfig.SerialNumber,ShmSysConfigAndInfo->SysConfig.SerialNumber,ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber));
+
+		DEBUG_INFO("InitShareMemory OK.\r\n");
+	}
+	
+	sprintf((char*)SysConfig.SystemId, "%s%s", SysConfig.ModelName, SysConfig.SerialNumber);
+	sprintf((char*)SysConfig.SystemDateTime, "%d-%d-%d %d:%d:%d", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
+	SysConfig.AuthorisationMode = 0;	// 0:PH card	1: OCPP backend		2: PH backend	3: Free Mode
+	SysConfig.DefaultLanguage  = 0;		// 0:English	1:Big5				2: GB			3: JN		4: Français 	5: Italiano		6: Español		7: Deutsch		8: Nederland	9: Norsk	10: Suomalainen		11: Svenska		12: Pусский		13: ไทย
+	SysConfig.RfidCardNumEndian = 0;	// 0: Little endian		1: Big endian
+
+	// Charging configuration
+	SysConfig.MaxChargingEnergy = 0;	// 0: No limit	Other: 1~65536 KWH
+	SysConfig.MaxChargingPower = 0;		// 0: No limit	Other: 1~65536 KW
+	SysConfig.MaxChargingCurrent = 0;	// 0: Rating value	Other: 1~Rating A
+	SysConfig.MaxChargingDuration = 0;	// 0: No limit	Other: 1~65536 Minute
+	SysConfig.PhaseLossPolicy = 0;		// 0: Charging	1: Stop charging
+	SysConfig.AcPhaseCount = 1;			// 1: One phase	3: Three phase
+
+	// Network configuration
+	strcpy((char*)SysConfig.FtpServer, "");
+	SysConfig.Eth0Interface.EthDhcpClient = 0;
+	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.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 = 2;		// 0: Disable	1: Infrastructure client	2: Infrastructure server	3: Ad-Hoc
+	SysConfig.AthInterface.WifiRssi = 0;		// Wifi rssi value
+	SysConfig.AthInterface.WifiDhcpServer = 0;	// 0: Enable	1: Disable
+	SysConfig.AthInterface.WifiDhcpClient = 0;	// 0: Enable	1: Disable
+
+	strcpy((char*)SysConfig.TelecomInterface.TelcomApn, "internet");
+	SysConfig.TelecomInterface.TelcomSimStatus = 0;	// SIM card status
+	SysConfig.TelecomInterface.TelcomModemMode = 0;	//0: No services	1: CDMA		2: GSM/GPRS	3: WCDMA	4: GSM/WCDMA	5: TD_SCDMA		6: Unknown
+
+	// Backend configuration
+	SysConfig.BackendConnTimeout=300; 		// 300 seconds
+	SysConfig.OfflinePolicy = 0;			// 0: Local list	1: PH RFID		2: Free		3: Deny
+	SysConfig.OfflineMaxChargeEnergy = 0;	// 0: Same as MaxChargeEnergy	Other: 1~65535KWH
+	SysConfig.OfflineMaxChargeDuration = 0; // 0: Same as MaxChargeDuration Other: 1~65535 minutes
+	strcpy((char*)SysConfig.OcppServerURL, "");
+	sprintf((char*)SysConfig.ChargeBoxId, "%s%s", SysConfig.ModelName, SysConfig.SerialNumber);
+
+
+	// 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)
+	{
+		// Save factory default setting value to file
+		fd = open("/mnt/FactoryDefaultConfig.bin", O_RDWR|O_CREAT);
+		if (fd < 0)
+		{
+
+			DEBUG_ERROR("open /mnt/FactoryDefaultConfig.bin NG\r\n");
+
+			free(ptr);
+			return 0;
+		}
+		wrd=write(fd, ptr, MtdBlockSize);
+		close(fd);
+		if(wrd<MtdBlockSize)
+		{
+			DEBUG_ERROR("write /mnt/FactoryDefaultConfig.bin NG\r\n");
+
+			free(ptr);
+			return 0;
+		}
+
+		DEBUG_INFO("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)
+		{
+
+			DEBUG_ERROR("open /dev/mtdblock12 NG\r\n");
+
+			free(ptr);
+			return 0;
+		}
+		wrd=write(fd, ptr, MtdBlockSize);
+		close(fd);
+		if(wrd<MtdBlockSize)
+		{
+			DEBUG_ERROR("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)
+		{
+			DEBUG_ERROR("open /dev/mtdblock11 NG\r\n");
+
+			free(ptr);
+			return 0;
+		}
+		wrd=write(fd, ptr, MtdBlockSize);
+		close(fd);
+		if(wrd<MtdBlockSize)
+		{
+			DEBUG_ERROR("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)
+		{
+			DEBUG_ERROR("open /dev/mtdblock10 NG\r\n");
+
+			free(ptr);
+			return 0;
+		}
+		wrd=write(fd, ptr, MtdBlockSize);
+		close(fd);
+		if(wrd<MtdBlockSize)
+		{
+			DEBUG_ERROR("write /dev/mtdblock10 NG\r\n");
+
+			free(ptr);
+			return 0;
+		}
+
+		DEBUG_INFO("FactoryConfig write to flash OK\r\n");
+	}
+
+	free(ptr);
+
+	return FAIL;
+}

+ 2434 - 0
EVSE/Projects/Noodoe/Apps/Module_InternalComm.c

@@ -0,0 +1,2434 @@
+#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	"main.h"
+#include	"Module_InternalComm.h"
+
+#define FAIL_SPEC_COMM		1000
+#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
+#define PASS				1
+#define FAIL				0
+#define ON					1
+#define OFF					0
+
+//Print out level
+unsigned char PRINT_OUT_LEVEL_STATE = 0;
+#define LEVEL_1				4 // 3 Seconds
+#define LEVEL_2				8 // 6 Seconds
+
+struct SysConfigAndInfo			*ShmSysConfigAndInfo;
+struct StatusCodeData 			*ShmStatusCodeData;
+struct PrimaryMcuData			*ShmPrimaryMcuData;
+struct OCPP16Data 				*ShmOCPP16Data;
+struct Charger					*ShmCharger;
+
+uint16_t						stepIndex;
+
+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 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);
+
+	if((ShmSysConfigAndInfo->SysConfig.ModelName != NULL) && (ShmSysConfigAndInfo->SysConfig.SerialNumber != NULL) && (strlen((char*)ShmSysConfigAndInfo->SysConfig.ModelName) >= 14))
+	{
+		sprintf(Buf,"echo \"[%04d.%02d.%02d %02d:%02d:%02d] - %s\" >> /Storage/SystemLog/[%04d.%02d]%s_%s_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,
+					ShmSysConfigAndInfo->SysConfig.ModelName,
+					ShmSysConfigAndInfo->SysConfig.SerialNumber);
+	}
+	else
+	{
+		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);
+	}
+
+#ifdef SystemLogMessage
+	system(Buf);
+#endif
+
+#ifdef ConsloePrintLog
+	printf("[%04d.%02d.%02d %02d:%02d:%02d] - %s", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec, buffer);
+#endif
+
+	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;
+}
+
+//=================================
+// Common routine
+//=================================
+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;
+
+	//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;
+	}
+
+	//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;
+	}
+
+	//Initial ShmPrimaryMcuKey
+	if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), 0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmget ShmPrimaryMcuData NG\r\n");
+		#endif
+		result = FAIL;
+	}
+	else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmat ShmPrimaryMcuData NG\r\n");
+		#endif
+		result = FAIL;
+	}
+
+	//creat ShmOCPP16Data
+	if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmget ShmOCPP16Data NG");
+		#endif
+		result = FAIL;
+	}
+	else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmat ShmOCPP16Data NG");
+		#endif
+		result = FAIL;
+	}
+	else
+	{}
+
+	//Initial ShmCharger
+	if ((MeterSMId = shmget(ShmChargerKey, sizeof(struct Charger), 0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmget ShmChargerKey NG\r\n");
+		#endif
+		result = FAIL;
+	}
+	else if ((ShmCharger = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmat ShmChargerKey NG\r\n");
+		#endif
+		result = FAIL;
+	}
+
+	return result;
+}
+
+int InitComPort()
+{
+	int fd;
+	struct termios tios;
+
+	fd = open("/dev/ttyS1", O_RDWR);
+	if(fd<=0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("open /dev/ttyS1 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;		// timeout 0.5 secod
+	tios.c_lflag=0;
+	tcflush(fd, TCIFLUSH);
+	ioctl (fd, TCSETS, &tios);
+
+	return fd;
+}
+
+void ack_delay(unsigned char cmd)
+{
+	switch(cmd)
+	{
+		case CMD_UPDATE_START:
+		case CMD_UPDATE_END:
+			usleep(300000);
+			break;
+		default:
+			usleep(100000);
+			break;
+	}
+}
+
+int tranceive(int fd, unsigned char* cmd, unsigned char cmd_len, unsigned char* rx)
+{
+	int len;
+
+	tcflush(fd,TCIOFLUSH);
+	if(write(fd, cmd, cmd_len) >= cmd_len)
+	{
+		ack_delay(cmd[3]);
+		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]))
+		{
+			strncpy(Ret_Buf->Version_FW, (char *)rx+6, (rx[4] | rx[5]<<8));
+			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]))
+		{
+			strncpy(Ret_Buf->Version_HW, (char *)rx+6, (rx[4] | rx[5]<<8));
+			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))/10.0;
+			Ret_Buf->behindRelay_Voltage_C1 =(rx[8] | (rx[9]<<8))/10.0;
+			if((rx[4] | rx[5]<<8) > 4)
+			{
+				Ret_Buf->behindFuse_Voltage_C2 =(rx[10] | (rx[11]<<8))/10.0;
+				Ret_Buf->behindRelay_Voltage_C2 =(rx[12] | (rx[13]<<8))/10.0;
+			}
+			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);
+
+	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)>>1);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<(rx[4] | rx[5]<<8);idx++)
+				Ret_Buf->point[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);
+
+	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_connector=0;idx_connector<(rx[4] | rx[5]<<8);idx_connector++)
+			{
+				for(int idx=0;idx<8;idx++)
+					Ret_Buf->relay_status[idx_connector][idx] = (rx[6+idx_connector]>>idx) & 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);
+
+	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_connector=0;idx_connector<((rx[4] | rx[5]<<8)>>2);idx_connector++)
+			{
+				Ret_Buf->adc_value_positive[idx_connector] = (rx[6+(4*idx_connector)] | rx[6+(4*idx_connector)+1]<<8);
+				Ret_Buf->adc_value_negative[idx_connector] = (rx[6+(4*idx_connector)+2] | rx[6+(4*idx_connector)+3]<<8);;
+			}
+
+			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_INPUT, 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->Button[0] 			= (rx[6] >> 6) & 0x01;
+			Ret_Buf->Button[1] 			= (rx[6] >> 7) & 0x01;
+			Ret_Buf->Button_Emergency	= (rx[7] >> 0) & 0x01;
+
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+unsigned char Query_Alarm_Log(unsigned char fd, unsigned char targetAddr, Alarm_Log *Ret_Buf)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[10] = {0xaa, 0x00, targetAddr, CMD_QUERY_ALARM_LOG, 0x03, 0x00, Ret_Buf->logArea, Ret_Buf->alarmIndex&0xff, ((Ret_Buf->alarmIndex>>8)&0xff), 0x00};
+	unsigned char rx[512];
+	unsigned char chksum = Ret_Buf->logArea ^ (Ret_Buf->alarmIndex&0xff) ^ ((Ret_Buf->alarmIndex>>8)&0xff);
+	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->log[0], &rx[8], 8);
+
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+unsigned char Query_RTC(unsigned char fd, unsigned char targetAddr, Rtc *Ret_Buf)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_RTC, 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->year = ((rx[6]-'0')*1000) + ((rx[7]-'0')*100) + ((rx[8]-'0')*10) + ((rx[9]-'0')*1);
+			Ret_Buf->month = ((rx[10]-'0')*10) + ((rx[11]-'0')*1);
+			Ret_Buf->day = ((rx[12]-'0')*10) + ((rx[13]-'0')*1);
+			Ret_Buf->hour = ((rx[14]-'0')*10) + ((rx[15]-'0')*1);
+			Ret_Buf->min = ((rx[16]-'0')*10) + ((rx[17]-'0')*1);
+			Ret_Buf->sec = ((rx[18]-'0')*10) + ((rx[19]-'0')*1);
+
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+unsigned char Query_AC_MCU_Status(unsigned char fd, unsigned char targetAddr, Ac_Primary_Mcu *Ret_Buf)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_AC_STATUS, 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->cp_state = rx[6];
+			Ret_Buf->current_limit = rx[7] | (rx[8]<<0x08);
+			Ret_Buf->cp_voltage_positive = (rx[9] | (rx[10]<<0x08))/100.0;
+			Ret_Buf->cp_voltage_negtive = (rx[11] | (rx[12]<<0x08))/100.0;
+			Ret_Buf->locker_state = rx[13];
+			Ret_Buf->relay_state = rx[14];
+			Ret_Buf->shutter_state = rx[15];
+			Ret_Buf->meter_state = rx[16];
+			Ret_Buf->pp_state = rx[17];
+			Ret_Buf->rating_current = rx[18];
+			Ret_Buf->rotatory_switch = (rx[19] & 0x0F);
+
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+unsigned char Query_AC_MCU_Alarm(unsigned char fd, unsigned char targetAddr, Ac_Primary_Mcu_Alarm *Ret_Buf)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_AC_ALARM, 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]))
+		{
+			//rx[6]
+			Ret_Buf->bits.OVP = (((rx[6]>>0)&0x01)?1:0);
+			Ret_Buf->bits.UVP = (((rx[6]>>1)&0x01)?1:0);
+			Ret_Buf->bits.OCP = (((rx[6]>>2)&0x01)?1:0);
+			Ret_Buf->bits.OTP = (((rx[6]>>3)&0x01)?1:0);
+			Ret_Buf->bits.gmi_fault = (((rx[6]>>4)&0x01)?1:0);
+			Ret_Buf->bits.cp_fault = (((rx[6]>>5)&0x01)?1:0);
+			Ret_Buf->bits.ac_leak = (((rx[6]>>6)&0x01)?1:0);
+			Ret_Buf->bits.dc_leak = (((rx[6]>>7)&0x01)?1:0);
+
+			//rx[7]
+			Ret_Buf->bits.mcu_selftest_fail = (((rx[7]>>0)&0x01)?1:0);
+			Ret_Buf->bits.handshaking_timeout = (((rx[7]>>1)&0x01)?1:0);
+			Ret_Buf->bits.emergency_stop = (((rx[7]>>2)&0x01)?1:0);
+			Ret_Buf->bits.relay_welding = (((rx[7]>>3)&0x01)?1:0);
+			Ret_Buf->bits.leak_module_fail = (((rx[7]>>4)&0x01)?1:0);
+			Ret_Buf->bits.shutter_fault = (((rx[7]>>5)&0x01)?1:0);
+			Ret_Buf->bits.locker_fault = (((rx[7]>>6)&0x01)?1:0);
+			Ret_Buf->bits.power_drop = (((rx[7]>>7)&0x01)?1:0);
+
+			//rx[8] 3~7bits reserved
+			Ret_Buf->bits.circuit_short = (((rx[8]>>0)&0x01)?1:0);
+			Ret_Buf->bits.set_circuit = (((rx[8]>>1)&0x01)?1:0);
+			Ret_Buf->bits.relay_drive_fault = (((rx[8]>>2)&0x01)?1:0);
+
+			//rx[9] 0~7bits reserved
+
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+unsigned char Query_Present_OutputCurrent(unsigned char fd, unsigned char targetAddr, Presentoutputcurrent *Ret_Buf)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_PRESENT_OUTPUTCURRENT, 0x00, 0x00, 0x00};
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+	if(len > 0)
+	{
+		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->L1N_L12[0] = (rx[6] | (rx[7]<<8))/10.0;
+			Ret_Buf->L2N_L23[0] = (rx[8] | (rx[9]<<8))/10.0;
+			Ret_Buf->L3N_L31[0] = (rx[10] | (rx[11]<<8))/10.0;
+			Ret_Buf->L1N_L12[1] = (rx[12] | (rx[13]<<8))/10.0;
+			Ret_Buf->L2N_L23[1] = (rx[14] | (rx[15]<<8))/10.0;
+			Ret_Buf->L3N_L31[1] = (rx[16] | (rx[17]<<8))/10.0;
+
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+unsigned char Query_Ble_Config(unsigned char fd, unsigned char targetAddr, Ble_Config_Data *Ret_Buf)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_BLE_CONFIG_DATA, 0x00, 0x00, 0x00};
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+	if(len > 0)
+	{
+		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->isLogin = (rx[6]?0x01:0x00);
+			Ret_Buf->isRequestStart = (rx[7]?0x01:0x00);
+			Ret_Buf->isRequestStop = (rx[8]?0x01:0x00);
+
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+unsigned char Query_Ble_Central_ID(unsigned char fd, unsigned char targetAddr, Ble_Login_Central_Id *Ret_Buf)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_BLE_CENTRAL_ID, 0x00, 0x00, 0x00};
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+	if(len > 0)
+	{
+		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]))
+		{
+			memset(Ret_Buf->id, 0x00, ARRAY_SIZE(Ret_Buf->id));
+			memcpy(&Ret_Buf->id[0], &rx[6], (rx[4] | (rx[5]<<8)));
+
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+unsigned char Query_Power_Consumption(unsigned char fd, unsigned char targetAddr, Power_Consumption *Ret_Buf)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_POWER_CONSUMPTION, 0x00, 0x00, 0x00};
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+	if(len > 0)
+	{
+		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-> power_consumption = ((uint32_t)rx[6] | (((uint32_t)rx[7])<<8) | (((uint32_t)rx[8])<<16) | (((uint32_t)rx[9])<<24));
+			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;
+
+	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] == 0x01))
+		{
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+unsigned char Config_Serial_Number(unsigned char fd, unsigned char targetAddr, Evse_Id *Set_Buf)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[27] = {0xaa, 0x00, targetAddr, CMD_CONFIG_SERIAL_NUMBER, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 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[14], &Set_Buf->serial_number[0], ARRAY_SIZE(Set_Buf->serial_number));
+
+	for(int idx=0;idx<(tx[4] | tx[5]<<8);idx++)
+		chksum ^= tx[6+idx];
+	tx[26] = 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] == 0x01))
+		{
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+unsigned char Config_Model_Name(unsigned char fd, unsigned char targetAddr, Evse_Id *Set_Buf)
+{
+	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], &Set_Buf->model_name[0], ARRAY_SIZE(Set_Buf->model_name));
+
+	for(int idx=0;idx<(tx[4] | tx[5]<<8);idx++)
+		chksum ^= tx[6+idx];
+	tx[20] = 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] == 0x01))
+		{
+			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[9] = {0xaa, 0x00, targetAddr, CMD_CONFIG_RELAY_OUTPUT, 0x02, 0x00, 0x00, 0x00, 0x00};
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+
+	for(int idx_connector=0;idx_connector<2;idx_connector++)
+		for(int idx = 0;idx<8;idx++)
+			tx[6+idx_connector] |= ((Set_Buf->relay_status[idx_connector][idx]?0x01:0x00)<<idx);
+
+	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] == 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_RTC(unsigned char fd, unsigned char targetAddr, Rtc *Set_Buf)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[21];
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+
+
+	tx[0] = 0xaa;
+	tx[1] = 0x00;
+	tx[2] = targetAddr;
+	tx[3] = CMD_CONFIG_RTC;
+	tx[4] = 0x0e;
+	tx[5] = 0x00;
+	tx[6] = ((Set_Buf->year)/1000)+'0';
+	tx[7] = ((Set_Buf->year)/100%10)+'0';
+	tx[8] = ((Set_Buf->year)/10%10)+'0';
+	tx[9] = ((Set_Buf->year)%10)+'0';
+	tx[10] = ((Set_Buf->month)/10)+'0';
+	tx[11] = ((Set_Buf->month)%10)+'0';
+	tx[12] = ((Set_Buf->day)/10)+'0';
+	tx[13] = ((Set_Buf->day)%10)+'0';
+	tx[14] = ((Set_Buf->hour)/10)+'0';
+	tx[15] = ((Set_Buf->hour)%10)+'0';
+	tx[16] = ((Set_Buf->min)/10)+'0';
+	tx[17] = ((Set_Buf->min)%10)+'0';
+	tx[18] = ((Set_Buf->sec)/10)+'0';
+	tx[19] = ((Set_Buf->sec)%10)+'0';
+
+	for(int idx=0;idx<(tx[4] | tx[5]<<8);idx++)
+		chksum ^= tx[6+idx];
+	tx[20] = 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] == 0x01))
+		{
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+unsigned char Config_AC_MCU_LED(unsigned char fd, unsigned char targetAddr, Ac_Primary_Mcu_Led *Set_Buf)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[12] ;
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+
+	tx[0] = 0xaa;
+	tx[1] = 0x00;
+	tx[2] = targetAddr;
+	tx[3] = CMD_CONFIG_AC_LED;
+	tx[4] = 0x05;
+	tx[5] = 0x00;
+	tx[6] = Set_Buf->mode;
+	tx[7] = ((Set_Buf->alarm_code>>0)&0xff);
+	tx[8] = ((Set_Buf->alarm_code>>8)&0xff);
+	tx[9] = ((Set_Buf->alarm_code>>16)&0xff);
+	tx[10] = ((Set_Buf->alarm_code>>24)&0xff);
+
+	for(int idx=0;idx<(tx[4] | tx[5]<<8);idx++)
+		chksum ^= tx[6+idx];
+	tx[11] = 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] == 0x01))
+		{
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+unsigned char Config_AC_MCU_LEGACY_REQUEST(unsigned char fd, unsigned char targetAddr, Legacy_Request *Set_Buf)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[9];
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+
+	tx[0] = 0xaa;
+	tx[1] = 0x00;
+	tx[2] = targetAddr;
+	tx[3] = CMD_CONFIG_MCU_MODE;
+	tx[4] = 0x02;
+	tx[5] = 0x00;
+	tx[6] = Set_Buf->isLegacyRequest;
+	tx[7] = 0x00;
+
+	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] == 0x01))
+		{
+			result = PASS;
+
+		}
+	}
+
+	return result;
+}
+
+unsigned char Config_AC_MCU_RESET_REQUEST(unsigned char fd, unsigned char targetAddr, Mcu_Reset_Request *Set_Buf)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[9];
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+
+	tx[0] = 0xaa;
+	tx[1] = 0x00;
+	tx[2] = targetAddr;
+	tx[3] = CMD_CONFIG_MCU_RESET_REQUEST;
+	tx[4] = 0x02;
+	tx[5] = 0x00;
+	tx[6] = Set_Buf->isMcuResetRequest;
+	tx[7] = 0x00;
+
+	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] == 0x01))
+		{
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+unsigned char Query_AC_GUN_PLUGIN_TIMES(unsigned char fd, unsigned char targetAddr, Gun_Plugin_Times *Ret_Buf)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_GUN_PLUGIN_TIMES, 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-> GunPluginTimes = ((uint32_t)rx[6] | (((uint32_t)rx[7])<<8) | (((uint32_t)rx[8])<<16) | (((uint32_t)rx[9])<<24));
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+unsigned char Config_AC_MaxCurrent_And_CpPwmDuty(unsigned char fd, unsigned char targetAddr, Ac_Primary_Mcu_Cp_Pwm_Duty*Set_Buf)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[8];
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+
+	tx[0] = 0xaa;
+	tx[1] = 0x00;
+	tx[2] = targetAddr;
+	tx[3] = CMD_CONFIG_CURRENT_LINIT;
+	tx[4] = 0x01;
+	tx[5] = 0x00;
+	tx[6] = Set_Buf->max_current;
+
+	for(int idx=0;idx<(tx[4] | tx[5]<<8);idx++)
+			chksum ^= tx[6+idx];
+	tx[7] = 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] == 0x01))
+		{
+			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_ABOARD, 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_END, 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] == 0x01))
+		{
+			result = PASS;
+		}
+	}
+	return result;
+}
+
+
+//================================================
+// Main process
+//================================================
+int main(void)
+{
+	int Uart1Fd;
+
+	unsigned short int failCount[2] = {0,0};
+	unsigned short int printOutCount[2] = {0,0};
+
+	if(InitShareMemory() == FAIL)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("InitShareMemory NG\n");
+		#endif
+		if(ShmStatusCodeData!=NULL)
+		{
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
+		}
+		sleep(5);
+		return 0;
+	}
+	else
+	{
+		DEBUG_INFO("InitShareMemory OK.\r\n");
+	}
+
+	Uart1Fd=InitComPort();
+	if(Uart1Fd<0)
+	{
+		DEBUG_ERROR("InitComPort NG\n");
+		if(ShmStatusCodeData!=NULL)
+		{
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
+		}
+		sleep(5);
+		return 0;
+	}
+	else
+	{
+		DEBUG_INFO("ttyS1 port open success.\r\n");
+	}
+
+	for(;;)
+	{
+		for(int gun_index=0;gun_index<AC_QUANTITY;gun_index++)
+		{
+			/*
+			 * Polling loop
+			 */
+			if((stepIndex%2)==0)
+			{
+				/*
+				 * High priority communication
+				 */
+
+				//===============================
+				// Case 1 : Config primary MCU LED
+				//===============================
+				ShmCharger->gun_info[gun_index].primaryMcuLed.alarm_code = ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode;
+				if(Config_AC_MCU_LED(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].primaryMcuLed))
+				{
+					failCount[gun_index] = 0;
+				}
+				else
+				{
+					DEBUG_WARN("MCU-%d set led fail...%d\r\n", gun_index, failCount[gun_index]);
+					if(failCount[gun_index]<1000)
+					{
+						failCount[gun_index]++;
+					}
+				}
+
+				//===============================
+				// Case 2 : Config primary Legacy request
+				//===============================
+				if(Config_AC_MCU_LEGACY_REQUEST(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1),&ShmCharger->gun_info[gun_index].legacyRequest))
+				{
+					failCount[gun_index] = 0;
+				}
+				else
+				{
+					DEBUG_WARN("MCU-%d set relay request fail...%d\r\n", gun_index, failCount[gun_index]);
+					if(failCount[gun_index]<1000)
+					{
+						failCount[gun_index]++;
+					}
+				}
+
+				//===============================
+				// Case 3 : Query primary MCU status
+				//===============================
+				if(Query_AC_MCU_Status(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].primaryMcuState))
+				{
+					ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState = ShmCharger->gun_info[gun_index].primaryMcuState.cp_state;
+					ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotDuty = (ShmCharger->gun_info[gun_index].primaryMcuState.current_limit>51?(unsigned char)((ShmCharger->gun_info[gun_index].primaryMcuState.current_limit/2.5)+64):(unsigned char)(ShmCharger->gun_info[gun_index].primaryMcuState.current_limit/0.6));
+					ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotVoltage = ShmCharger->gun_info[gun_index].primaryMcuState.cp_voltage_positive;
+					ShmCharger->gun_info[gun_index].PilotVoltage.PilotVoltagePositive = ShmCharger->gun_info[gun_index].primaryMcuState.cp_voltage_positive;
+					ShmCharger->gun_info[gun_index].PilotVoltage.PilotVoltageNegative = ShmCharger->gun_info[gun_index].primaryMcuState.cp_voltage_negtive;
+
+					failCount[gun_index] = 0;
+				}
+				else
+				{
+					DEBUG_WARN("MCU-%d get status fail...%d\r\n", gun_index, failCount[gun_index]);
+					if(failCount[gun_index]<1000)
+					{
+						failCount[gun_index]++;
+					}
+				}
+
+				//===============================
+				// Case 4 : Query primary MCU Alarm code
+				//===============================
+				if(Query_AC_MCU_Alarm(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].primaryMcuAlarm))
+				{
+					//DEBUG_INFO("MCU-%d get alarm code success.\r\n",gun_index);
+
+					//================================================
+					// Byte[6]
+					// Byte[7]
+					// Byte[8] Alarm code 3~7 bits Reserved
+					// Byte[9] Alarm code 0~7 bits Reserved
+					//================================================
+
+					//================================================
+					// Byte[6]
+					//================================================
+					if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OVP == 0x01)
+						ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode |= 1<<0;
+					else
+						ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode &= ~(1<<0);
+
+					if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.UVP == 0x01)
+						ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode |= 1<<1;
+					else
+						ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode &= ~(1<<1);
+
+					if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OCP == 0x01)
+						ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode |= 1<<2;
+					else
+						ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode &= ~(1<<2);
+
+					if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OTP == 0x01)
+						ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode |= 1<<3;
+					else
+						ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode &= ~(1<<3);
+
+					if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.gmi_fault == 0x01)
+						ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode |= 1<<4;
+					else
+						ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode &= ~(1<<4);
+
+					if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.cp_fault == 0x01)
+						ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode |= 1<<5;
+					else
+						ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode &= ~(1<<5);
+
+					if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.ac_leak == 0x01)
+						ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode |= 1<<6;
+					else
+						ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode &= ~(1<<6);
+
+					if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.dc_leak == 0x01)
+						ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode |= 1<<7;
+					else
+						ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode &= ~(1<<7);
+
+					//================================================
+					// Byte[7]
+					//================================================
+					if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.mcu_selftest_fail == 0x01)
+						ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode |= 1<<8;
+					else
+						ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode &= ~(1<<8);
+
+					if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.handshaking_timeout == 0x01)
+						ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode |= 1<<9;
+					else
+						ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode &= ~(1<<9);
+
+					if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.emergency_stop == 0x01)
+						ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode |= 1<<10;
+					else
+						ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode &= ~(1<<10);
+
+					if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.relay_welding == 0x01)
+						ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode |= 1<<11;
+					else
+						ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode &= ~(1<<11);
+
+					if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.leak_module_fail == 0x01)
+						ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode |= 1<<12;
+					else
+						ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode &= ~(1<<12);
+
+					if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.shutter_fault == 0x01)
+						ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode |= 1<<13;
+					else
+						ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode &= ~(1<<13);
+
+					if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.locker_fault == 0x01)
+						ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode |= 1<<14;
+					else
+						ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode &= ~(1<<14);
+
+					if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.power_drop == 0x01)
+						ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode |= 1<<15;
+					else
+						ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode &= ~(1<<15);
+
+					//================================================
+					// Byte[8]
+					//================================================
+					if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.circuit_short == 0x01)
+						ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode |= 1<<16;
+					else
+						ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode &= ~(1<<16);
+
+					if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.set_circuit == 0x01)
+						ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode |= 1<<17;
+					else
+						ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode &= ~(1<<17);
+
+					if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.relay_drive_fault == 0x01)
+						ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode |= 1<<18;
+					else
+						ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode &= ~(1<<18);
+
+					//================================================
+					// Byte[9] Reserved
+					//================================================
+
+					failCount[gun_index] = 0;
+				}
+				else
+				{
+					DEBUG_WARN("MCU-%d get alarm fail...%d\r\n", gun_index, failCount[gun_index]);
+					if(failCount[gun_index]<1000)
+					{
+						failCount[gun_index]++;
+					}
+				}
+
+				//===============================
+				// Case 5 : Query primary MCU BLE config
+				//===============================
+				if(Query_Ble_Config(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].bleConfigData))
+				{
+					ShmSysConfigAndInfo->SysConfig.Bluetooth.isLogin = ShmCharger->gun_info[gun_index].bleConfigData.isLogin;
+					ShmSysConfigAndInfo->SysConfig.Bluetooth.isRequestStart = ShmCharger->gun_info[gun_index].bleConfigData.isRequestStart;
+					ShmSysConfigAndInfo->SysConfig.Bluetooth.isRequestStop = ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop;
+
+					failCount[gun_index] = 0;
+				}
+				else
+				{
+					DEBUG_WARN("MCU-%d get ble config fail...%d\r\n", gun_index, failCount[gun_index]);
+					if(failCount[gun_index]<1000)
+					{
+						failCount[gun_index]++;
+					}
+				}
+
+				//===============================
+				// Case 6 : Query primary MCU ble login id
+				//===============================
+				if(Query_Ble_Central_ID(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].bleLoginCentralId))
+				{
+					memcpy(ShmSysConfigAndInfo->SysConfig.Bluetooth.LoginCentralID, ShmCharger->gun_info[gun_index].bleLoginCentralId.id, sizeof ShmSysConfigAndInfo->SysConfig.Bluetooth.LoginCentralID);
+
+					failCount[gun_index] = 0;
+				}
+				else
+				{
+					DEBUG_WARN("MCU-%d get ble login central id fail...%d\r\n", gun_index, failCount[gun_index]);
+					if(failCount[gun_index]<1000)
+					{
+						failCount[gun_index]++;
+					}
+				}
+
+				//===============================
+				// Case 7 : Config primary MCU reset request
+				//===============================
+				if(ShmCharger->gun_info[gun_index].mcuResetRequest.isMcuResetRequest == ON)
+				{
+					if(Config_AC_MCU_RESET_REQUEST(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].mcuResetRequest) == PASS)
+					{
+						DEBUG_INFO("**************************************************\r\n");
+						DEBUG_INFO("********* High priority polling : Case 7 *********\r\n");
+						DEBUG_INFO("**************************************************\r\n");
+						DEBUG_INFO("MCU-%d set MCU reset Request : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].mcuResetRequest.isMcuResetRequest);
+
+						ShmCharger->gun_info[gun_index].mcuResetRequest.isMcuResetRequest = OFF;
+
+						failCount[gun_index] = 0;
+					}
+					else
+					{
+						DEBUG_WARN("MCU-%d get MCU reset fail...%d\r\n", gun_index, failCount[gun_index]);
+						if(failCount[gun_index]<1000)
+						{
+							failCount[gun_index]++;
+						}
+					}
+				}
+
+				//==========================================================
+				// High priority polling log print out
+				//==========================================================
+				if(ShmCharger->gun_info[gun_index].legacyRequest.isLegacyRequest == ON)
+				{
+					PRINT_OUT_LEVEL_STATE = LEVEL_1;
+					if(printOutCount[gun_index]>LEVEL_1)
+						printOutCount[gun_index] = 0;
+				}
+				else
+				{
+					PRINT_OUT_LEVEL_STATE = LEVEL_2;
+					if(printOutCount[gun_index]>LEVEL_2)
+						printOutCount[gun_index] = 0;
+				}
+
+				if(printOutCount[gun_index] == PRINT_OUT_LEVEL_STATE)
+				{
+					//===============================
+					// Config primary MCU LED
+					//===============================
+					DEBUG_INFO("**************************************************\r\n");
+					DEBUG_INFO("********* High priority polling : Case 1 *********\r\n");
+					DEBUG_INFO("**************************************************\r\n");
+					DEBUG_INFO("MCU-%d set Led mode : %d\r\n",gun_index, ShmCharger->gun_info[gun_index].primaryMcuLed.mode);
+					DEBUG_INFO("MCU-%d set Alarm code : %x\r\n",gun_index, ShmCharger->gun_info[gun_index].primaryMcuLed.alarm_code);
+
+					//===============================
+					// Config primary Legacy request
+					//===============================
+					DEBUG_INFO("**************************************************\r\n");
+					DEBUG_INFO("********* High priority polling : Case 2 *********\r\n");
+					DEBUG_INFO("**************************************************\r\n");
+					DEBUG_INFO("MCU-%d set relay request : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].legacyRequest.isLegacyRequest);
+
+					//===============================
+					// Query primary MCU status
+					//===============================
+					DEBUG_INFO("**************************************************\r\n");
+					DEBUG_INFO("********* High priority polling : Case 3 *********\r\n");
+					DEBUG_INFO("**************************************************\r\n");
+					DEBUG_INFO("MCU-%d get Pilot State : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.cp_state);
+					DEBUG_INFO("MCU-%d get Pilot Duty : %.2f\r\n", gun_index, (float)ShmCharger->gun_info[gun_index].primaryMcuState.current_limit);
+					DEBUG_INFO("MCU-%d get Pilot Voltage Positive : %.2f\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.cp_voltage_positive);
+					DEBUG_INFO("MCU-%d get Pilot Voltage Negative : %.2f\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.cp_voltage_negtive);
+					DEBUG_INFO("MCU-%d get Relay State : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.relay_state);
+					DEBUG_INFO("MCU-%d get Rating Current : %.2f\r\n", gun_index, (float)ShmCharger->gun_info[gun_index].primaryMcuState.rating_current);
+					DEBUG_INFO("MCU-%d get Rotary switch : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.rotatory_switch);
+
+					/*
+					DEBUG_INFO("MCU-%d get Locker State : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.locker_state);
+					DEBUG_INFO("MCU-%d get Shutter State : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.shutter_state);
+					DEBUG_INFO("MCU-%d get Meter State : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.meter_state);
+					DEBUG_INFO("MCU-%d get PP State : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.pp_state);
+										*/
+
+					//===============================
+					// Query primary MCU Alarm code
+					//===============================
+					if((ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode>0))
+					{
+						DEBUG_INFO("**************************************************\r\n");
+						DEBUG_INFO("********* High priority polling : Case 4 *********\r\n");
+						DEBUG_INFO("**************************************************\r\n");
+						DEBUG_INFO("MCU-%d get OVP : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OVP);
+						DEBUG_INFO("MCU-%d get UVP : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.UVP);
+						DEBUG_INFO("MCU-%d get OCP : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OCP);
+						DEBUG_INFO("MCU-%d get OTP : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OTP);
+						DEBUG_INFO("MCU-%d get gmi_fault : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.gmi_fault);
+						DEBUG_INFO("MCU-%d get cp_fault : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.cp_fault);
+						DEBUG_INFO("MCU-%d get ac_leak : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.ac_leak);
+						DEBUG_INFO("MCU-%d get dc_leak : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.dc_leak);
+						DEBUG_INFO("MCU-%d get mcu_selftest_fail : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.mcu_selftest_fail);
+						DEBUG_INFO("MCU-%d get handshaking_timeout : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.handshaking_timeout);
+						DEBUG_INFO("MCU-%d get emergency_stop : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.emergency_stop);
+						DEBUG_INFO("MCU-%d get relay_welding : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.relay_welding);
+						DEBUG_INFO("MCU-%d get leak_module_fail : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.leak_module_fail);
+						DEBUG_INFO("MCU-%d get shutter_fault : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.shutter_fault);
+						DEBUG_INFO("MCU-%d get locker_fault : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.locker_fault);
+						DEBUG_INFO("MCU-%d get power_drop : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.power_drop);
+						DEBUG_INFO("MCU-%d get circuit_short : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.circuit_short);
+						DEBUG_INFO("MCU-%d get set_circuit : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.set_circuit);
+						DEBUG_INFO("MCU-%d get relay_drive_fault : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.relay_drive_fault);
+						DEBUG_INFO("MCU-%d get InputAlarmCode : %x\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode);
+					}
+
+					//===============================
+					// Query primary MCU BLE config
+					//===============================
+					if(ShmCharger->gun_info[gun_index].bleConfigData.isLogin == ON)
+					{
+						DEBUG_INFO("**************************************************\r\n");
+						DEBUG_INFO("********* High priority polling : Case 5 *********\r\n");
+						DEBUG_INFO("**************************************************\r\n");
+						DEBUG_INFO("MCU-%d get isUserLogin : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].bleConfigData.isLogin);
+						DEBUG_INFO("MCU-%d get isRequestStartCharger : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].bleConfigData.isRequestStart);
+						DEBUG_INFO("MCU-%d get isRequestStopCharger : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop);
+					}
+
+					//===============================
+					// Query primary MCU ble login id
+					//===============================
+					if(strcmp((char *)&ShmCharger->gun_info[gun_index].bleLoginCentralId.id,"") != 0)
+					{
+						DEBUG_INFO("**************************************************\r\n");
+						DEBUG_INFO("********* High priority polling : Case 6 *********\r\n");
+						DEBUG_INFO("**************************************************\r\n");
+						DEBUG_INFO("MCU-%d get ble central id : %s\r\n", gun_index, ShmCharger->gun_info[gun_index].bleLoginCentralId.id);
+					}
+
+					usleep(100000);
+				}
+
+				printOutCount[gun_index]++;
+			}
+			else
+			{
+				/*
+				 * Normal priority communication
+				 */
+
+				switch(stepIndex)
+				{
+					case 1:
+						//===============================
+						// Query present input voltage
+						//===============================
+						if(Query_Present_InputVoltage(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].inputVoltage) == PASS)
+						{
+							ShmSysConfigAndInfo->SysInfo.InputVoltageR = ShmCharger->gun_info[gun_index].inputVoltage.L1N_L12;
+							ShmSysConfigAndInfo->SysInfo.InputVoltageS = ShmCharger->gun_info[gun_index].inputVoltage.L2N_L23;
+							ShmSysConfigAndInfo->SysInfo.InputVoltageT = ShmCharger->gun_info[gun_index].inputVoltage.L3N_L31;
+
+							ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingVoltage = ShmCharger->gun_info[gun_index].inputVoltage.L1N_L12;
+
+							failCount[gun_index] = 0;
+						}
+						else
+						{
+							DEBUG_WARN("MCU-%d get input voltage fail...%d\r\n", gun_index, failCount[gun_index]);
+							if(failCount[gun_index]<1000)
+							{
+								failCount[gun_index]++;
+							}
+						}
+						break;
+					case 3:
+						//===============================
+						// Query present output current
+						//===============================
+						if(Query_Present_OutputCurrent(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].outputCurrent) == PASS)
+						{
+							ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrent = (float)ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0];
+
+							failCount[gun_index] = 0;
+						}
+						else
+						{
+							DEBUG_WARN("MCU-%d get output current fail...%d\r\n", gun_index, failCount[gun_index]);
+							if(failCount[gun_index]<1000)
+							{
+								failCount[gun_index]++;
+							}
+						}
+						break;
+					case 5:
+						//===============================
+						// Query gun plug-in times
+						//===============================
+						if(Query_AC_GUN_PLUGIN_TIMES(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].gunPluginTimes) == PASS)
+						{
+							ShmSysConfigAndInfo->SysConfig.AcPlugInTimes = ((long)ShmCharger->gun_info[gun_index].gunPluginTimes.GunPluginTimes & 0xFFFF);
+
+							failCount[gun_index] = 0;
+						}
+						else
+						{
+							DEBUG_WARN("MCU-%d get gun plugin times fail...%d\r\n", gun_index, failCount[gun_index]);
+							if(failCount[gun_index]<1000)
+							{
+								failCount[gun_index]++;
+							}
+						}
+						break;
+					case 7:
+						//===============================
+						// Query temperature
+						//===============================
+						if(Query_Temperature(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].temperature) == PASS)
+						{
+							ShmSysConfigAndInfo->SysInfo.SystemAmbientTemp = ShmCharger->gun_info[gun_index].temperature.point[0];
+
+							failCount[gun_index] = 0;
+						}
+						else
+						{
+							DEBUG_WARN("MCU-%d get temperature fail...%d\r\n", gun_index, failCount[gun_index]);
+							if(failCount[gun_index]<1000)
+							{
+								failCount[gun_index]++;
+							}
+						}
+						break;
+					case 9:
+						//===============================
+						// Config primary set CP PWN duty
+						//===============================
+						if(ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty == ON)
+						{
+							if(Config_AC_MaxCurrent_And_CpPwmDuty(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty))
+							{
+								failCount[gun_index] = 0;
+								ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty = OFF;
+							}
+							else
+							{
+								ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty = OFF;
+
+								DEBUG_WARN("MCU-%d set cp pwn duty fail...%d\r\n", gun_index, failCount[gun_index]);
+								if(failCount[gun_index]<1000)
+								{
+									failCount[gun_index]++;
+								}
+							}
+						}
+						break;
+					case 11:
+						//===============================
+						// Query RTC
+						//===============================
+						if(Query_RTC(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].rtc))
+						{
+							struct timeb csuTime, mcuTime;
+							struct tm *tmCSU;
+							struct tm tmMcu;
+							ftime(&csuTime);
+							tmCSU = localtime(&csuTime.time);
+							tmMcu.tm_year = ShmCharger->gun_info[gun_index].rtc.year-1900;
+							tmMcu.tm_mon = ShmCharger->gun_info[gun_index].rtc.month-1;
+							tmMcu.tm_mday = ShmCharger->gun_info[gun_index].rtc.day;
+							tmMcu.tm_hour = ShmCharger->gun_info[gun_index].rtc.hour;
+							tmMcu.tm_min = ShmCharger->gun_info[gun_index].rtc.min;
+							tmMcu.tm_sec = ShmCharger->gun_info[gun_index].rtc.sec;
+							mcuTime.time = mktime(&tmMcu);
+
+							if(ShmCharger->gun_info[gun_index].bleConfigData.isLogin && !ShmOCPP16Data->OcppConnStatus)
+							{
+								if(abs(DiffTimeb(csuTime, mcuTime)) > 10000)
+								{
+									char cmdBuf[128];
+									sprintf(cmdBuf, "date -u -s \"%04d-%02d-%02d %02d:%02d:%02d\"", ShmCharger->gun_info[gun_index].rtc.year,
+																									ShmCharger->gun_info[gun_index].rtc.month,
+																									ShmCharger->gun_info[gun_index].rtc.day,
+																									ShmCharger->gun_info[gun_index].rtc.hour,
+																									ShmCharger->gun_info[gun_index].rtc.min,
+																									ShmCharger->gun_info[gun_index].rtc.sec);
+									system(cmdBuf);
+									system("hwclock -w -u");
+									system("hwclock -s");
+								}
+							}
+							else
+							{
+								if(abs(DiffTimeb(csuTime, mcuTime)) > 10000)
+								{
+									ShmCharger->gun_info[gun_index].rtc.year = tmCSU->tm_year+1900;
+									ShmCharger->gun_info[gun_index].rtc.month = tmCSU->tm_mon+1;
+									ShmCharger->gun_info[gun_index].rtc.day = tmCSU->tm_mday;
+									ShmCharger->gun_info[gun_index].rtc.hour = tmCSU->tm_hour;
+									ShmCharger->gun_info[gun_index].rtc.min = tmCSU->tm_min;
+									ShmCharger->gun_info[gun_index].rtc.sec = tmCSU->tm_sec;
+									Config_RTC(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].rtc);
+								}
+							}
+
+							failCount[gun_index] = 0;
+						}
+						else
+						{
+							DEBUG_WARN("MCU-%d get rtc fail...%d\r\n", gun_index, failCount[gun_index]);
+							if(failCount[gun_index]<1000)
+							{
+								failCount[gun_index]++;
+							}
+						}
+						break;
+					case 13:
+						//===============================
+						// Query primary MCU power consumption
+						//===============================
+						if(Query_Power_Consumption(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].powerConsumption))
+						{
+							failCount[gun_index] = 0;
+						}
+						else
+						{
+							DEBUG_WARN("MCU-%d get power consumption fail...%d\r\n", gun_index, failCount[gun_index]);
+							if(failCount[gun_index]<1000)
+							{
+								failCount[gun_index]++;
+							}
+						}
+						break;
+					case 15:
+						//===============================
+						// Upgrade MCU
+						//===============================
+						if(ShmCharger->gun_info[gun_index].mcuFlag.isMcuUpgradeReq)
+						{
+							DEBUG_INFO("==================================================\r\n");
+							DEBUG_INFO("======== Normal priority polling : Case 15 =======\r\n");
+							DEBUG_INFO("==================================================\r\n");
+
+							unsigned char cmd[512];
+							if(Upgrade_UART(Uart1Fd, AC_WALLMOUNT_CONTROLLER, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), ShmCharger->fwUpgradeInfo.location, ShmCharger->fwUpgradeInfo.modelName))
+							{
+								DEBUG_INFO("MCU-%d upgrade firmware OK...%s\r\n", gun_index, ShmCharger->gun_info[gun_index].ver.Version_FW);
+								sleep(20);
+								ShmCharger->gun_info[gun_index].mcuFlag.isMcuUpgradeReq = OFF;
+								failCount[gun_index] = 0;
+							}
+							else
+							{
+								DEBUG_WARN("MCU-%d upgrade firmware fail...%d\r\n", gun_index, failCount[gun_index]);
+								if(failCount[gun_index]<1000)
+								{
+									failCount[gun_index]++;
+								}
+							}
+
+							sprintf((char*)cmd, "yes|rm %s", ShmCharger->fwUpgradeInfo.location);
+							system((char*)cmd);
+						}
+						break;
+					case 17:
+						//DEBUG_INFO("==================================================\r\n");
+						//DEBUG_INFO("======== Normal priority polling : Case 17 =======\r\n");
+						//DEBUG_INFO("==================================================\r\n");
+						break;
+					case 19:
+						//DEBUG_INFO("==================================================\r\n");
+						//DEBUG_INFO("======== Normal priority polling : Case 19 =======\r\n");
+						//DEBUG_INFO("==================================================\r\n");
+						break;
+					case 21:
+						//===============================
+						// Query firmware version
+						//===============================
+						if(ShmCharger->gun_info[gun_index].mcuFlag.isReadFwVerPass != PASS)
+						{
+							DEBUG_INFO("==================================================\r\n");
+							DEBUG_INFO("======== Normal priority polling : Case 21-1======\r\n");
+							DEBUG_INFO("==================================================\r\n");
+							if(Query_FW_Ver(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].ver) == PASS)
+							{
+								DEBUG_INFO("MCU-%d get firmware version : %s\r\n", gun_index, ShmCharger->gun_info[gun_index].ver.Version_FW);
+								memcpy(ShmPrimaryMcuData->version, ShmCharger->gun_info[gun_index].ver.Version_FW, sizeof(ShmPrimaryMcuData->version));
+								ShmCharger->gun_info[gun_index].mcuFlag.isReadFwVerPass = PASS;
+
+								failCount[gun_index] = 0;
+							}
+							else
+							{
+								DEBUG_WARN("MCU-%d get firmware version fail...%d\r\n", gun_index, failCount[gun_index]);
+								if(failCount[gun_index]<1000)
+								{
+									failCount[gun_index]++;
+								}
+							}
+						}
+
+						//===============================
+						// Config primary MCU serial number
+						//===============================
+						if(ShmCharger->gun_info[gun_index].mcuFlag.isSetSerialNumberPass != PASS)
+						{
+							DEBUG_INFO("==================================================\r\n");
+							DEBUG_INFO("======== Normal priority polling : Case 21-2======\r\n");
+							DEBUG_INFO("==================================================\r\n");
+							memcpy(ShmCharger->evseId.serial_number, ShmSysConfigAndInfo->SysConfig.SerialNumber, ARRAY_SIZE(ShmCharger->evseId.serial_number));
+							if(Config_Serial_Number(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->evseId))
+							{
+								DEBUG_INFO("MCU-%d set serial number : %.12s\r\n",gun_index,ShmCharger->evseId.serial_number);
+								ShmCharger->gun_info[gun_index].mcuFlag.isSetSerialNumberPass = PASS;
+
+								failCount[gun_index] = 0;
+							}
+							else
+							{
+								DEBUG_WARN("MCU-%d set serial number fail...%d\r\n", gun_index, failCount[gun_index]);
+								if(failCount[gun_index]<1000)
+								{
+									failCount[gun_index]++;
+								}
+							}
+						}
+
+						//===============================
+						// Config primary MCU model name
+						//===============================
+						if(ShmCharger->gun_info[gun_index].mcuFlag.isSetModelNamePass != PASS)
+						{
+							DEBUG_INFO("==================================================\r\n");
+							DEBUG_INFO("======== Normal priority polling : Case 21-3======\r\n");
+							DEBUG_INFO("==================================================\r\n");
+							memcpy(ShmCharger->evseId.model_name, ShmSysConfigAndInfo->SysConfig.ModelName, ARRAY_SIZE(ShmCharger->evseId.model_name));
+							if(Config_Model_Name(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->evseId))
+							{
+								DEBUG_INFO("MCU-%d set model name : %.14s\r\n",gun_index,ShmCharger->evseId.model_name);
+								ShmCharger->gun_info[gun_index].mcuFlag.isSetModelNamePass = PASS;
+
+								failCount[gun_index] = 0;
+							}
+							else
+							{
+								DEBUG_WARN("MCU-%d set model name fail...%d\r\n", gun_index, failCount[gun_index]);
+								if(failCount[gun_index]<1000)
+								{
+									failCount[gun_index]++;
+								}
+							}
+						}
+						break;
+					default:
+						stepIndex = 0;
+						break;
+				}
+
+				//==========================================================
+				// Low priority polling log print out
+				//==========================================================
+				if(printOutCount[gun_index] == PRINT_OUT_LEVEL_STATE)
+				{
+					if(stepIndex == 1)
+					{
+						DEBUG_INFO("==================================================\r\n");
+						DEBUG_INFO("======== Normal priority polling : Case 1 ========\r\n");
+						DEBUG_INFO("==================================================\r\n");
+						DEBUG_INFO("MCU-%d get input voltage : %f\r\n", gun_index, (float)ShmCharger->gun_info[gun_index].inputVoltage.L1N_L12);
+						DEBUG_INFO("MCU-%d get PresentChargingVoltage : %.2f\r\n", gun_index, (float)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingVoltage);
+					}
+					else if(stepIndex == 3)
+					{
+						DEBUG_INFO("==================================================\r\n");
+						DEBUG_INFO("======== Normal priority polling : Case 3 ========\r\n");
+						DEBUG_INFO("==================================================\r\n");
+						DEBUG_INFO("MCU-%d get output current : %f\r\n", gun_index, (float)ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0]);
+					}
+					else if (stepIndex == 5)
+					{
+						DEBUG_INFO("==================================================\r\n");
+						DEBUG_INFO("======== Normal priority polling : Case 5 ========\r\n");
+						DEBUG_INFO("==================================================\r\n");
+						DEBUG_INFO("MCU-%d get gun plugin times : %ld\r\n", gun_index, (long)ShmCharger->gun_info[gun_index].gunPluginTimes.GunPluginTimes);
+					}
+					else if (stepIndex == 7)
+					{
+						DEBUG_INFO("==================================================\r\n");
+						DEBUG_INFO("======== Normal priority polling : Case 7 ========\r\n");
+						DEBUG_INFO("==================================================\r\n");
+						DEBUG_INFO("MCU-%d get temperature : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].temperature.point[0]);
+					}
+					else if (stepIndex == 9)
+					{
+						DEBUG_INFO("==================================================\r\n");
+						DEBUG_INFO("======== Normal priority polling : Case 9 ========\r\n");
+						DEBUG_INFO("==================================================\r\n");
+						DEBUG_INFO("MCU-%d cp pwn duty : %d\r\n",gun_index, ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current);
+					}
+					else if (stepIndex == 11)
+					{
+						DEBUG_INFO("==================================================\r\n");
+						DEBUG_INFO("======== Normal priority polling : Case 11 =======\r\n");
+						DEBUG_INFO("==================================================\r\n");
+						if(ShmCharger->gun_info[gun_index].bleConfigData.isLogin && !ShmOCPP16Data->OcppConnStatus)
+						{
+							DEBUG_INFO("Sync from MCU-%d rtc OK...%04d-%02d-%02d %02d:%02d:%02d\r\n", gun_index,
+																											  ShmCharger->gun_info[gun_index].rtc.year,
+																											  ShmCharger->gun_info[gun_index].rtc.month,
+																											  ShmCharger->gun_info[gun_index].rtc.day,
+																											  ShmCharger->gun_info[gun_index].rtc.hour,
+																											  ShmCharger->gun_info[gun_index].rtc.min,
+																											  ShmCharger->gun_info[gun_index].rtc.sec);
+
+
+						}
+						else
+						{
+							DEBUG_INFO("MCU-%d set rtc OK...%04d-%02d-%02d %02d:%02d:%02d\r\n", gun_index,
+																										ShmCharger->gun_info[gun_index].rtc.year,
+																										ShmCharger->gun_info[gun_index].rtc.month,
+																										ShmCharger->gun_info[gun_index].rtc.day,
+																										ShmCharger->gun_info[gun_index].rtc.hour,
+																										ShmCharger->gun_info[gun_index].rtc.min,
+																										ShmCharger->gun_info[gun_index].rtc.sec);
+						}
+					}
+					else if (stepIndex == 13)
+					{
+						DEBUG_INFO("==================================================\r\n");
+						DEBUG_INFO("======== Normal priority polling : Case 13 =======\r\n");
+						DEBUG_INFO("==================================================\r\n");
+						DEBUG_INFO("MCU-%d get power consumption : %f kWh\r\n",gun_index, ((float)ShmCharger->gun_info[gun_index].powerConsumption.power_consumption/100));
+					}
+
+					usleep(100000);
+				}
+			}
+			stepIndex++;
+
+			//===============================
+			// Communication fail check
+			//===============================
+			if(failCount[gun_index] >= FAIL_SPEC_COMM)
+			{
+				if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.comm_timeout == OFF)
+				{
+					DEBUG_ERROR("Primary MCU-%d communication fault", gun_index);
+					ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.comm_timeout = ON;
+				}
+			}
+			else
+			{
+				if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.comm_timeout == ON)
+				{
+					DEBUG_ERROR("Primary MCU-%d communication recover", gun_index);
+					ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.comm_timeout = OFF;
+				}
+			}
+		}
+	}
+
+	return FAIL;
+}

+ 67 - 0
EVSE/Projects/Noodoe/Apps/Module_InternalComm.h

@@ -0,0 +1,67 @@
+/*
+ * Module_InternalComm.h
+ *
+ *  Created on: 2020¦~01¤ë15¤é
+ *      Author: USER
+ */
+
+#ifndef MODULE_INTERNALCOMM_H_
+#define MODULE_INTERNALCOMM_H_
+
+#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)
+
+extern int StoreLogMsg(const char *fmt, ...);
+
+enum MESSAGE_COMMAND
+{
+	CMD_QUERY_FW_VER = 0x01,
+	CMD_QUERY_HW_VER = 0x02,
+	CMD_QUERY_PRESENT_INPUTVOLTAGE = 0x03,
+	CMD_QUERY_PRESENT_OUTPUTVOLTAGE = 0x04,
+	CMD_QUERY_FAN_SPEED = 0x05,
+	CMD_QUERY_TEMPERATURE = 0x06,
+	CMD_QUERY_AUX_POWERVOLTAGE = 0x07,
+	CMD_QUERY_RELAY_OUTPUT = 0x08,
+	CMD_QUERY_GFD_ADC = 0x09,
+	CMD_QUERY_GPIO_INPUT = 0x0a,
+	CMD_QUERY_ALARM_LOG = 0x22,
+	CMD_QUERY_RTC = 0x26,
+	CMD_QUERY_PRESENT_OUTPUTCURRENT = 0x27,
+	CMD_QUERY_AC_STATUS = 0x28,
+	CMD_QUERY_AC_ALARM = 0x29,
+	CMD_QUERY_BLE_CONFIG_DATA = 0x2A,
+	CMD_QUERY_BLE_CENTRAL_ID = 0x2B,
+	CMD_QUERY_POWER_CONSUMPTION = 0x2C,
+	CMD_QUERY_GUN_PLUGIN_TIMES = 0x2D,
+
+	CMD_CONFIG_FAN_SPEED = 0x81,
+	CMD_CONFIG_SERIAL_NUMBER = 0x82,
+	CMD_CONFIG_MODEL_NAME = 0x83,
+	CMD_CONFIG_RELAY_OUTPUT = 0x85,
+	CMD_CONFIG_GPIO_OUTPUT = 0x86,
+	CMD_CONFIG_RTC = 0x87,
+	CMD_CONFIG_AC_LED = 0x88,
+	CMD_CONFIG_CURRENT_LINIT = 0x89,
+	CMD_CONFIG_MCU_MODE = 0x8A,
+	CMD_CONFIG_MCU_RESET_REQUEST = 0x8C,
+
+	CMD_UPDATE_START = 0xe0,
+	CMD_UPDATE_ABOARD = 0xe1,
+	CMD_UPDATE_TRANSFER = 0xe2,
+	CMD_UPDATE_END = 0xe3
+};
+
+enum MESSAGE_ADDRESS
+{
+	ADDR_AUX = 0x01,
+	ADDR_FAN = 0x02,
+	ADDR_RELAY = 0x03,
+	ADDR_DC_PRIMARY = 0x04,
+	ADDR_AC_PRIMARY_1 = 0xff,
+	ADDR_AC_PRIMARY_2 = 0xff
+};
+
+
+#endif /* MODULE_INTERNALCOMM_H_ */

+ 298 - 0
EVSE/Projects/Noodoe/Apps/Module_Speaker.c

@@ -0,0 +1,298 @@
+/*
+ * Module_Speaker.c
+ *
+ *  Created on: 2020年01月15日
+ *      Author: Eason Yang
+ */
+
+#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"
+#include	"main.h"
+
+#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)
+#define EVENT_INFO(format, args...) StoreEventLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+
+#define Debug
+#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
+#define PASS				1
+#define FAIL				-1
+#define ON					1
+#define OFF					0
+
+#define INTERVAL_1			100000
+#define INTERVAL_2			50000
+
+unsigned char speaker_type = SPEAKER_STOP;
+unsigned char pre_speaker_type = SPEAKER_STOP;
+
+struct SysConfigAndInfo			*ShmSysConfigAndInfo;
+struct StatusCodeData 			*ShmStatusCodeData;
+struct Charger					*ShmCharger;
+
+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 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);
+
+	if((ShmSysConfigAndInfo->SysConfig.ModelName != NULL) && (ShmSysConfigAndInfo->SysConfig.SerialNumber != NULL) && (strlen((char*)ShmSysConfigAndInfo->SysConfig.ModelName) >= 14))
+	{
+		sprintf(Buf,"echo \"[%04d.%02d.%02d %02d:%02d:%02d] - %s\" >> /Storage/SystemLog/[%04d.%02d]%s_%s_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,
+					ShmSysConfigAndInfo->SysConfig.ModelName,
+					ShmSysConfigAndInfo->SysConfig.SerialNumber);
+	}
+	else
+	{
+		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);
+	}
+
+#ifdef SystemLogMessage
+	system(Buf);
+#endif
+
+#ifdef ConsloePrintLog
+	printf("[%04d.%02d.%02d %02d:%02d:%02d] - %s", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec, buffer);
+#endif
+
+	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;
+}
+
+//=================================
+// Common routine
+//=================================
+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;
+
+	//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;
+	}
+
+	//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;
+	}
+
+	//Initial ShmCharger
+	if ((MeterSMId = shmget(ShmChargerKey, sizeof(struct Charger), 0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmget ShmChargerKey NG\r\n");
+		#endif
+		result = FAIL;
+	}
+	else if ((ShmCharger = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmat ShmChargerKey NG\r\n");
+		#endif
+		result = FAIL;
+	}
+
+	return result;
+}
+
+//================================================
+// Main process
+//================================================
+int main(void)
+{
+	if(InitShareMemory() == FAIL)
+	{
+		DEBUG_ERROR("InitShareMemory NG\n");
+
+		if(ShmStatusCodeData!=NULL)
+		{
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
+		}
+		sleep(5);
+		return FAIL;
+	}
+
+	for(;;)
+	{
+		if(ShmCharger->isSpeakerOn == ON)
+		{
+			switch(ShmCharger->speaker_type)
+			{
+				case SPEAKER_STOP:
+					DEBUG_INFO("SPEAKER_STOP...\r\n");
+					ShmCharger->isSpeakerOn = OFF;
+					break;
+				case SPEAKER_ALWAYS_ON:
+					break;
+				case SPEAKER_SHORT:
+					system("echo 1 > /sys/class/gpio/gpio65/value");
+					usleep(INTERVAL_1);
+					system("echo 0 > /sys/class/gpio/gpio65/value");
+
+					ShmCharger->isSpeakerOn = OFF;
+					DEBUG_INFO("SPEAKER_SHORT...\r\n");
+					break;
+				case SPEAKER_LONG:
+					break;
+				case SPEAKER_INTERVAL_SHORT:
+					break;
+				case SPEAKER_INTERVAL_LONG:
+					break;
+				case SPEAKER_INTERVAL_3COUNT:
+					system("echo 1 > /sys/class/gpio/gpio65/value");
+					usleep(INTERVAL_2);
+					system("echo 0 > /sys/class/gpio/gpio65/value");
+					usleep(INTERVAL_2);
+					system("echo 1 > /sys/class/gpio/gpio65/value");
+					usleep(INTERVAL_2);
+					system("echo 0 > /sys/class/gpio/gpio65/value");
+					usleep(INTERVAL_2);
+					system("echo 1 > /sys/class/gpio/gpio65/value");
+					usleep(INTERVAL_2);
+					system("echo 0 > /sys/class/gpio/gpio65/value");
+
+					ShmCharger->isSpeakerOn = OFF;
+					DEBUG_INFO("SPEAKER_INTERVAL_3COUNT...\r\n");
+					break;
+			}
+		}
+		usleep(100000);
+	}
+}
+

+ 2710 - 0
EVSE/Projects/Noodoe/Apps/main.c

@@ -0,0 +1,2710 @@
+#include	"define.h"
+#include 	"main.h"
+
+
+//==========================
+// System basic sample constant
+//==========================
+#define ARRAY_SIZE(A)					(sizeof(A) / sizeof(A[0]))
+#define PASS							1
+#define FAIL							-1
+#define YES								1
+#define NO								0
+#define ON								1
+#define OFF								0
+#define BUFFER_SIZE						128
+
+//==========================
+// Timer interval
+//==========================
+#define TMR_IDX_HANDSHAKING				0
+#define TMR_IDX_AUTH					1
+#define TMR_IDX_LOGPPRINTOUT			2
+#define TMR_IDX_3						3
+#define TMR_IDX_4						4
+#define TMR_IDX_5						5
+#define TMR_IDX_6						6
+#define TMR_IDX_7						7
+#define TMR_IDX_8						8
+#define TMR_IDX_9 						9
+
+#define TIMEOUT_SPEC_HANDSHAKING		180000
+#define TIMEOUT_SPEC_AUTH				30000
+#define TIMEOUT_SPEC_HANDSHAKING_LED	185000
+#define TIMEOUT_SPEC_LOGPPRINTOUT		20000
+
+#define MtdBlockSize 					0x600000
+
+//==========================
+// Declare method
+//==========================
+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 isReachableInternet();
+int InitRfidPort(void);
+int GetAlarmValue(void);
+int GetInfoValue(void);
+int GetFaultValue(void);
+int GetCardSerialNumber();
+void setLedMotion(unsigned char gun_index,unsigned char led_mode);
+void setRelay(unsigned char gun_index,unsigned char isOn);
+void setSpeaker(unsigned char isOn, unsigned char speaker_mode);
+
+//==========================
+// Declare RFID module type
+//==========================
+#define MODULE_EWT		0
+
+int		wtdFd = -1;
+int 	rfidFd = -1;
+char* 	rfidPortName = "/dev/ttyS2";
+RFID 	rfid;
+char 	*valid_Internet[2] 	  = {"8.8.8.8", "180.76.76.76"};
+
+//==========================
+// Declare share memory
+//==========================
+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 Charger					*ShmCharger;
+
+struct timeb					startTime[AC_QUANTITY][10];
+struct timeb					startChargingTime[AC_QUANTITY];
+struct timeb					endChargingTime[AC_QUANTITY];
+sqlite3 *localDb;
+
+//=================================
+// Common routine
+//=================================
+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);
+	}
+}
+
+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);
+
+	if((ShmSysConfigAndInfo->SysConfig.ModelName != NULL) && (ShmSysConfigAndInfo->SysConfig.SerialNumber != NULL) && (strlen((char*)ShmSysConfigAndInfo->SysConfig.ModelName) >= 14))
+	{
+		sprintf(Buf,"echo \"[%04d.%02d.%02d %02d:%02d:%02d] - %s\" >> /Storage/SystemLog/[%04d.%02d]%s_%s_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,
+					ShmSysConfigAndInfo->SysConfig.ModelName,
+					ShmSysConfigAndInfo->SysConfig.SerialNumber);
+	}
+	else
+	{
+		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);
+	}
+
+#ifdef SystemLogMessage
+	system(Buf);
+#endif
+
+#ifdef ConsloePrintLog
+	printf("[%04d.%02d.%02d %02d:%02d:%02d] - %s", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec, buffer);
+#endif
+
+	return rc;
+}
+
+int DiffTimebWithNow(struct timeb ST)
+{
+	//return milli-second
+	struct timeb ET;
+	unsigned int StartTime,StopTime;
+
+	ftime(&ET);
+	StartTime=(unsigned int)ST.time;
+	StopTime=(unsigned int)ET.time;
+	return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
+}
+
+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 getDateTimeString(char* result)
+{
+	time_t CurrentTime;
+	struct tm *tm;
+
+	CurrentTime = time(NULL);
+	tm=localtime(&CurrentTime);
+
+	sprintf(result, "%04d.%02d.%02d %02d:%02d:%02d", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec);
+}
+
+//======================================================
+// 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 CreatShareMemory()
+{
+	int result = PASS;
+	int MeterSMId;
+
+
+	//creat ShmSysConfigAndInfo
+	if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), IPC_CREAT | 0777)) < 0)
+	{
+		DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\r\n");
+		result = FAIL;
+	}
+	else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+
+		DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\r\n");
+
+		result = FAIL;
+   	}
+   	memset(ShmSysConfigAndInfo,0,sizeof(struct SysConfigAndInfo));
+
+   	//creat ShmStatusCodeData
+   	if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), IPC_CREAT | 0777)) < 0)
+	{
+
+   		DEBUG_ERROR("shmget ShmStatusCodeData NG\r\n");
+
+   		result = FAIL;
+	}
+	else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+
+		DEBUG_ERROR("shmat ShmStatusCodeData NG\r\n");
+
+		result = FAIL;
+   	}
+   	memset(ShmStatusCodeData, 0, sizeof(struct StatusCodeData));
+
+   	//creat ShmPsuData
+   	if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), IPC_CREAT | 0777)) < 0)
+	{
+
+   		DEBUG_ERROR("shmget ShmPsuData NG\r\n");
+
+   		result = FAIL;
+	}
+	else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+
+		DEBUG_ERROR("shmat ShmPsuData NG\r\n");
+
+		result = FAIL;
+   	}
+   	memset(ShmPsuData,0,sizeof(struct PsuData));
+
+   	//creat ShmCHAdeMOData
+   	if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData), IPC_CREAT | 0777)) < 0)
+	{
+
+   		DEBUG_ERROR("shmget ShmCHAdeMOData NG1\r\n");
+
+   		result = FAIL;
+	}
+	else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+
+		DEBUG_ERROR("shmat ShmCHAdeMOData NG2\r\n");
+
+		result = FAIL;
+    }
+    memset(ShmCHAdeMOData,0,sizeof(struct CHAdeMOData));
+
+    //creat ShmCcsData
+    if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData), IPC_CREAT | 0777)) < 0)
+   	{
+
+   		DEBUG_ERROR("shmget ShmCcsData NG\r\n");
+
+   		result = FAIL;
+	}
+   	else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+   	{
+
+   		DEBUG_ERROR("shmat ShmCcsData NG\r\n");
+
+   		result = FAIL;
+    }
+    memset(ShmCcsData,0,sizeof(struct CcsData));
+
+   	//creat ShmPrimaryMcuData
+    if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), IPC_CREAT | 0777)) < 0)
+   	{
+
+   		DEBUG_ERROR("shmget ShmPrimaryMcuData NG\r\n");
+
+   		result = FAIL;
+	}
+    else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+    {
+
+    	DEBUG_ERROR("shmat ShmPrimaryMcuData NG\r\n");
+
+    	result = FAIL;
+   	}
+   	memset(ShmPrimaryMcuData,0,sizeof(struct PrimaryMcuData));
+
+   	 /*
+   	 //creat ShmFanModuleData
+   	if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData), IPC_CREAT | 0777)) < 0)
+    {
+
+   		DEBUG_ERROR("shmget ShmFanModuleData NG\r\n");
+
+   		result = FAIL;
+	}
+    else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+    {
+
+    	DEBUG_ERROR("shmat ShmFanModuleData NG\r\n");
+
+    	result = FAIL;
+   	 }
+   	 memset(ShmFanModuleData,0,sizeof(struct FanModuleData));
+
+   	 //creat ShmRelayModuleData
+   	if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData), IPC_CREAT | 0777)) < 0)
+    {
+
+   		DEBUG_ERROR("shmget ShmRelayModuleData NG\r\n");
+
+   		result = FAIL;
+	}
+    else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+    {
+
+    	DEBUG_ERROR("shmat ShmRelayModuleData NG\r\n");
+
+    	result = FAIL;
+   	}
+   	memset(ShmRelayModuleData,0,sizeof(struct RelayModuleData));*/
+
+   	//creat ShmOCPP16Data
+   	if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), IPC_CREAT | 0777)) < 0)
+    {
+
+   		DEBUG_ERROR("shmget ShmOCPP16Data NG\r\n");
+
+   		result = FAIL;
+	}
+    else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+    {
+
+    	DEBUG_ERROR("shmat ShmOCPP16Data NG\r\n");
+
+    	result = FAIL;
+   	}
+   	memset(ShmOCPP16Data,0,sizeof(struct OCPP16Data));
+
+	//creat ShmCharger
+   	if ((MeterSMId = shmget(ShmChargerKey, sizeof(struct Charger), IPC_CREAT | 0777)) < 0)
+    {
+
+   		DEBUG_ERROR("shmget ShmCharger NG\r\n");
+
+   		result = FAIL;
+	}
+    else if ((ShmCharger = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+    {
+
+    	DEBUG_ERROR("shmat ShmCharger NG\r\n");
+
+    	result = FAIL;
+   	}
+   	memset(ShmCharger,0,sizeof(struct Charger));
+
+    return result;
+}
+
+//===============================================
+// SQLite3 related routine
+//===============================================
+int DB_Open(sqlite3 *db)
+{
+	int result = PASS;
+	char* errMsg = NULL;
+	char* createSql="CREATE TABLE IF NOT EXISTS charging_record("
+					"idx integer primary key AUTOINCREMENT, "
+					"reservationId text, "
+					"transactionId text, "
+					"startMethod text, "
+					"userId text, "
+					"dateTimeStart text, "
+					"dateTimeStop text,"
+					"socStart text, "
+					"socStop text, "
+					"chargeEnergy text, "
+					"stopReason text"
+					");";
+
+	//sqlite3_config(SQLITE_CONFIG_URI, 1);
+	if(sqlite3_open("/Storage/ChargeLog/localCgargingRecord.db", &db))
+	{
+		result = FAIL;
+		DEBUG_INFO( "Can't open database: %s\r\n", sqlite3_errmsg(db));
+		sqlite3_close(db);
+	}
+	else
+	{
+		DEBUG_INFO( "Local charging record database open successfully.\r\n");
+		if (sqlite3_exec(db, createSql, 0, 0, &errMsg) != SQLITE_OK)
+		{
+			result = FAIL;
+			DEBUG_INFO( "Create local charging record table error message: %s\n", errMsg);
+		}
+		else
+		{
+			DEBUG_INFO( "Opened local charging record table successfully\n");
+		}
+		sqlite3_close(db);
+	}
+
+	return result;
+}
+
+int DB_Insert_Record(sqlite3 *db, int gun_index)
+{
+	int result = PASS;
+	char* errMsg = NULL;
+	char insertSql[1024];
+
+	sprintf(insertSql, "insert into charging_record(reservationId, transactionId, startMethod, userId, dateTimeStart, dateTimeStop, socStart, socStop, chargeEnergy, stopReason) "
+					   "values('%d', '%d', '%d', '%s', '%s', '%s', '%d', '%d', '%f', '%s');",
+					   ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].ReservationId,
+					   ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId,
+					   ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod,
+					   ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId,
+					   ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartDateTime,
+					   ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StopDateTime,
+					   ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc,
+					   ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc,
+					   ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy,
+					   ShmOCPP16Data->StopTransaction[gun_index].StopReason);
+
+	if(sqlite3_open("/Storage/ChargeLog/localCgargingRecord.db", &db))
+	{
+		result = FAIL;
+		DEBUG_INFO( "Can't open database: %s\r\n", sqlite3_errmsg(db));
+		sqlite3_close(db);
+	}
+	else
+	{
+		DEBUG_INFO( "Local charging record database open successfully.\r\n");
+		if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK)
+		{
+			result = FAIL;
+			DEBUG_INFO( "Insert local charging record error message: %s\n", errMsg);
+		}
+		else
+		{
+			DEBUG_INFO( "Insert local charging record successfully\n");
+		}
+		sqlite3_close(db);
+	}
+
+	return result;
+}
+
+//======================================================
+// Peripheral initial
+//======================================================
+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("System watch dog initial fail.\r\n");
+	}
+
+	return fd;
+}
+
+void InitGPIO()
+{
+	/*****************0~3, 4 bank, bank x 32+ num*********************/
+	/***************************************************************/
+	/*************** INPUT PIN ***************************************/
+	/***************************************************************/
+
+	/***************************************************************/
+	/*************** OUTPUT PIN ************************************/
+	/***************************************************************/
+	/*MCU request:GPIO3_20 => H:ON; L:OFF*/
+	system("echo 116 > /sys/class/gpio/export");
+	system("echo \"out\" > /sys/class/gpio/gpio116/direction");
+	system("echo 0 > /sys/class/gpio/gpio116/value");
+
+	/*Rfid:GPIO0_19 => Reset_PING H:ON; L:OFF*/
+	system("echo 19 > /sys/class/gpio/export");
+	system("echo \"out\" > /sys/class/gpio/gpio19/direction");
+	system("echo 1 > /sys/class/gpio/gpio19/value");
+
+	/*Speaker:GPIO2_1 => H:ON; L:OFF*/
+	system("echo 65 > /sys/class/gpio/export");
+	system("echo \"out\" > /sys/class/gpio/gpio65/direction");
+	system("echo 0 > /sys/class/gpio/gpio65/value");
+
+	/*4G/Wifi RST:GPIO3_14 => H:ON; L:OFF*/
+	system("echo 110 > /sys/class/gpio/export");
+	system("echo \"out\" > /sys/class/gpio/gpio110/direction");
+	system("echo 1 > /sys/class/gpio/gpio110/value");
+	sleep(3);
+	system("echo 0 > /sys/class/gpio/gpio110/value");
+
+	DEBUG_INFO("Initial GPIO OK\r\n");
+}
+
+int LoadSysConfigAndInfo(struct SysConfigData *ptr)
+{
+	int fd,wrd;
+	unsigned char *buf;
+	unsigned int ChkSum,ChkSumOrg;
+
+	if((buf=malloc(MtdBlockSize))==NULL)
+	{
+
+		DEBUG_ERROR("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("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("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+(MtdBlockSize-4),sizeof(ChkSumOrg));
+
+	//================================================
+	// Load configuration from mtdblock11
+	//================================================
+	if(ChkSum!=ChkSumOrg)
+	{
+
+		DEBUG_ERROR("Primary SysConfigData checksum NG, read backup\r\n");
+
+		fd = open("/dev/mtdblock11", O_RDWR);
+		if (fd < 0)
+		{
+			free(buf);
+
+			DEBUG_ERROR("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("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+(MtdBlockSize-4),sizeof(ChkSumOrg));
+
+		//================================================
+		// Load configuration from mtdblock12 (Factory default)
+		//================================================
+		if(ChkSum!=ChkSumOrg)
+		{
+			DEBUG_WARN("backup SysConfigData checksum NG, read Factory default\r\n");
+
+			fd = open("/dev/mtdblock12", O_RDWR);
+			if (fd < 0)
+			{
+				free(buf);
+
+				DEBUG_ERROR("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("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+(MtdBlockSize-4),sizeof(ChkSumOrg));
+			if(ChkSum!=ChkSumOrg)
+			{
+				DEBUG_WARN("factory default  SysConfigData checksum NG, restore factory default\r\n");
+				free(buf);
+				system("cd /root;./Module_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("Load SysConfigData OK\r\n");
+
+	return PASS;
+
+}
+
+void InitEthernet()
+{
+	pid_t pid;
+	uint8_t cnt_pingDNS_Fail;
+	char tmpbuf[256];
+	//unsigned int address;
+
+	//Init Eth0 for internet
+	if(isInterfaceUp("eth0")==PASS)
+	{
+		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);
+		system("/sbin/ifconfig eth0:1 192.168.201.201 netmask 255.255.255.248 up");
+	}
+
+	if(isInterfaceUp("eth1")==PASS)
+	{
+		//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.Eth0Interface.EthDhcpClient==0)
+		system("/sbin/udhcpc -i eth0 -s /root/dhcp_script/eth0.script > /dev/null &");
+
+	//check internet status
+	pid = fork();
+
+	if(pid == 0)
+	{
+		for(;;)
+		{
+			if(isReachableInternet() == PASS)
+			{
+				ShmSysConfigAndInfo->SysInfo.InternetConn = ON;
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=OFF;
+				cnt_pingDNS_Fail = 0;
+			}
+			else
+			{
+				if(++cnt_pingDNS_Fail > 3)
+				{
+					ShmSysConfigAndInfo->SysInfo.InternetConn = OFF;
+					ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=ON;
+				}
+			}
+
+			sleep(5);
+		}
+	}
+
+	DEBUG_INFO("Initial Ethernet OK\r\n");
+}
+
+int SpawnTask()
+{
+	system ("pkill Module_4g");
+	system ("pkill Module_Wifi");
+	system ("pkill Module_EventLogging");
+	system ("pkill OcppBackend");
+	system ("pkill Module_AlarmDetect");
+	system ("pkill Module_InternalComm");
+	system ("pkill Module_Speaker");
+	system ("pkill Module_ProduceUtils");
+
+	if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T')
+	{
+		system("/root/Module_4g &");
+	}
+	else if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W')
+	{
+		system("/root/Module_Wifi &");
+	}
+
+	system("/root/Module_EventLogging &");
+	if(strcmp((char *)&ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0)
+	{
+		system("/root/OcppBackend &");
+	}
+	system ("/root/Module_AlarmDetect &");
+	system ("/root/Module_InternalComm &");
+	system ("/root/Module_Speaker &");
+	system ("/root/Module_ProduceUtils &");
+
+	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+=*(BufTmp+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("write /dev/mtdblock11(backup) NG\r\n");
+				   		result = FAIL;
+					}
+				}
+				else
+				{
+					DEBUG_ERROR("open /dev/mtdblock11(backup) NG\r\n");
+					result = FAIL;
+				}
+			}
+			else
+			{
+		    		DEBUG_ERROR("write /dev/mtdblock10 NG\r\n");
+		    		result = FAIL;
+			}
+		}
+		else
+		{
+			DEBUG_ERROR("open /dev/mtdblock10 NG\r\n");
+			result = FAIL;
+		}
+	}
+	else
+	{
+		DEBUG_ERROR("alloc BlockSize NG\r\n");
+    		result = FAIL;
+	}
+	if(BufTmp!=NULL)
+		free(BufTmp);
+
+	return result;
+}
+
+int Initialization()
+{
+	int result = PASS;
+
+	LoadSysConfigAndInfo(&ShmSysConfigAndInfo->SysConfig);
+
+	InitGPIO();
+
+	InitEthernet();
+
+	if(DB_Open(localDb) != PASS)
+		result = FAIL;
+
+	rfidFd = InitRfidPort();
+
+	wtdFd = InitWatchDog();
+
+	if((wtdFd < 0) || (rfidFd < 0))
+		result = FAIL;
+
+	if(result == PASS)
+		DEBUG_INFO("Initialization OK.\r\n");
+	else
+		DEBUG_INFO("Initialization Fail.\r\n");
+
+	return result;
+}
+
+//=====================================================
+// Common routine
+//=====================================================
+char* getSystemModeName(unsigned char mode)
+{
+	char* result;
+
+	switch(mode)
+	{
+		case SYS_MODE_BOOTING:
+			result = "booting";
+			break;
+		case SYS_MODE_IDLE:
+			result = "idle";
+			break;
+		case SYS_MODE_AUTHORIZING:
+			result = "authorizing";
+			break;
+		case SYS_MODE_PREPARING:
+			result = "preparing";
+			break;
+		case SYS_MODE_CHARGING:
+			result = "charging";
+			break;
+		case SYS_MODE_TERMINATING:
+			result = "terminating";
+			break;
+		case SYS_MODE_ALARM:
+			result = "alarm";
+			break;
+		case SYS_MODE_FAULT:
+			result = "fault";
+			break;
+		case SYS_MODE_MAINTAIN:
+			result = "maintain";
+			break;
+		case SYS_MODE_RESERVATION:
+			result = "reservation";
+			break;
+		case SYS_MODE_BOOKING:
+			result = "booking";
+			break;
+		case SYS_MODE_DEBUG:
+			result = "debug";
+			break;
+		case SYS_MODE_UPDATE:
+			result = "upgrade";
+			break;
+		default:
+			result = "unknown";
+			break;
+	}
+
+	return result;
+}
+
+void setChargerMode(unsigned char gun_index, unsigned char mode)
+{
+	ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PreviousSystemStatus = ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus;
+	ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus = mode;
+
+	DEBUG_INFO("Gun-%02d mode switch from %s to %s\r\n", gun_index, getSystemModeName(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PreviousSystemStatus), getSystemModeName(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus));
+}
+
+unsigned char isMode(unsigned char gun_index, unsigned char mode)
+{
+	return ((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus == mode)?YES:NO);
+}
+
+unsigned char isModeChange(unsigned char gun_index)
+{
+	unsigned char result = NO;
+
+	if(!isMode(gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PreviousSystemStatus))
+	{
+		result = YES;
+
+		ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PreviousSystemStatus = ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus;
+	}
+
+	return result;
+}
+
+//===============================================
+// Get firmware version
+//===============================================
+void get_firmware_version(unsigned char gun_index)
+{
+	FILE *fp;
+	char cmd[512];
+	char buf[512];
+
+	// Get CSU hardware version
+	sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuHwRev, "REV.XXXXXXX");
+
+	// Get CSU boot loader version
+	memcpy(ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev, ShmSysConfigAndInfo->SysConfig.CsuBootLoadFwRev, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.CsuBootLoadFwRev));
+
+	// Get CSU kernel version
+	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);
+		}
+	}
+
+	// Get MCU firmware version
+	strcpy((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, ShmCharger->gun_info[gun_index].ver.Version_FW);
+
+	// Get CSU root file system version
+	sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, "B0.20.00.0000.00");
+
+	// Get AC connector type from model name
+	for(uint8_t idx=0;idx<3;idx++)
+	{
+		switch(ShmSysConfigAndInfo->SysConfig.ModelName[7+idx])
+		{
+			case '1':
+				// J1772 Plug
+				ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[6] = '4';
+				ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev[6] = '4';
+				break;
+			case '2':
+				// J1772 Socket
+				ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[6] = '1';
+				ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev[6] = '1';
+				break;
+			case '3':
+				// CE Plug
+				ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[6] = '5';
+				ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev[6] = '5';
+				break;
+			case '4':
+				// CE Socket
+				ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[6] = '2';
+				ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev[6] = '2';
+				break;
+			case '5':
+				// GB Plug
+				ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[6] = '6';
+				ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev[6] = '6';
+				break;
+			case '6':
+				// GB Socket
+				ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[6] = '3';
+				ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev[6] = '3';
+				break;
+		}
+	}
+
+	// Get network option from model name
+	switch(ShmSysConfigAndInfo->SysConfig.ModelName[10])
+	{
+		case 'B':
+		case 'U':
+			//Blue tooth
+			ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '3';
+			ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev[9] = '3';
+			break;
+		case 'W':
+			// WIFI
+			ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '1';
+			ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev[9] = '1';
+			break;
+		case 'T':
+			// 3G/4G
+			ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '2';
+			ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev[9] = '2';
+			break;
+		default:
+			// LAN
+			ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '0';
+			ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev[9] = '0';
+			break;
+	}
+
+	// Get rating power from model name
+	memcpy(&ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[10], &ShmSysConfigAndInfo->SysConfig.ModelName[4], 0x03);
+	memcpy(&ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev[10], &ShmSysConfigAndInfo->SysConfig.ModelName[4], 0x03);
+
+	// Get vender code from model name
+	memcpy(&ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[14], &ShmSysConfigAndInfo->SysConfig.ModelName[12], 0x02);
+	memcpy(&ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev[14], &ShmSysConfigAndInfo->SysConfig.ModelName[12], 0x02);
+
+	DEBUG_INFO("====================================================================\r\n");
+	DEBUG_INFO("Model: %s\r\n", ShmSysConfigAndInfo->SysConfig.ModelName);
+	DEBUG_INFO("CSU hardware version: %s\r\n", ShmSysConfigAndInfo->SysInfo.CsuHwRev);
+	DEBUG_INFO("CSU boot loader version: %s\r\n", ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev);
+	DEBUG_INFO("CSU kernel version: %s\r\n", ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev);
+	DEBUG_INFO("CSU root file system version: %s\r\n", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
+	DEBUG_INFO("CSU MCU-%2d firmware version: %s\r\n", gun_index, ShmCharger->gun_info[gun_index].ver.Version_FW);
+	DEBUG_INFO("====================================================================\r\n");
+}
+
+//===============================================
+// Upgrade firmware
+//===============================================
+int upgrade_check()
+{
+	int result = PASS;
+	int fd;
+	DIR *dir;
+	struct dirent *file;
+	char cmd[512];
+	long int MaxLen=48*1024*1024;
+
+	if ((dir = opendir ("/mnt")) != NULL)
+	{
+		/* print all the files and directories within directory */
+		while ((file = readdir (dir)) != NULL)
+		{
+			if(strlen(file->d_name)>2)
+			{
+				memset(&ShmCharger->fwUpgradeInfo, 0xFF, sizeof(Fw_Upgrade_Info));
+				DEBUG_INFO("New firmware file: %s\n", file->d_name);
+				sprintf(ShmCharger->fwUpgradeInfo.location, "/mnt/%s", file->d_name);
+
+				if((fd=open(ShmCharger->fwUpgradeInfo.location, O_RDONLY)) >= 0)
+				{
+					unsigned char *ptr = malloc(MaxLen); //-48 is take out the header
+					memset(ptr, 0xFF, MaxLen);  //-48 is take out the header
+					read(fd, ptr, MaxLen);
+					close(fd);
+
+					ShmCharger->fwUpgradeInfo.fwType = ((ptr[0x13]<<0) | (ptr[0x12]<<8) | (ptr[0x11]<<16) | (ptr[0x10]<<24));
+					substr(ShmCharger->fwUpgradeInfo.modelName, (char *)ptr, 0, 0x10);
+					DEBUG_INFO("New firmware type: %X\r\n", ShmCharger->fwUpgradeInfo.fwType);
+					DEBUG_INFO("New firmware model name: %s, %s\r\n", ShmCharger->fwUpgradeInfo.modelName, ShmSysConfigAndInfo->SysConfig.ModelName);
+
+					if((strcmp(ShmCharger->fwUpgradeInfo.modelName, (char*)ShmSysConfigAndInfo->SysConfig.ModelName)==0) && (ShmCharger->fwUpgradeInfo.fwType>0))
+					{
+						switch(ShmCharger->fwUpgradeInfo.fwType)
+						{
+							case CSU_BOOTLOADER:
+							case CSU_KERNEL_CONFIGURATION:
+							case CSU_KERNEL_IMAGE:
+							case CSU_ROOT_FILE_SYSTEM:
+							case CSU_USER_CONFIGURATION:
+							case CSU_PRIMARY_CONTROLLER:
+								if(Upgrade_Flash(ShmCharger->fwUpgradeInfo.fwType, ShmCharger->fwUpgradeInfo.location, ShmCharger->fwUpgradeInfo.modelName) != PASS)
+									result = FAIL;
+
+								sprintf(cmd, "yes|rm %s", ShmCharger->fwUpgradeInfo.location);
+								system(cmd);
+								break;
+							case AC_WALLMOUNT_CONTROLLER:
+								for(int gun_index = 0;gun_index<AC_QUANTITY;gun_index++)
+									ShmCharger->gun_info[gun_index].mcuFlag.isMcuUpgradeReq = ON;
+								break;
+							default:
+								result = FAIL;
+								DEBUG_WARN("Image file is unknown type.\r\n");
+								sprintf(cmd, "yes|rm %s", ShmCharger->fwUpgradeInfo.location);
+								system(cmd);
+								break;
+						}
+					}
+
+					free(ptr);
+				}
+				else
+				{
+					// File open error
+					DEBUG_ERROR("New firmware open error.\r\n");
+				}
+			}
+		}
+		closedir (dir);
+	}
+	else
+	{
+	  DEBUG_ERROR("/mnt does not valid.\r\n");
+	}
+
+	return result;
+}
+
+//===============================================
+// Check RFID is match with start user
+//===============================================
+int isMatchStartUser(unsigned char gun_index)
+{
+	uint8_t tmpUser[32];
+
+	if(ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian)
+	{
+		// Big endian
+		switch(rfid.snType)
+		{
+			case RFID_SN_TYPE_6BYTE:
+				sprintf((char*)tmpUser, "%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*)tmpUser, "%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*)tmpUser, "%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:
+			default:
+				sprintf((char*)tmpUser, "%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3]);
+				break;
+		}
+	}
+	else
+	{
+		// Little endian
+		switch(rfid.snType)
+		{
+			case RFID_SN_TYPE_6BYTE:
+				sprintf((char*)tmpUser, "%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*)tmpUser, "%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*)tmpUser, "%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:
+			default:
+				sprintf((char*)tmpUser, "%02X%02X%02X%02X", rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]);
+				break;
+		}
+	}
+
+	return ((strcmp((char*)tmpUser, (char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId)==0)?YES:NO);
+}
+
+//===============================================
+//	Read RFID Serial Number
+//===============================================
+int GetCardSerialNumber()
+{
+	int isSuccess = FAIL;
+	int module_type = MODULE_EWT;
+
+	if(getRequestCardSN(rfidFd,module_type,&rfid))
+	{
+		if(rfid.cardType == ISO14443A)
+		{
+			if(rfid.snType == RFID_SN_TYPE_4BYTE)
+			{
+				isSuccess = PASS;
+			}
+			else if (rfid.snType == RFID_SN_TYPE_7BYTE)
+			{
+				isSuccess = PASS;
+			}
+		}
+		else if(rfid.cardType == IS014443B)
+		{
+			isSuccess = PASS;
+		}
+		else if(rfid.cardType == FELICA)
+		{
+			isSuccess = PASS;
+		}
+		else
+		{}
+	}
+	else
+	{}
+
+	return isSuccess;
+}
+
+//===============================================
+// Alarm value check
+//===============================================
+int GetAlarmValue()
+{
+	int result = PASS;
+
+	if( (ShmStatusCodeData->AlarmCode.AlarmEvents.AlarmVal[0] > 0) || (ShmStatusCodeData->AlarmCode.AlarmEvents.AlarmVal[1] > 0) || (ShmStatusCodeData->AlarmCode.AlarmEvents.AlarmVal[2] > 0) ||
+		(ShmStatusCodeData->AlarmCode.AlarmEvents.AlarmVal[3] > 0) || (ShmStatusCodeData->AlarmCode.AlarmEvents.AlarmVal[4] > 0) || (ShmStatusCodeData->AlarmCode.AlarmEvents.AlarmVal[5] > 0) ||
+		(ShmStatusCodeData->AlarmCode.AlarmEvents.AlarmVal[6] > 0) || (ShmStatusCodeData->AlarmCode.AlarmEvents.AlarmVal[7] > 0))
+	{
+		result = FAIL;
+	}
+
+	return result;
+}
+
+//===============================================
+// Info value check
+//===============================================
+int GetInfoValue()
+{
+	int result = PASS;
+
+	if( (ShmStatusCodeData->InfoCode.InfoEvents.InfoVal[0] > 0) || (ShmStatusCodeData->InfoCode.InfoEvents.InfoVal[1] > 0) || (ShmStatusCodeData->InfoCode.InfoEvents.InfoVal[2] > 0) ||
+		(ShmStatusCodeData->InfoCode.InfoEvents.InfoVal[3] > 0) || (ShmStatusCodeData->InfoCode.InfoEvents.InfoVal[4] > 0) || (ShmStatusCodeData->InfoCode.InfoEvents.InfoVal[5] > 0) ||
+		(ShmStatusCodeData->InfoCode.InfoEvents.InfoVal[6] > 0) || (ShmStatusCodeData->InfoCode.InfoEvents.InfoVal[7] > 0) || (ShmStatusCodeData->InfoCode.InfoEvents.InfoVal[8] > 0) ||
+		(ShmStatusCodeData->InfoCode.InfoEvents.InfoVal[9] > 0))
+	{
+		result = FAIL;
+	}
+
+	return result;
+}
+
+//===============================================
+// Fault value check
+//===============================================
+int GetFaultValue()
+{
+	int result = PASS;
+
+	if( (ShmStatusCodeData->FaultCode.FaultEvents.FaultVal[0] > 0) ||
+		(ShmStatusCodeData->FaultCode.FaultEvents.FaultVal[1] > 0) ||
+		(ShmStatusCodeData->FaultCode.FaultEvents.FaultVal[2] > 0) ||
+		(ShmStatusCodeData->FaultCode.FaultEvents.FaultVal[3] > 0))
+	{
+		result = FAIL;
+	}
+
+	return result;
+}
+
+//===============================================
+// Set led motion
+//===============================================
+void setLedMotion(unsigned char gun_index,unsigned char led_mode)
+{
+	switch(led_mode)
+	{
+		case LED_ACTION_INIT:
+			ShmCharger->gun_info[gun_index].primaryMcuLed.mode = LED_ACTION_INIT;
+			break;
+		case LED_ACTION_IDLE:
+			ShmCharger->gun_info[gun_index].primaryMcuLed.mode = LED_ACTION_IDLE;
+			break;
+		case LED_ACTION_AUTHED:
+			ShmCharger->gun_info[gun_index].primaryMcuLed.mode = LED_ACTION_AUTHED;
+			break;
+		case LED_ACTION_CONNECTED:
+			ShmCharger->gun_info[gun_index].primaryMcuLed.mode = LED_ACTION_CONNECTED;
+			break;
+		case LED_ACTION_CHARGING:
+			ShmCharger->gun_info[gun_index].primaryMcuLed.mode = LED_ACTION_CHARGING;
+			break;
+		case LED_ACTION_STOP:
+			ShmCharger->gun_info[gun_index].primaryMcuLed.mode = LED_ACTION_STOP;
+			break;
+		case LED_ACTION_ALARM:
+			ShmCharger->gun_info[gun_index].primaryMcuLed.mode = LED_ACTION_ALARM;
+			break;
+		case LED_ACTION_MAINTAIN:
+			ShmCharger->gun_info[gun_index].primaryMcuLed.mode = LED_ACTION_MAINTAIN;
+			break;
+		case LED_ACTION_RFID_PASS:
+			ShmCharger->gun_info[gun_index].primaryMcuLed.mode = LED_ACTION_RFID_PASS;
+			break;
+		case LED_ACTION_RFID_FAIL:
+			ShmCharger->gun_info[gun_index].primaryMcuLed.mode = LED_ACTION_RFID_FAIL;
+			break;
+		case LED_ACTION_BLE_CONNECT:
+			ShmCharger->gun_info[gun_index].primaryMcuLed.mode = LED_ACTION_BLE_CONNECT;
+			break;
+		case LED_ACTION_BLE_DISABLE:
+			ShmCharger->gun_info[gun_index].primaryMcuLed.mode = LED_ACTION_BLE_DISABLE;
+			break;
+		case LED_ACTION_DEBUG:
+			ShmCharger->gun_info[gun_index].primaryMcuLed.mode = LED_ACTION_DEBUG;
+			break;
+		case LED_ACTION_ALL_OFF:
+			ShmCharger->gun_info[gun_index].primaryMcuLed.mode = LED_ACTION_ALL_OFF;
+			break;
+		case LED_RELAY_ON:
+			ShmCharger->gun_info[gun_index].primaryMcuLed.mode = LED_RELAY_ON;
+			break;
+		case LED_RELAY_OFF:
+			ShmCharger->gun_info[gun_index].primaryMcuLed.mode = LED_RELAY_OFF;
+			break;
+		case LED_ACTION_HANDSHAKE_FAIL:
+			ShmCharger->gun_info[gun_index].primaryMcuLed.mode = LED_ACTION_HANDSHAKE_FAIL;
+			break;
+		case LED_ACTION_INTERNET_DISCONNECT:
+			ShmCharger->gun_info[gun_index].primaryMcuLed.mode = LED_ACTION_INTERNET_DISCONNECT;
+			break;
+	}
+}
+
+//===============================================
+// Relay on/off request set
+//===============================================
+void setRelay(unsigned char gun_index,unsigned char isOn)
+{
+	if(isOn == ON)
+	{
+		if(ShmCharger->gun_info[gun_index].legacyRequest.isLegacyRequest == OFF)
+		{
+			ShmCharger->gun_info[gun_index].legacyRequest.isLegacyRequest = ON;
+			DEBUG_INFO("Gun-%d Output relay sts: ON \r\n",gun_index);
+		}
+	}
+	else
+	{
+		if(ShmCharger->gun_info[gun_index].legacyRequest.isLegacyRequest == ON)
+		{
+			ShmCharger->gun_info[gun_index].legacyRequest.isLegacyRequest = OFF;
+			DEBUG_INFO("Gun-%d Output relay sts: OFF \r\n",gun_index);
+		}
+	}
+}
+
+//===============================================
+// Relay on/off request get
+//===============================================
+int getRelay(unsigned char gun_index)
+{
+	return ShmCharger->gun_info[gun_index].legacyRequest.isLegacyRequest;
+}
+
+//===============================================
+// Set speaker on/off request
+//===============================================
+void setSpeaker(unsigned char isOn, unsigned char speaker_mode)
+{
+	if(isOn == ON)
+	{
+		ShmCharger->isSpeakerOn = ON;
+		ShmCharger->speaker_type = speaker_mode;
+	}
+}
+
+//===============================================
+// Initialization RFID communication port
+//===============================================
+int InitRfidPort()
+{
+	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;
+}
+
+//===============================================
+// Check internet access status
+//===============================================
+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;
+}
+
+//===============================================
+// 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(DiffTimebWithNow(expiredTime)>=0)
+		{
+			result = YES;
+		}
+	}
+	else
+	{
+		DEBUG_WARN("Expired date parsing error.\r\n");
+		DEBUG_INFO("Date expired.\r\n");
+		result = YES;
+	}
+
+	return result;
+}
+
+//===============================================
+// Valid from local white list
+//===============================================
+int isValidLocalWhiteCard()
+{
+	uint8_t result = FAIL;
+	for(uint8_t idx=0;idx<ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.LocalWhiteCard);idx++)
+	{
+		if(strcmp((char*)ShmSysConfigAndInfo->SysConfig.UserId, (char*)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[idx]) == 0)
+		{
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+//==========================================
+// Get Ethernet MAC address
+//==========================================
+int getEth0MacAddress()
+{
+	int result = PASS;
+	FILE *fp;
+	char cmd[256];
+	char buf[512];
+	char tmp[512];
+
+	strcpy(cmd, "ifconfig");;
+	fp = popen(cmd, "r");
+	if(fp != NULL)
+	{
+		while(fgets(buf, sizeof(buf), fp) != NULL)
+		{
+			if(strstr(buf, "eth0") > 0)
+			{
+				result = PASS;
+			}
+
+			if(strstr(buf, "eth0      Link encap:Ethernet  HWaddr") > 0)
+			{
+				sscanf(buf, "%*s%*s%*s%*s%s", tmp);
+				strcpy((char*)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthMacAddress, tmp);
+			}
+		}
+	}
+	pclose(fp);
+
+	return result;
+}
+
+//==========================================
+// Check task processing
+//==========================================
+void checkTask()
+{
+	if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T')
+	{
+		if(system("pidof -s Module_4g > /dev/null") != 0)
+		{
+			DEBUG_INFO("Module_4g not running, restart it.\r\n");
+			system("/root/Module_4g &");
+		}
+	}
+	else if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W')
+	{
+		if(system("pidof -s Module_Wifi > /dev/null") != 0)
+		{
+			DEBUG_INFO("Module_Wifi not running, restart it.\r\n");
+			system("/root/Module_Wifi &");
+		}
+	}
+
+	if(system("pidof -s Module_EventLogging > /dev/null") != 0)
+	{
+		DEBUG_INFO("Module_EventLogging not running, restart it.\r\n");
+		system("/root/Module_EventLogging &");
+	}
+
+	if(strcmp((char *)&ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0)
+	{
+		if(system("pidof -s OcppBackend > /dev/null") != 0)
+		{
+			DEBUG_INFO("OcppBackend not running, restart it.\r\n");
+			system("/root/OcppBackend &");
+		}
+	}
+
+	if(system("pidof -s Module_AlarmDetect > /dev/null") != 0)
+	{
+		DEBUG_INFO("Module_AlarmDetect not running, restart it.\r\n");
+		system("/root/Module_AlarmDetect &");
+	}
+
+	if(system("pidof -s Module_InternalComm > /dev/null") != 0)
+	{
+		DEBUG_INFO("Module_InternalComm not running, restart it.\r\n");
+		system("/root/Module_InternalComm &");
+	}
+
+	if(system("pidof -s Module_Speaker > /dev/null") != 0)
+	{
+		DEBUG_INFO("Module_Speaker not running, restart it.\r\n");
+		system("/root/Module_Speaker &");
+	}
+
+	if(system("pidof -s Module_ProduceUtils > /dev/null") != 0)
+	{
+		DEBUG_INFO("Module_ProduceUtils not running, restart it.\r\n");
+		system ("/root/Module_ProduceUtils &");
+	}
+}
+
+//===============================================
+// Check Connection Timeout
+//===============================================
+void checkConnectionTimeout()
+{
+	if(system("pidof -s OcppBackend > /dev/null") != 0)
+	{
+		ShmCharger->timeoutSpec.Present_Timeout_Spec = TIMEOUT_SPEC_HANDSHAKING;
+		//DEBUG_INFO("Handshaking timeout specification follow by initial setting : %d s \r\n", TIMEOUT_SPEC_HANDSHAKING/1000);
+	}
+	else
+	{
+		if(strcmp((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData,"") != 0)
+		{
+			ShmCharger->timeoutSpec.Setting_Timeout_Spec = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
+
+			if(ShmCharger->timeoutSpec.Setting_Timeout_Spec <= 0)
+			{
+				ShmCharger->timeoutSpec.Present_Timeout_Spec = TIMEOUT_SPEC_HANDSHAKING;
+				//DEBUG_INFO("Handshaking timeout specification follow by OCPP Configuration : Fail. Value can't be zero or less than zero.\r\n.");
+			}
+			else
+			{
+				ShmCharger->timeoutSpec.Present_Timeout_Spec = (ShmCharger->timeoutSpec.Setting_Timeout_Spec*1000);
+				//DEBUG_INFO("Handshaking timeout specification follow by OCPP Configuration : Pass...\r\n.");
+			}
+			//DEBUG_INFO("Handshaking timeout specification follow by OCPP Configuration : %s s \r\n.",ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
+
+		}
+		else
+		{
+			ShmCharger->timeoutSpec.Present_Timeout_Spec = TIMEOUT_SPEC_HANDSHAKING;
+			//DEBUG_INFO("Handshaking timeout specification follow by OCPP Configuration : Fail. Table is blank...\r\n.");
+		}
+
+		//DEBUG_INFO("Present timeout spec : %d \r\n", ShmCharger->timeoutSpec.Present_Timeout_Spec);
+	}
+}
+
+//===============================================
+// Main process
+//===============================================
+int main(void)
+{
+	//Create all share memory
+	if(CreatShareMemory()==0)
+	{
+		DEBUG_ERROR("CreatShareMemory NG\r\n");
+
+		if(ShmStatusCodeData!=NULL)
+		{
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
+		}
+		sleep(5);
+		system("reboot -f");
+		sleep(5);
+		system("reboot -f");
+	}
+	else
+	{
+		DEBUG_INFO("CreatShareMemory OK\r\n");
+	}
+
+	for(int gun_index = 0;gun_index<AC_QUANTITY;gun_index++)
+	{
+		ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PreviousSystemStatus = 0xff;
+		ShmCharger->gun_info[gun_index].primaryMcuState.rotatory_switch = 0xff;
+		ShmCharger->gun_info[gun_index].mcuResetRequest.isMcuResetRequest = ON;
+		ShmCharger->gun_info[gun_index].isInitialPass = NO;
+	}
+
+	// Main loop
+	for(;;)
+	{
+		//==========================================
+		// Synchronize share memory from OCPP struct
+		//==========================================
+		ShmSysConfigAndInfo->SysInfo.OcppConnStatus = ShmOCPP16Data->OcppConnStatus;
+
+		//==========================================
+		// Ethernet Mac address
+		//==========================================
+		getEth0MacAddress();
+
+		//==========================================
+		// Check task processing
+		//==========================================
+		checkTask();
+
+		//==========================================
+		// Check timeout spec
+		//==========================================
+		checkConnectionTimeout();
+
+		//==========================================
+		// Something need run in Idle mode
+		//==========================================
+		if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[0].SystemStatus==SYS_MODE_IDLE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[0].SystemStatus==SYS_MODE_ALARM)) &&
+		   (AC_QUANTITY>1?((ShmSysConfigAndInfo->SysInfo.AcChargingData[1].SystemStatus==SYS_MODE_IDLE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[1].SystemStatus==SYS_MODE_ALARM)):true))
+		{
+			//======================================
+			// Check restore factory setting request
+			//======================================
+			if(ShmSysConfigAndInfo->SysInfo.FactoryConfiguration)
+			{
+				system("cd /root;./Module_FactoryConfig -m");
+				system("sync");
+				sleep(5);
+				system("reboot -f");
+				sleep(5);
+				system("reboot -f");
+			}
+
+			//======================================
+			// Check upgrade firmware request
+			//======================================
+			if(ShmSysConfigAndInfo->SysInfo.FirmwareUpdate ||
+			   ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq)
+			{
+				ShmCharger->isUpdateSuccess = FAIL;
+				for(int gun_index = 0;gun_index<AC_QUANTITY;gun_index++)
+				{
+					setLedMotion(gun_index,LED_ACTION_MAINTAIN);
+					setChargerMode(gun_index, SYS_MODE_UPDATE);
+				}
+			}
+		}
+
+		//==========================================
+		// Check remote reset request
+		//==========================================
+		if(ShmOCPP16Data->MsMsg.bits.ResetReq)
+		{
+			if((!isMode(0, SYS_MODE_CHARGING) && !isMode(0, SYS_MODE_TERMINATING)) &&
+			   (AC_QUANTITY>1?(!isMode(1, SYS_MODE_CHARGING) && !isMode(1, SYS_MODE_TERMINATING)):true))
+			{
+				ShmOCPP16Data->MsMsg.bits.ResetReq = OFF;
+
+				if(strcmp((char*)ShmOCPP16Data->Reset.Type, "Hard") == 0)
+				{
+					system("sync");
+					sleep(5);
+					system("reboot -f");
+					sleep(5);
+					system("reboot -f");
+				}
+				else
+				{
+					system("/usr/bin/run_evse_restart.sh");
+				}
+			}
+		}
+
+		//==========================================
+		// Check RFID
+		//==========================================
+		if(!ShmCharger->gun_info[ShmCharger->gun_selectd].rfidReq)
+		{
+			if(GetCardSerialNumber()!= FAIL)
+			{
+				ShmCharger->gun_info[ShmCharger->gun_selectd].rfidReq = ON;
+			}
+		}
+
+		//==========================================
+		// Connector loop
+		//==========================================
+		for(int gun_index = 0;gun_index<AC_QUANTITY;gun_index++)
+		{
+			// Synchronize current rating value from MCU
+			ShmSysConfigAndInfo->SysConfig.RatingCurrent = ShmCharger->gun_info[gun_index].primaryMcuState.rating_current;
+
+			// Assign connector location index for OCPP
+			ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].Index = gun_index;
+
+			// Synchronize present charging power
+			if(ShmCharger->gun_info[gun_index].primaryMcuState.relay_state == ON)
+				ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingPower = (ShmSysConfigAndInfo->SysInfo.InputVoltageR* ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrent)/1000;
+			else
+				ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingPower = 0;
+
+			// The system switch to Booting mode
+			if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus == 0XFF)
+			{
+				setChargerMode(gun_index, SYS_MODE_BOOTING);
+			}
+
+			// Check initialization "PASS" or "FAIL"
+			if(ShmCharger->gun_info[gun_index].isInitialPass == YES)
+			{
+				// Alarm event check
+				if((ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode>0))
+				{
+					if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus != SYS_MODE_ALARM)
+					{
+						setChargerMode(gun_index, SYS_MODE_ALARM);
+					}
+				}
+				else
+				{
+					if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus == SYS_MODE_ALARM)
+					{
+
+					}
+				}
+			}
+
+			// Reservation request check
+			if(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowReq)
+			{
+				ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowReq = OFF;
+				if(isMode(gun_index, SYS_MODE_IDLE) && !isReservationExpired(gun_index))
+				{
+					ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].ReservationId = ShmOCPP16Data->ReserveNow[gun_index].ReservationId;
+					setChargerMode(gun_index, SYS_MODE_RESERVATION);
+				}
+				DEBUG_INFO("Reservation request on connector-%d.\r\n", gun_index);
+				ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = ON;
+			}
+
+			// Change availability check
+			if(ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityReq)
+			{
+				if(strcmp((char*)ShmOCPP16Data->ChangeAvailability[gun_index].Type, "Operative") == 0)
+				{
+					if(isMode(gun_index, SYS_MODE_MAINTAIN))
+					{
+						setChargerMode(gun_index, SYS_MODE_IDLE);
+						ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityReq = OFF;
+					}
+				}
+				else
+				{
+					if(isMode(gun_index, SYS_MODE_IDLE))
+					{
+						setChargerMode(gun_index, SYS_MODE_MAINTAIN);
+						ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityReq = OFF;
+					}
+				}
+			}
+
+			// Connector process
+			switch(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus)
+			{
+				case SYS_MODE_BOOTING:
+					if(isModeChange(gun_index))
+					{
+						setLedMotion(gun_index,LED_ACTION_INIT);
+
+						//CSU Initialization & task spawn
+						if((Initialization() != PASS) ||
+						   (SpawnTask() != PASS) )
+						{
+							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = ON;
+						}
+					}
+
+					if(ShmCharger->gun_info[gun_index].mcuFlag.isReadFwVerPass &&
+					   ShmCharger->gun_info[gun_index].mcuFlag.isSetModelNamePass &&
+					   ShmCharger->gun_info[gun_index].mcuFlag.isSetSerialNumberPass)
+					{
+						ShmCharger->gun_selectd = 0;
+
+						// Firmware version
+						get_firmware_version(gun_index);
+
+						// OCPP BootNotification info set
+						memcpy((char*)ShmOCPP16Data->OcppServerURL, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
+						memcpy((char*)ShmOCPP16Data->ChargeBoxId, (char*)ShmSysConfigAndInfo->SysConfig.ChargeBoxId, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ChargeBoxId));
+						sprintf((char*)ShmOCPP16Data->BootNotification.CpFwVersion, (char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
+						sprintf((char*)ShmOCPP16Data->BootNotification.CpMeterSerialNumber, "N/A");
+						sprintf((char*)ShmOCPP16Data->BootNotification.CpMeterType, "AC");
+
+						DEBUG_INFO("==========================================\r\n");
+						DEBUG_INFO("System ID: %s\r\n",ShmSysConfigAndInfo->SysConfig.SystemId);
+						DEBUG_INFO("==========================================\r\n");
+
+						DEBUG_INFO("========== OCPP BootNotification information ==========\r\n");
+						DEBUG_INFO("OCPP OcppServerURL: %s\r\n",ShmSysConfigAndInfo->SysConfig.OcppServerURL);
+						DEBUG_INFO("OCPP ChargeBoxId: %s\r\n",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
+						DEBUG_INFO("OCPP ChargePointVendor: %s\r\n",ShmSysConfigAndInfo->SysConfig.chargePointVendor);
+						DEBUG_INFO("OCPP CpFwVersion: %s\r\n",ShmOCPP16Data->BootNotification.CpFwVersion);
+						DEBUG_INFO("OCPP CpMeterSerialNumber: %s\r\n",ShmOCPP16Data->BootNotification.CpMeterSerialNumber);
+						DEBUG_INFO("OCPP CpMeterType: %s\r\n",ShmOCPP16Data->BootNotification.CpMeterType);
+						DEBUG_INFO("=======================================================\r\n");
+
+						DEBUG_INFO("========== Set Wifi information ==========\r\n");
+						DEBUG_INFO("Wifi mode: %d\r\n",  ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode);
+						DEBUG_INFO("Wifi SSID: %s\r\n",  ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid);
+						DEBUG_INFO("Wifi password: %s\r\n",  ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword);
+						DEBUG_INFO("==========================================\r\n");
+
+						// Flag for initialization system success
+						ShmCharger->gun_info[gun_index].isInitialPass = YES;
+
+						// Set max current to rating current
+						ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current = ShmCharger->gun_info[gun_index].primaryMcuState.rating_current;
+
+						// If rotate switch equal zero, the system needs to change Debug mode
+						if(ShmCharger->gun_info[gun_index].primaryMcuState.rotatory_switch == 0)
+							setChargerMode(gun_index, SYS_MODE_DEBUG);
+						else
+							setChargerMode(gun_index, SYS_MODE_IDLE);
+					}
+
+					break;
+				case SYS_MODE_IDLE:
+					if(isModeChange(gun_index))
+					{
+						setLedMotion(gun_index,LED_ACTION_IDLE);
+						setRelay(gun_index,OFF);
+						ShmCharger->gun_info[gun_index].isGunPlugged = NO;
+						ShmCharger->gun_info[gun_index].rfidReq = OFF;
+						ShmCharger->gun_info[gun_index].bleConfigData.isRequestStart = OFF;
+						ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop = OFF;
+						ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStartTransactionReq = OFF;
+						ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq = OFF;
+						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode = 0x00;
+						ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration = 0;
+						ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy = 0;
+						ShmCharger->gun_info[gun_index].targetCurrent = 0xFF;
+						ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current = ShmCharger->gun_info[gun_index].primaryMcuState.rating_current;
+
+						// Response StopTransactionConf
+						if(ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf == ON)
+							ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = OFF;
+					}
+
+					if(((ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_FREE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_B)) ||
+					   ((ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_FREE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_C)) ||
+					   (ShmCharger->gun_info[gun_index].rfidReq == ON) ||
+					   (ShmCharger->gun_info[gun_index].bleConfigData.isRequestStart == ON) ||
+					   (ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStartTransactionReq == ON))
+					{
+						// Clean User id & Card Number
+						memset(ShmSysConfigAndInfo->SysConfig.UserId, 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.UserId));
+
+						if((ShmCharger->gun_info[gun_index].rfidReq == ON))
+						{
+							ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod = START_METHOD_RFID;
+							DEBUG_INFO("Start Method : RFID...\r\n");
+
+							if(ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian)
+							{
+								// Big endian
+								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:
+									default:
+										sprintf((char*)ShmSysConfigAndInfo->SysConfig.UserId, "%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3]);
+										break;
+								}
+							}
+							else
+							{
+								// Little endian
+								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:
+									default:
+										sprintf((char*)ShmSysConfigAndInfo->SysConfig.UserId, "%02X%02X%02X%02X", rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]);
+										break;
+								}
+							}
+
+							DEBUG_INFO("Start request User Id : %s\r\n", ShmSysConfigAndInfo->SysConfig.UserId);
+						}
+						else if(ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStartTransactionReq)
+						{
+							ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod = START_METHOD_BACKEND;
+							memcpy(ShmSysConfigAndInfo->SysConfig.UserId, ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, ARRAY_SIZE(ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag));
+							DEBUG_INFO("Start Method : BACKEND...\r\n");
+						}
+						else if(ShmCharger->gun_info[gun_index].bleConfigData.isRequestStart == ON)
+						{
+							ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod = START_METHOD_BLE;
+							memcpy(ShmSysConfigAndInfo->SysConfig.UserId, ShmCharger->gun_info[gun_index].bleLoginCentralId.id, ARRAY_SIZE(ShmCharger->gun_info[gun_index].bleLoginCentralId.id));
+							DEBUG_INFO("Start Method : BLE...\r\n");
+						}
+						else
+						{
+							ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod = START_METHOD_FREE;
+							DEBUG_INFO("Start Method : FREE..\r\n");
+						}
+
+						ShmCharger->gun_info[gun_index].rfidReq = OFF;
+						ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStartTransactionReq = OFF;
+						ShmCharger->gun_info[gun_index].bleConfigData.isRequestStart = OFF;
+						ShmCharger->gun_info[gun_index].isGunPlugged = NO;
+
+						setChargerMode(gun_index, SYS_MODE_AUTHORIZING);
+					}
+					else
+					{}
+
+					break;
+				case SYS_MODE_AUTHORIZING:
+					if(isModeChange(gun_index))
+					{
+						ftime(&startTime[gun_index][TMR_IDX_AUTH]);
+
+						if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod == START_METHOD_RFID)
+						{
+							switch(ShmSysConfigAndInfo->SysConfig.AuthorisationMode)
+							{
+								case AUTH_MODE_BACKEND_OCPP:
+									if(ShmOCPP16Data->OcppConnStatus)
+									{
+										// On line
+										ShmOCPP16Data->SpMsg.bits.AuthorizeReq = ON;
+									}
+									else
+									{
+										// Off line
+										switch(ShmSysConfigAndInfo->SysConfig.OfflinePolicy)
+										{
+											case OFF_POLICY_LOCALLIST:
+												ShmOCPP16Data->SpMsg.bits.AuthorizeReq = ON;
+												break;
+											case OFF_POLICY_PH_RFID:
+												break;
+											case OFF_POLICY_FREE:
+												break;
+											case OFF_POLICY_NOCHARGE:
+											default:
+												break;
+										}
+									}
+									break;
+								case AUTH_MODE_FREE:
+								default:
+									break;
+							}
+						}
+					}
+
+					if(DiffTimebWithNow(startTime[gun_index][TMR_IDX_AUTH]) > TIMEOUT_SPEC_AUTH)
+					{
+						// Authorization timeout process.
+						ShmCharger->gun_info[gun_index].rfidReq = OFF;
+						setChargerMode(gun_index, SYS_MODE_IDLE);
+						DEBUG_WARN("Authorize timeout!\r\n");
+					}
+					else
+					{
+						switch(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod)
+						{
+							case START_METHOD_RFID:
+								if(ShmOCPP16Data->SpMsg.bits.AuthorizeConf ||
+								  (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_FREE) ||
+								  !ShmOCPP16Data->OcppConnStatus ||
+								  ((isValidLocalWhiteCard() == PASS) && (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == OFF_POLICY_LOCALLIST)))
+								{
+									if((strcmp((char*)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted")==0) ||
+									   (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_FREE) ||
+									   (!ShmOCPP16Data->OcppConnStatus&&(ShmSysConfigAndInfo->SysConfig.OfflinePolicy == OFF_POLICY_FREE)) ||
+									   ((isValidLocalWhiteCard() == PASS) && (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == OFF_POLICY_LOCALLIST)))
+									{
+										DEBUG_INFO("Authorize pass.\r\n");
+										setSpeaker(ON,SPEAKER_SHORT);
+										setLedMotion(gun_index,LED_ACTION_RFID_PASS);
+										sleep(3);
+										setChargerMode(gun_index, SYS_MODE_PREPARING);
+									}
+									else
+									{
+										DEBUG_INFO("Authorize fail.\r\n");
+										setSpeaker(ON,SPEAKER_INTERVAL_3COUNT);
+										setLedMotion(gun_index,LED_ACTION_RFID_FAIL);
+										sleep(3);
+										setChargerMode(gun_index, SYS_MODE_IDLE);
+									}
+
+									ShmCharger->gun_info[gun_index].rfidReq = OFF;
+									ShmOCPP16Data->SpMsg.bits.AuthorizeConf = OFF;
+								}
+								break;
+							case START_METHOD_BACKEND:
+							case START_METHOD_BLE:
+							case START_METHOD_FREE:
+							default:
+								setSpeaker(ON,SPEAKER_SHORT);
+								setChargerMode(gun_index, SYS_MODE_PREPARING);
+								break;
+						}
+					}
+
+					break;
+				case SYS_MODE_PREPARING:
+					if(isModeChange(gun_index))
+					{
+						ftime(&startTime[gun_index][TMR_IDX_HANDSHAKING]);
+						setRelay(gun_index, ON);
+						setLedMotion(gun_index,LED_ACTION_CONNECTED);
+					}
+
+					// If control pilot detect Bx, skip watch dog time out.
+					if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_B)
+					{
+						ftime(&startTime[gun_index][TMR_IDX_HANDSHAKING]);
+						ShmCharger->gun_info[gun_index].isGunPlugged = YES;
+					}
+
+					if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_A) && (ShmCharger->gun_info[gun_index].isGunPlugged == YES))
+					{
+						DEBUG_INFO("Charging gun is plugged before.\r\n");
+						setChargerMode(gun_index, SYS_MODE_IDLE);
+					}
+
+					if(DiffTimebWithNow(startTime[gun_index][TMR_IDX_HANDSHAKING]) > ShmCharger->timeoutSpec.Present_Timeout_Spec)
+					{
+						setLedMotion(gun_index, LED_ACTION_HANDSHAKE_FAIL);
+
+						if(DiffTimebWithNow(startTime[gun_index][TMR_IDX_HANDSHAKING]) > (ShmCharger->timeoutSpec.Present_Timeout_Spec+5000))
+						{
+							DEBUG_INFO("Handshaking timeout...");
+							setChargerMode(gun_index, SYS_MODE_IDLE);
+						}
+					}
+					else if((ShmCharger->gun_info[gun_index].primaryMcuState.relay_state == ON))
+					{
+						ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].OutputEnergy = 0;
+						ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy = 0;
+						getDateTimeString((char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartDateTime);
+						ShmCharger->gun_info[gun_index].powerConsumption.power_consumption_at_start = ShmCharger->gun_info[gun_index].powerConsumption.power_consumption;
+						ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (ShmCharger->gun_info[gun_index].powerConsumption.power_consumption/100);
+						memcpy((char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId, ShmSysConfigAndInfo->SysConfig.UserId, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.UserId));
+
+						memcpy((char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId, ARRAY_SIZE(ShmOCPP16Data->StartTransaction[gun_index].IdTag));
+						ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = ON;
+
+						setChargerMode(gun_index, SYS_MODE_CHARGING);
+					}
+
+					break;
+				case SYS_MODE_CHARGING:
+					if(isModeChange(gun_index))
+					{
+						ShmCharger->gun_info[gun_index].rfidReq = OFF;
+						ftime(&startChargingTime[gun_index]);
+						ftime(&startTime[gun_index][TMR_IDX_LOGPPRINTOUT]);
+					}
+
+					if((ShmCharger->gun_info[gun_index].rfidReq == ON) ||
+					   (ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop == ON) ||
+					   (ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq == ON)||
+					   (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState != CP_STATE_C) ||
+					   ShmOCPP16Data->MsMsg.bits.ResetReq)
+					{
+						setChargerMode(gun_index, SYS_MODE_TERMINATING);
+					}
+					else
+					{
+						setLedMotion(gun_index,LED_ACTION_CHARGING);
+						ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (ShmCharger->gun_info[gun_index].powerConsumption.power_consumption - ShmCharger->gun_info[gun_index].powerConsumption.power_consumption_at_start)/100;
+						ftime(&endChargingTime[gun_index]);
+						ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index])/1000;
+						ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy = ((float)(ShmCharger->gun_info[gun_index].powerConsumption.power_consumption - ShmCharger->gun_info[gun_index].powerConsumption.power_consumption_at_start))/100;
+						ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].OutputEnergy =  ((float)(ShmCharger->gun_info[gun_index].powerConsumption.power_consumption - ShmCharger->gun_info[gun_index].powerConsumption.power_consumption_at_start))/100;
+
+						// Response StartTransactionConf
+						if(ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf == ON)
+							ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = OFF;
+
+						/*
+						 * TODO:
+						 * 	1. Query target current from charging profile
+						 */
+						// Checking charging profile target current
+
+						// Determine max charging current to MCU
+						if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
+						{
+							ShmCharger->gun_info[gun_index].targetCurrent = ((ShmCharger->gun_info[gun_index].targetCurrent > ShmCharger->gun_info[gun_index].primaryMcuState.rating_current)?ShmCharger->gun_info[gun_index].primaryMcuState.rating_current:ShmCharger->gun_info[gun_index].targetCurrent);
+							if(ShmCharger->gun_info[gun_index].targetCurrent != ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current)
+							{
+								ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current = ((ShmCharger->gun_info[gun_index].targetCurrent > ShmCharger->gun_info[gun_index].primaryMcuState.rating_current)?ShmCharger->gun_info[gun_index].primaryMcuState.rating_current:ShmCharger->gun_info[gun_index].targetCurrent);
+								ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty = YES;
+							}
+						}
+						else
+						{
+							ShmCharger->gun_info[gun_index].targetCurrent = ((ShmCharger->gun_info[gun_index].targetCurrent > ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent)?ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent:ShmCharger->gun_info[gun_index].targetCurrent);
+							if(ShmCharger->gun_info[gun_index].targetCurrent != ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current)
+							{
+								ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current = ((ShmCharger->gun_info[gun_index].targetCurrent > ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent)?ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent:ShmCharger->gun_info[gun_index].targetCurrent);
+								ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty = YES;
+							}
+						}
+
+						// Debug information
+						if(DiffTimebWithNow(startTime[gun_index][TMR_IDX_LOGPPRINTOUT]) > TIMEOUT_SPEC_LOGPPRINTOUT)
+						{
+							DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent: %d \r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
+							DEBUG_INFO("ShmCharger->gun_info[%d].primaryMcuCp_Pwn_Duty.max_current: %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current);
+							DEBUG_INFO("ShmCharger->gun_info[%d].targetCurrent: %d\r\n", gun_index, ShmCharger->gun_info[gun_index].targetCurrent);
+							ftime(&startTime[gun_index][TMR_IDX_LOGPPRINTOUT]);
+						}
+
+						if(ShmOCPP16Data->OcppConnStatus)
+						{
+							// On-line max condition check
+							if((ShmSysConfigAndInfo->SysConfig.MaxChargingDuration > 0) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration >= (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration*60)))
+							{
+								setChargerMode(gun_index, SYS_MODE_TERMINATING);
+								DEBUG_INFO("Connector-%d charging duration(%d) already over max duration(%d) in second.\r\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration, (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration*60));
+							}
+							else if((ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy > 0) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy >= ((float)ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy)))
+							{
+								setChargerMode(gun_index, SYS_MODE_TERMINATING);
+								DEBUG_INFO("Connector-%d charging energy(%.2f) already over max energy(%.2f) in KWH.\r\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy, ((float)ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy));
+							}
+							else
+							{
+								setRelay(gun_index, ON);
+							}
+						}
+						else
+						{
+							// Off-line max condition check
+							if(ShmSysConfigAndInfo->SysConfig.OfflinePolicy != OFF_POLICY_NOCHARGE)
+							{
+								if(((ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration > 0) ? (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration >= (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration*60)) : (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration > 0) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration >= (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration*60))))
+								{
+									setChargerMode(gun_index, SYS_MODE_TERMINATING);
+									DEBUG_INFO("Connector-%d charging duration(%d) already over off-line max duration(%d) in second.\r\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration, (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration*60));
+								}
+								else if(((ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy > 0) ? (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy >= ((float)ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy)) : (ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy > 0) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy >= ((float)ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy))))
+								{
+									setChargerMode(gun_index, SYS_MODE_TERMINATING);
+									DEBUG_INFO("Connector-%d charging energy(%.2f) already over off-line max energy(%.2f) in KWH.\r\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy, ((float)ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy));
+								}
+								else
+								{
+									setRelay(gun_index, ON);
+								}
+							}
+							else
+							{
+								setRelay(gun_index, OFF);
+								DEBUG_INFO("Connector-%d can not charging in off line\r\n", gun_index);
+							}
+						}
+					}
+
+					break;
+				case SYS_MODE_TERMINATING:
+					if(isModeChange(gun_index))
+					{
+						if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration != 0)
+						{
+							ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index])/1000;
+						}
+
+						setLedMotion(gun_index, LED_ACTION_STOP);
+						getDateTimeString((char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StopDateTime);
+					}
+
+					// If RFID SN different with start user, it need to authorize ID
+					if((ShmCharger->gun_info[gun_index].rfidReq == ON) && !isMatchStartUser(gun_index))
+					{
+						if((DiffTimebWithNow(startTime[gun_index][TMR_IDX_AUTH]) > TIMEOUT_SPEC_AUTH) && !ShmOCPP16Data->SpMsg.bits.AuthorizeReq)
+						{
+							// Request authorization
+							ftime(&startTime[gun_index][TMR_IDX_AUTH]);
+							memset(ShmSysConfigAndInfo->SysConfig.UserId, 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.UserId));
+							if(ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian)
+							{
+								// Big endian
+								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:
+									default:
+										sprintf((char*)ShmSysConfigAndInfo->SysConfig.UserId, "%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3]);
+										break;
+								}
+							}
+							else
+							{
+								// Little endian
+								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:
+									default:
+										sprintf((char*)ShmSysConfigAndInfo->SysConfig.UserId, "%02X%02X%02X%02X", rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]);
+										break;
+								}
+							}
+							DEBUG_INFO("End request User Id : %s\r\n", ShmSysConfigAndInfo->SysConfig.UserId);
+
+							if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod == START_METHOD_RFID)
+							{
+								switch(ShmSysConfigAndInfo->SysConfig.AuthorisationMode)
+								{
+									case AUTH_MODE_BACKEND_OCPP:
+										if(ShmOCPP16Data->OcppConnStatus)
+										{
+											// On line
+											ShmOCPP16Data->SpMsg.bits.AuthorizeReq = ON;
+										}
+										else
+										{
+											// Off line
+											switch(ShmSysConfigAndInfo->SysConfig.OfflinePolicy)
+											{
+												case OFF_POLICY_LOCALLIST:
+													ShmOCPP16Data->SpMsg.bits.AuthorizeReq = ON;
+													break;
+												case OFF_POLICY_PH_RFID:
+													break;
+												case OFF_POLICY_FREE:
+													break;
+												case OFF_POLICY_NOCHARGE:
+												default:
+													break;
+											}
+										}
+										break;
+									case AUTH_MODE_FREE:
+									default:
+										break;
+								}
+							}
+						}
+						else
+						{
+							if(ShmOCPP16Data->SpMsg.bits.AuthorizeConf ||
+							  (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_FREE) ||
+							  !ShmOCPP16Data->OcppConnStatus)
+							{
+								if((strcmp((char*)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted")==0) ||
+								   (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_FREE) ||
+								   (!ShmOCPP16Data->OcppConnStatus&&(ShmSysConfigAndInfo->SysConfig.OfflinePolicy == OFF_POLICY_FREE)))
+								{
+									ShmCharger->gun_info[gun_index].isAuthPassEnd = ON;
+								}
+								else
+								{
+									ShmCharger->gun_info[gun_index].rfidReq = OFF;
+								}
+
+								ShmOCPP16Data->SpMsg.bits.AuthorizeConf = OFF;
+							}
+						}
+					}
+
+					// End authorize pass
+					if(((ShmCharger->gun_info[gun_index].rfidReq == ON) && isMatchStartUser(gun_index)) ||
+					   (ShmCharger->gun_info[gun_index].isAuthPassEnd) ||
+					   (ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop == ON) ||
+					   (ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq == ON) ||
+					   (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_A) ||
+					   ShmOCPP16Data->MsMsg.bits.ResetReq)
+					{
+						if(ShmCharger->gun_info[gun_index].legacyRequest.isLegacyRequest == ON)
+							setSpeaker(ON,SPEAKER_SHORT);
+
+						setRelay(gun_index, OFF);
+
+						if(!ShmCharger->gun_info[gun_index].primaryMcuState.relay_state)
+						{
+							if(ShmOCPP16Data->MsMsg.bits.ResetReq)
+							{
+								if(strcmp((char*)ShmOCPP16Data->Reset.Type, "Hard")==0)
+									sprintf((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "HardReset");
+								else
+									sprintf((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "SoftReset");
+							}
+							else if(ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)
+							{
+								sprintf((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "Remote");
+							}
+							else if(ShmCharger->gun_info[gun_index].rfidReq || ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop)
+							{
+								sprintf((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "Local");
+							}
+							else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_A)
+							{
+								sprintf((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
+							}
+							else
+							{
+								sprintf((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "Other");
+							}
+
+							memcpy((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].IdTag));
+							ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (ShmCharger->gun_info[gun_index].powerConsumption.power_consumption/100);
+							ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = ON;
+
+							ShmCharger->gun_info[gun_index].rfidReq = OFF;
+							ShmCharger->gun_info[gun_index].isAuthPassEnd = OFF;
+							ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop = OFF;
+							ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq = OFF;
+
+							DB_Insert_Record(localDb, gun_index);
+							setChargerMode(gun_index, SYS_MODE_IDLE);
+						}
+					}
+					else
+					{
+						if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_C) &&
+						   (ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop != ON)  &&
+						   (ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq != ON) &&
+						   !ShmOCPP16Data->MsMsg.bits.ResetReq &&
+						   !(ShmOCPP16Data->OcppConnStatus && (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration > 0) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration >= (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration*60))) &&
+						   !(ShmOCPP16Data->OcppConnStatus && (ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy > 0) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy >= ((float)ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy))) &&
+						   !(!ShmOCPP16Data->OcppConnStatus && (ShmSysConfigAndInfo->SysConfig.OfflinePolicy != OFF_POLICY_NOCHARGE) && ((ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration > 0) ? (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration >= (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration*60)) : (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration > 0) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration >= (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration*60)))) &&
+						   !(!ShmOCPP16Data->OcppConnStatus && (ShmSysConfigAndInfo->SysConfig.OfflinePolicy != OFF_POLICY_NOCHARGE) && ((ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy > 0) ? (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy >= ((float)ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy)) : (ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy > 0) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy >= ((float)ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy)))))
+						{
+							setChargerMode(gun_index, SYS_MODE_CHARGING);
+						}
+					}
+					break;
+				case SYS_MODE_ALARM:
+					if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode == 0))
+					{
+						if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PreviousSystemStatus == SYS_MODE_CHARGING) ||
+						   (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PreviousSystemStatus == SYS_MODE_TERMINATING))
+						{
+							setChargerMode(gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PreviousSystemStatus);
+						}
+						else
+						{
+							setChargerMode(gun_index, SYS_MODE_IDLE);
+						}
+					}
+
+					setLedMotion(gun_index,LED_ACTION_ALARM);
+					break;
+				case SYS_MODE_FAULT:
+					if(isModeChange(gun_index))
+					{
+						/*
+						 * TODO:
+						 * 1. LED control depend on relay status
+						 * 2. Alarm latch & release logic
+						 */
+					}
+
+					break;
+				case SYS_MODE_MAINTAIN:
+					if(isModeChange(gun_index))
+					{
+						setLedMotion(gun_index,LED_ACTION_MAINTAIN);
+					}
+
+					break;
+				case SYS_MODE_UPDATE:
+					if(isModeChange(gun_index))
+					{
+						setLedMotion(gun_index,LED_ACTION_MAINTAIN);
+					}
+
+					//======================================
+					// Check local upgrade firmware request
+					//======================================
+					if(ShmSysConfigAndInfo->SysInfo.FirmwareUpdate)
+					{
+						DEBUG_INFO("Firmware local upgrading...\r\n");
+						ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = OFF;
+
+						if(upgrade_check())
+						{
+							ShmCharger->isUpdateSuccess = PASS;
+						}
+						else
+						{
+							ShmCharger->isUpdateSuccess = FAIL;
+						}
+					}
+					else if(ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq)
+					{
+						//======================================
+						// Check remote upgrade firmware request
+						//======================================
+						if(strcmp((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "DownloadFailed")==0)
+						{
+							DEBUG_INFO("Firmware remote upgraded fail...\r\n");
+							ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = OFF;
+							ShmCharger->isUpdateSuccess = FAIL;
+						}
+						else if(strcmp((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "Downloaded")==0)
+						{
+							DEBUG_INFO("Firmware remote upgrading...\r\n");
+							sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installing");
+							ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
+							ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = OFF;
+							if(upgrade_check())
+							{
+								ShmCharger->isUpdateSuccess = PASS;
+							}
+							else
+							{
+								ShmCharger->isUpdateSuccess = FAIL;
+							}
+						}
+						else
+						{}
+					}
+					else
+					{
+						//======================================
+						// Upgrade complete reboot system
+						//======================================
+						if(!ShmCharger->gun_info[gun_index].mcuFlag.isMcuUpgradeReq && ((AC_QUANTITY>1)?!ShmCharger->gun_info[gun_index^1].mcuFlag.isMcuUpgradeReq:YES))
+						{
+							if(ShmCharger->isUpdateSuccess == PASS)
+							{
+								sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installed");
+								ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
+								DEBUG_WARN("Firmware upgrade success.\r\n");
+
+								sleep(5);
+								DEBUG_INFO("Firmware upgraded, reboot...\r\n");
+								system("reboot -f");
+								sleep(5);
+								system("reboot -f");
+							}
+							else
+							{
+								sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "InstallationFailed");
+								ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
+								DEBUG_WARN("Firmware upgrade fail.\r\n");
+								system("/usr/bin/run_evse_restart.sh");
+							}
+						}
+					}
+
+					break;
+				case SYS_MODE_RESERVATION:
+					if(isModeChange(gun_index))
+					{
+						setLedMotion(gun_index,LED_ACTION_MAINTAIN);
+					}
+
+					if(isReservationExpired(gun_index))
+					{
+						DEBUG_INFO("Reservation: Time's up...\r\n");
+						setChargerMode(gun_index, SYS_MODE_IDLE);
+					}
+					else if(ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq)
+					{
+						DEBUG_INFO("Reservation: Cancel reservation...\r\n");
+						setChargerMode(gun_index, SYS_MODE_IDLE);
+
+						ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = OFF;
+						ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = ON;
+					}
+
+					break;
+				case SYS_MODE_BOOKING:
+					if(isModeChange(gun_index))
+					{
+						/*
+						 * TODO:
+						 * 1. LED control depend on relay status
+						 * 2. Check booking start is on time?
+						 */
+					}
+					break;
+				case SYS_MODE_DEBUG:
+					if(isModeChange(gun_index))
+					{
+						setLedMotion(gun_index,LED_ACTION_DEBUG);
+					}
+					break;
+			}
+		}
+
+		// System watch dog reset
+		write(wtdFd, "a", 1);
+
+		usleep(50000);
+	}
+
+	return FAIL;
+}

+ 415 - 0
EVSE/Projects/Noodoe/Apps/main.h

@@ -0,0 +1,415 @@
+/*
+ * Config.h
+ *
+ *  Created on: 2020年01月15日
+ *      Author: Eason Yang
+ */
+
+#ifndef CONFIG_MAIN_H_
+#define CONFIG_MAIN_H_
+
+#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	<dirent.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	<stddef.h>
+#include	<stdint.h>
+#include	<sqlite3.h>
+
+
+//===================================
+//	Define CP State constant
+//===================================
+#define CP_STATE_UNKNOWN			0
+#define CP_STATE_A					1
+#define CP_STATE_B					2
+#define CP_STATE_C					3
+#define CP_STATE_D					4
+#define CP_STATE_E					5
+#define CP_STATE_F					6
+
+//===================================
+// Define start mode constant
+//===================================
+#define START_METHOD_FREE	 		0
+#define START_METHOD_RFID	 		1
+#define START_METHOD_BACKEND 		2
+#define START_METHOD_BLE	 		3
+
+//===================================
+// Define Speaker type constant
+//===================================
+#define SPEAKER_STOP				0
+#define SPEAKER_ALWAYS_ON			1
+#define SPEAKER_SHORT				2
+#define SPEAKER_LONG				3
+#define SPEAKER_INTERVAL_SHORT		4
+#define SPEAKER_INTERVAL_LONG		5
+#define SPEAKER_INTERVAL_3COUNT		6
+
+//===================================
+// Define Alarm code constant
+//===================================
+#define ALARM_OVER_VOLTAGE          0x000001
+#define ALARM_UNDER_VOLTAGE         0x000002
+#define ALARM_OVER_CURRENT          0x000004
+#define ALARM_OVER_TEMPERATURE      0x000008
+#define ALARM_GROUND_FAIL           0x000010
+#define ALARM_CP_ERROR              0x000020
+#define ALARM_CURRENT_LEAK_AC       0x000040
+#define ALARM_CURRENT_LEAK_DC       0x000080
+#define ALARM_MCU_TESTFAIL          0x000100
+#define ALARM_HANDSHAKE_TIMEOUT     0x000200
+#define ALARM_EMERGENCY_STOP        0x000400
+#define ALARM_RELAY_WELDING         0x000800
+#define ALARM_LEAK_MODULE_FAIL      0x001000
+#define ALARM_SHUTTER_FAULT         0x002000
+#define ALARM_LOCKER_FAULT          0x004000
+#define ALARM_POWER_DROP            0x008000
+#define ALARM_CURRENT_SHORT         0x010000
+#define ALARM_ROTATORY_SWITCH_FAULT 0x020000
+#define ALARM_RELAY_DRIVE_FAULT     0x040000
+
+//===================================
+// Define Led constant
+//===================================
+#define LED_ACTION_INIT             	0
+#define LED_ACTION_IDLE             	1
+#define LED_ACTION_AUTHED           	2
+#define LED_ACTION_CONNECTED        	3
+#define LED_ACTION_CHARGING         	4
+#define LED_ACTION_STOP             	5
+#define LED_ACTION_ALARM            	6
+#define LED_ACTION_MAINTAIN         	7
+#define LED_ACTION_RFID_PASS        	8
+#define LED_ACTION_RFID_FAIL        	9
+#define LED_ACTION_BLE_CONNECT      	10
+#define LED_ACTION_BLE_DISABLE      	11
+#define LED_ACTION_DEBUG            	12
+#define LED_ACTION_ALL_OFF          	13
+#define LED_RELAY_ON               	 	14
+#define LED_RELAY_OFF               	15
+#define LED_ACTION_HANDSHAKE_FAIL   	16
+#define LED_ACTION_INTERNET_DISCONNECT	17
+
+
+#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)
+
+extern int StoreLogMsg(const char *fmt, ...);
+
+
+//============================================================
+// Private shared memory key define
+//============================================================
+#define ShmChargerKey		2001
+
+typedef struct Verion
+{
+	char Version_FW[32];
+	char Version_HW[32];
+}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[4];
+}FanSpeed;
+
+typedef struct TEMPERATURE
+{
+	unsigned char point[8];
+}Temperature;
+
+typedef struct AUXPOWER
+{
+	unsigned char voltage[8];
+}AuxPower;
+
+typedef struct RELAY
+{
+	unsigned char relay_status[2][8];
+}Relay;
+
+typedef struct GFD
+{
+	unsigned short int adc_value_positive[2];
+	unsigned short int adc_value_negative[2];
+}Gfd;
+
+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 Button[2];
+	unsigned char Button_Emergency;
+}Gpio_in;
+
+typedef struct GPIO_OUT
+{
+	unsigned char AC_Connector;
+	unsigned char Button_LED[2];
+	unsigned char System_LED[4];
+}Gpio_out;
+
+typedef struct ALARM_LOG
+{
+	unsigned char logArea;
+	unsigned int alarmIndex;
+	unsigned char log[8];
+}Alarm_Log;
+
+typedef struct BLE_CONFIG_DATA
+{
+	unsigned char isLogin:1;
+	unsigned char isRequestStart:1;
+	unsigned char isRequestStop:1;
+}Ble_Config_Data;
+
+typedef struct BLE_LONGIN_CENTRAL_ID
+{
+	unsigned char id[32];
+}Ble_Login_Central_Id;
+
+typedef struct RTC
+{
+	unsigned short int year;
+	unsigned char month;
+	unsigned char day;
+	unsigned char hour;
+	unsigned char min;
+	unsigned char sec;
+}Rtc;
+
+typedef struct PRESENTOUTPUTCURRENT
+{
+	double L1N_L12[2];
+	double L2N_L23[2];
+	double L3N_L31[2];
+}Presentoutputcurrent;
+
+typedef struct AC_PRIMARY_MCU
+{
+	unsigned char cp_state;
+	unsigned int  current_limit;
+	float cp_voltage_positive;
+	float cp_voltage_negtive;
+	unsigned char locker_state;
+	unsigned char relay_state;
+	unsigned char shutter_state;
+	unsigned char meter_state;
+	unsigned char pp_state;
+	unsigned char rating_current;
+	unsigned char rotatory_switch;
+}Ac_Primary_Mcu;
+
+typedef struct AC_PRIMARY_MCU_ALARM
+{
+	union
+	{
+		unsigned long InputAlarmCode;
+		struct
+		{
+			unsigned long OVP:1;
+			unsigned long UVP:1;
+			unsigned long OCP:1;
+			unsigned long OTP:1;
+			unsigned long gmi_fault:1;
+			unsigned long cp_fault:1;
+			unsigned long ac_leak:1;
+			unsigned long dc_leak:1;
+			unsigned long mcu_selftest_fail:1;
+			unsigned long handshaking_timeout:1;
+			unsigned long emergency_stop:1;
+			unsigned long relay_welding:1;
+			unsigned long leak_module_fail:1;
+			unsigned long shutter_fault:1;
+			unsigned long locker_fault:1;
+			unsigned long power_drop:1;
+			unsigned long circuit_short:1;
+			unsigned long set_circuit:1;
+			unsigned long relay_drive_fault:1;
+			unsigned long comm_timeout:1;
+		}bits;
+	};
+}Ac_Primary_Mcu_Alarm;
+
+typedef struct AC_PRIMARY_MCU_LED
+{
+	unsigned char mode;
+	unsigned long alarm_code;
+}Ac_Primary_Mcu_Led;
+
+typedef struct EVSE_ID
+{
+	unsigned char model_name[14];
+	unsigned char serial_number[12];
+}Evse_Id;
+
+typedef struct AC_PRIMARY_MCU_CP_PWM_DUTY
+{
+	unsigned int max_current;
+}Ac_Primary_Mcu_Cp_Pwm_Duty;
+
+typedef struct LEGACY_REQUEST
+{
+	unsigned char isLegacyRequest:1;
+}Legacy_Request;
+
+typedef struct POWER_CONSUMPTION
+{
+	uint32_t power_consumption;
+	uint32_t power_consumption_at_start;
+
+}Power_Consumption;
+
+typedef struct MCU_OP_FLAG
+{
+	unsigned char isSetModePass:1;
+	unsigned char isSetSerialNumberPass:1;
+	unsigned char isSetModelNamePass:1;
+	unsigned char isReadFwVerPass:1;
+	unsigned char isMcuUpgradeReq:1;
+	unsigned char isSetCpPwmDuty:1;
+}Mcu_Op_Flag;
+
+typedef struct SYSTEM_ALARM_CODE
+{
+	unsigned long SystemAlarmCode;
+
+}System_Alarm_Code;
+
+typedef struct OTHER_ALARM_CODE
+{
+	unsigned long isMcuSelfTest:1;
+	unsigned long isCurrentShort:1;
+	unsigned long isLeakageModule:1;
+	unsigned long isShutterFail:1;
+	unsigned long isLockerFault:1;
+	unsigned long isRotatorySwitch:1;
+	unsigned long isPowerDrop:1;
+	unsigned long isOverCurrent:1;
+	unsigned long isHandshakingTimeOut:1;
+	unsigned long HandShakingAlarmRequest:1;
+	unsigned long isDcLeakage:1;
+	unsigned long isACLeakage:1;
+}Other_Alarm_Code;
+
+typedef struct PILOT_VOLTAGE
+{
+	float PilotVoltagePositive;
+	float PilotVoltageNegative;
+
+}Pilot_Voltage;
+
+typedef struct FW_UPGRADE_INFO
+{
+	int fwType;
+	char modelName[17];
+	char location[384];
+}Fw_Upgrade_Info;
+
+typedef struct GUN_PLUGIN_TIMES
+{
+	uint32_t GunPluginTimes;
+
+}Gun_Plugin_Times;
+
+typedef struct MCU_RESET_REQUEST
+{
+	unsigned char isMcuResetRequest:1;
+}Mcu_Reset_Request;
+
+typedef struct TIMEOUT_SPEC
+{
+	int Setting_Timeout_Spec;
+	int Present_Timeout_Spec;
+}Timeout_Spec;
+
+typedef struct GUN_INFO
+{
+	Ver 											ver;
+	PresentInputVoltage 							inputVoltage;
+	Presentoutputcurrent							outputCurrent;
+	Temperature 									temperature;
+	Ble_Config_Data									bleConfigData;
+	Ble_Login_Central_Id							bleLoginCentralId;
+	Rtc												rtc;
+	Ac_Primary_Mcu									primaryMcuState;
+	Ac_Primary_Mcu_Alarm							primaryMcuAlarm;
+	Ac_Primary_Mcu_Led								primaryMcuLed;
+	Mcu_Op_Flag										mcuFlag;
+	Power_Consumption								powerConsumption;
+	Legacy_Request									legacyRequest;
+	System_Alarm_Code								systemAlarmCode;
+	Ac_Primary_Mcu_Cp_Pwm_Duty						primaryMcuCp_Pwn_Duty;
+	Other_Alarm_Code								otherAlarmCode;
+	Pilot_Voltage									PilotVoltage;
+	Gun_Plugin_Times								gunPluginTimes;
+	Mcu_Reset_Request								mcuResetRequest;
+	uint16_t										targetCurrent;
+	uint8_t											isAuthPassEnd:1;
+	uint8_t											rfidReq:1;
+	uint8_t											isGunPlugged:1;
+	uint8_t											isInitialPass:1;
+}Gun_Info;
+
+struct Charger
+{
+	Ver 					ver;
+	Evse_Id					evseId;
+	Gun_Info 				gun_info[2];
+	Fw_Upgrade_Info			fwUpgradeInfo;
+	Timeout_Spec			timeoutSpec;
+	
+	uint8_t					gun_selectd;
+	uint8_t	 				speaker_type;
+	uint8_t					isSpeakerOn:1;
+	uint8_t		 			isUpdateSuccess:1;
+};
+
+#endif /* CONFIG_MAIN_H_ */

BIN
EVSE/Projects/Noodoe/Images/MLO


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


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


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


BIN
EVSE/Projects/Noodoe/Images/zImage


+ 73 - 0
Makefile

@@ -1094,3 +1094,76 @@ cryptodev_install:
 	@cd board-support/extra-drivers; \
 	cd `find . -maxdepth 1 -name "cryptodev*"`; \
 	make ARCH=arm  KERNEL_DIR=$(LINUXKERNEL_INSTALL_DIR)  INSTALL_MOD_PATH=$(DESTDIR) PREFIX=$(SDK_PATH_TARGET)  install
+
+Noodoe-uboot-default: u-boot_clean u-boot
+	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/MLO EVSE/Projects/Noodoe/Images/
+	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/u-boot.img EVSE/Projects/Noodoe/Images/
+
+Noodoe-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
+
+Noodoe-uboot:
+	@echo ===================================
+	@echo    Building U-boot
+	@echo ===================================
+	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[Noodoe]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/Noodoe/Images/
+	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/u-boot.img EVSE/Projects/Noodoe/Images/
+	@cp -f board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/spl/u-boot-spl.bin EVSE/Projects/Noodoe/Images/
+
+Noodoe-linux-default: linux_clean linux
+	@cp -f board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/arch/arm/boot/zImage EVSE/Projects/Noodoe/Images/
+	@cp -f board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/arch/arm/boot/dts/am335x-evm.dtb EVSE/Projects/Noodoe/Images/
+
+Noodoe-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/[Noodoe]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/Noodoe/Images/
+	@cp -f board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/arch/arm/boot/dts/am335x-evm.dtb EVSE/Projects/Noodoe/Images/
+	@cp -f board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/drivers/net/ethernet/qualcomm/qcaspi.ko EVSE/rootfs/lib/
+
+Noodoe-rootfs:
+	@echo =================================
+	@echo     Building User rootfs
+	@echo =================================
+#	@cd EVSE/GPL;make Project=Noodoe all
+	@cd EVSE/Modularization;make Project=Noodoe all
+	@cd EVSE/Projects/Noodoe/Apps;make Project=Noodoe all
+	@rm -f EVSE/Projects/Noodoe/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/Noodoe/Images/ramdisk.gz
+	@mkdir -p EVSE/Projects/Noodoe/Images/mnt
+	@gunzip EVSE/Projects/Noodoe/Images/ramdisk.gz
+	@sync
+	@mount -o loop EVSE/Projects/Noodoe/Images/ramdisk EVSE/Projects/Noodoe/Images/mnt
+	@cp -rfv EVSE/rootfs/* EVSE/Projects/Noodoe/Images/mnt/
+	@chown www-data:www-data EVSE/Projects/Noodoe/Images/mnt/var/www -R
+	@chmod 777 EVSE/Projects/Noodoe/Images/mnt/var/log -R
+	@chmod 777 EVSE/Projects/Noodoe/Images/mnt/var/run -R
+	@cp -rfv EVSE/Projects/Noodoe/Images/root/* EVSE/Projects/Noodoe/Images/mnt/root
+	@sync
+	@sleep 3
+	@umount EVSE/Projects/Noodoe/Images/mnt
+	@sync
+	@gzip -v9 EVSE/Projects/Noodoe/Images/ramdisk
+	@rm -rfv EVSE/Projects/Noodoe/Images/root
+	@rm -rfv EVSE/Projects/Noodoe/Images/mnt
+
+Noodoe-all: Noodoe-uboot Noodoe-linux Noodoe-rootfs
+

File diff suppressed because it is too large
+ 32723 - 32723
board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/.tmp_System.map


File diff suppressed because it is too large
+ 1398 - 1412
board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/.tmp_kallsyms1.S


File diff suppressed because it is too large
+ 1398 - 1412
board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/.tmp_kallsyms2.S


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 @@
-402
+403

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

@@ -0,0 +1,667 @@
+/*
+ * 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 */ 
+			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 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*/
+			/** GPIO 3 */
+			0x1A8 (PIN_OUTPUT | MUX_MODE7)			/* MCASP0_AXR1	=>	GPIO3_20 */	/*control MCU to output CP PWM*/
+		>;
+	};
+	
+	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 */
+		>;
+	};
+#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*/
+		>;
+	};
+#endif	
+	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_PULLDOWN | MUX_MODE0)		/* MII1_COL.gmii1_col */
+			//0x10C(PIN_INPUT_PULLDOWN | 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 */
+			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 */      
+
+		>;
+	};
+
+	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)		
+			
+		>;
+	};
+
+
+	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 */
+		>;
+	};
+#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 */
+		>;
+	};
+
+	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";
+};
+#if 0
+&uart5 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&uart5_pins>;
+
+	status = "okay";
+};
+#endif
+&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>;
+	status = "okay";
+};
+
+&davinci_mdio {
+	pinctrl-names = "default", "sleep";
+	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";
+
+};
+#if 0
+&cpsw_emac1 {
+	phy_id = <&davinci_mdio>, <2>;
+ 	phy-mode = "mii";
+
+};
+#endif
+
+&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>;
+};
+#if 0
+&dcan1 {
+	status = "okay";	
+	pinctrl-names = "default";
+	pinctrl-0 = <&dcan1_pins_default>;
+};
+#endif

+ 31 - 13
board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/scripts/.conmakehash.cmd

@@ -5,18 +5,23 @@ source_scripts/conmakehash := scripts/conmakehash.c
 deps_scripts/conmakehash := \
   /usr/include/stdc-predef.h \
   /usr/include/stdio.h \
+  /usr/include/x86_64-linux-gnu/bits/libc-header-start.h \
   /usr/include/features.h \
   /usr/include/x86_64-linux-gnu/sys/cdefs.h \
   /usr/include/x86_64-linux-gnu/bits/wordsize.h \
+  /usr/include/x86_64-linux-gnu/bits/long-double.h \
   /usr/include/x86_64-linux-gnu/gnu/stubs.h \
   /usr/include/x86_64-linux-gnu/gnu/stubs-64.h \
-  /usr/lib/gcc/x86_64-linux-gnu/5/include/stddef.h \
+  /usr/lib/gcc/x86_64-linux-gnu/7/include/stddef.h \
   /usr/include/x86_64-linux-gnu/bits/types.h \
   /usr/include/x86_64-linux-gnu/bits/typesizes.h \
-  /usr/include/libio.h \
-  /usr/include/_G_config.h \
-  /usr/include/wchar.h \
-  /usr/lib/gcc/x86_64-linux-gnu/5/include/stdarg.h \
+  /usr/include/x86_64-linux-gnu/bits/types/__FILE.h \
+  /usr/include/x86_64-linux-gnu/bits/types/FILE.h \
+  /usr/include/x86_64-linux-gnu/bits/libio.h \
+  /usr/include/x86_64-linux-gnu/bits/_G_config.h \
+    $(wildcard include/config/h.h) \
+  /usr/include/x86_64-linux-gnu/bits/types/__mbstate_t.h \
+  /usr/lib/gcc/x86_64-linux-gnu/7/include/stdarg.h \
   /usr/include/x86_64-linux-gnu/bits/stdio_lim.h \
   /usr/include/x86_64-linux-gnu/bits/sys_errlist.h \
   /usr/include/x86_64-linux-gnu/bits/stdio.h \
@@ -24,29 +29,42 @@ deps_scripts/conmakehash := \
   /usr/include/stdlib.h \
   /usr/include/x86_64-linux-gnu/bits/waitflags.h \
   /usr/include/x86_64-linux-gnu/bits/waitstatus.h \
+  /usr/include/x86_64-linux-gnu/bits/floatn.h \
+  /usr/include/x86_64-linux-gnu/bits/floatn-common.h \
+  /usr/include/x86_64-linux-gnu/sys/types.h \
+  /usr/include/x86_64-linux-gnu/bits/types/clock_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/clockid_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/time_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/timer_t.h \
+  /usr/include/x86_64-linux-gnu/bits/stdint-intn.h \
   /usr/include/endian.h \
   /usr/include/x86_64-linux-gnu/bits/endian.h \
   /usr/include/x86_64-linux-gnu/bits/byteswap.h \
   /usr/include/x86_64-linux-gnu/bits/byteswap-16.h \
-  /usr/include/x86_64-linux-gnu/sys/types.h \
-  /usr/include/time.h \
+  /usr/include/x86_64-linux-gnu/bits/uintn-identity.h \
   /usr/include/x86_64-linux-gnu/sys/select.h \
   /usr/include/x86_64-linux-gnu/bits/select.h \
-  /usr/include/x86_64-linux-gnu/bits/sigset.h \
-  /usr/include/x86_64-linux-gnu/bits/time.h \
+  /usr/include/x86_64-linux-gnu/bits/types/sigset_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/__sigset_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/struct_timeval.h \
+  /usr/include/x86_64-linux-gnu/bits/types/struct_timespec.h \
   /usr/include/x86_64-linux-gnu/bits/select2.h \
   /usr/include/x86_64-linux-gnu/sys/sysmacros.h \
+  /usr/include/x86_64-linux-gnu/bits/sysmacros.h \
   /usr/include/x86_64-linux-gnu/bits/pthreadtypes.h \
+  /usr/include/x86_64-linux-gnu/bits/thread-shared-types.h \
+  /usr/include/x86_64-linux-gnu/bits/pthreadtypes-arch.h \
   /usr/include/alloca.h \
   /usr/include/x86_64-linux-gnu/bits/stdlib-bsearch.h \
   /usr/include/x86_64-linux-gnu/bits/stdlib-float.h \
   /usr/include/x86_64-linux-gnu/bits/stdlib.h \
   /usr/include/sysexits.h \
   /usr/include/string.h \
-  /usr/include/xlocale.h \
-  /usr/include/x86_64-linux-gnu/bits/string.h \
-  /usr/include/x86_64-linux-gnu/bits/string2.h \
-  /usr/include/x86_64-linux-gnu/bits/string3.h \
+  /usr/include/x86_64-linux-gnu/bits/types/locale_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/__locale_t.h \
+  /usr/include/strings.h \
+  /usr/include/x86_64-linux-gnu/bits/strings_fortified.h \
+  /usr/include/x86_64-linux-gnu/bits/string_fortified.h \
   /usr/include/ctype.h \
 
 scripts/conmakehash: $(deps_scripts/conmakehash)

+ 33 - 15
board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/scripts/.kallsyms.cmd

@@ -6,18 +6,23 @@ deps_scripts/kallsyms := \
     $(wildcard include/config/page/offset.h) \
   /usr/include/stdc-predef.h \
   /usr/include/stdio.h \
+  /usr/include/x86_64-linux-gnu/bits/libc-header-start.h \
   /usr/include/features.h \
   /usr/include/x86_64-linux-gnu/sys/cdefs.h \
   /usr/include/x86_64-linux-gnu/bits/wordsize.h \
+  /usr/include/x86_64-linux-gnu/bits/long-double.h \
   /usr/include/x86_64-linux-gnu/gnu/stubs.h \
   /usr/include/x86_64-linux-gnu/gnu/stubs-64.h \
-  /usr/lib/gcc/x86_64-linux-gnu/5/include/stddef.h \
+  /usr/lib/gcc/x86_64-linux-gnu/7/include/stddef.h \
   /usr/include/x86_64-linux-gnu/bits/types.h \
   /usr/include/x86_64-linux-gnu/bits/typesizes.h \
-  /usr/include/libio.h \
-  /usr/include/_G_config.h \
-  /usr/include/wchar.h \
-  /usr/lib/gcc/x86_64-linux-gnu/5/include/stdarg.h \
+  /usr/include/x86_64-linux-gnu/bits/types/__FILE.h \
+  /usr/include/x86_64-linux-gnu/bits/types/FILE.h \
+  /usr/include/x86_64-linux-gnu/bits/libio.h \
+  /usr/include/x86_64-linux-gnu/bits/_G_config.h \
+    $(wildcard include/config/h.h) \
+  /usr/include/x86_64-linux-gnu/bits/types/__mbstate_t.h \
+  /usr/lib/gcc/x86_64-linux-gnu/7/include/stdarg.h \
   /usr/include/x86_64-linux-gnu/bits/stdio_lim.h \
   /usr/include/x86_64-linux-gnu/bits/sys_errlist.h \
   /usr/include/x86_64-linux-gnu/bits/stdio.h \
@@ -25,31 +30,44 @@ deps_scripts/kallsyms := \
   /usr/include/stdlib.h \
   /usr/include/x86_64-linux-gnu/bits/waitflags.h \
   /usr/include/x86_64-linux-gnu/bits/waitstatus.h \
+  /usr/include/x86_64-linux-gnu/bits/floatn.h \
+  /usr/include/x86_64-linux-gnu/bits/floatn-common.h \
+  /usr/include/x86_64-linux-gnu/sys/types.h \
+  /usr/include/x86_64-linux-gnu/bits/types/clock_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/clockid_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/time_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/timer_t.h \
+  /usr/include/x86_64-linux-gnu/bits/stdint-intn.h \
   /usr/include/endian.h \
   /usr/include/x86_64-linux-gnu/bits/endian.h \
   /usr/include/x86_64-linux-gnu/bits/byteswap.h \
   /usr/include/x86_64-linux-gnu/bits/byteswap-16.h \
-  /usr/include/x86_64-linux-gnu/sys/types.h \
-  /usr/include/time.h \
+  /usr/include/x86_64-linux-gnu/bits/uintn-identity.h \
   /usr/include/x86_64-linux-gnu/sys/select.h \
   /usr/include/x86_64-linux-gnu/bits/select.h \
-  /usr/include/x86_64-linux-gnu/bits/sigset.h \
-  /usr/include/x86_64-linux-gnu/bits/time.h \
+  /usr/include/x86_64-linux-gnu/bits/types/sigset_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/__sigset_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/struct_timeval.h \
+  /usr/include/x86_64-linux-gnu/bits/types/struct_timespec.h \
   /usr/include/x86_64-linux-gnu/bits/select2.h \
   /usr/include/x86_64-linux-gnu/sys/sysmacros.h \
+  /usr/include/x86_64-linux-gnu/bits/sysmacros.h \
   /usr/include/x86_64-linux-gnu/bits/pthreadtypes.h \
+  /usr/include/x86_64-linux-gnu/bits/thread-shared-types.h \
+  /usr/include/x86_64-linux-gnu/bits/pthreadtypes-arch.h \
   /usr/include/alloca.h \
   /usr/include/x86_64-linux-gnu/bits/stdlib-bsearch.h \
   /usr/include/x86_64-linux-gnu/bits/stdlib-float.h \
   /usr/include/x86_64-linux-gnu/bits/stdlib.h \
   /usr/include/string.h \
-  /usr/include/xlocale.h \
-  /usr/include/x86_64-linux-gnu/bits/string.h \
-  /usr/include/x86_64-linux-gnu/bits/string2.h \
-  /usr/include/x86_64-linux-gnu/bits/string3.h \
+  /usr/include/x86_64-linux-gnu/bits/types/locale_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/__locale_t.h \
+  /usr/include/strings.h \
+  /usr/include/x86_64-linux-gnu/bits/strings_fortified.h \
+  /usr/include/x86_64-linux-gnu/bits/string_fortified.h \
   /usr/include/ctype.h \
-  /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/limits.h \
-  /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/syslimits.h \
+  /usr/lib/gcc/x86_64-linux-gnu/7/include-fixed/limits.h \
+  /usr/lib/gcc/x86_64-linux-gnu/7/include-fixed/syslimits.h \
   /usr/include/limits.h \
   /usr/include/x86_64-linux-gnu/bits/posix1_lim.h \
   /usr/include/x86_64-linux-gnu/bits/local_lim.h \

+ 36 - 13
board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/scripts/.sortextable.cmd

@@ -8,33 +8,49 @@ deps_scripts/sortextable := \
   /usr/include/features.h \
   /usr/include/x86_64-linux-gnu/sys/cdefs.h \
   /usr/include/x86_64-linux-gnu/bits/wordsize.h \
+  /usr/include/x86_64-linux-gnu/bits/long-double.h \
   /usr/include/x86_64-linux-gnu/gnu/stubs.h \
   /usr/include/x86_64-linux-gnu/gnu/stubs-64.h \
   /usr/include/x86_64-linux-gnu/bits/types.h \
   /usr/include/x86_64-linux-gnu/bits/typesizes.h \
-  /usr/include/time.h \
-  /usr/lib/gcc/x86_64-linux-gnu/5/include/stddef.h \
+  /usr/include/x86_64-linux-gnu/bits/types/clock_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/clockid_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/time_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/timer_t.h \
+  /usr/lib/gcc/x86_64-linux-gnu/7/include/stddef.h \
+  /usr/include/x86_64-linux-gnu/bits/stdint-intn.h \
   /usr/include/endian.h \
   /usr/include/x86_64-linux-gnu/bits/endian.h \
   /usr/include/x86_64-linux-gnu/bits/byteswap.h \
   /usr/include/x86_64-linux-gnu/bits/byteswap-16.h \
+  /usr/include/x86_64-linux-gnu/bits/uintn-identity.h \
   /usr/include/x86_64-linux-gnu/sys/select.h \
   /usr/include/x86_64-linux-gnu/bits/select.h \
-  /usr/include/x86_64-linux-gnu/bits/sigset.h \
-  /usr/include/x86_64-linux-gnu/bits/time.h \
+  /usr/include/x86_64-linux-gnu/bits/types/sigset_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/__sigset_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/struct_timeval.h \
+  /usr/include/x86_64-linux-gnu/bits/types/struct_timespec.h \
   /usr/include/x86_64-linux-gnu/bits/select2.h \
   /usr/include/x86_64-linux-gnu/sys/sysmacros.h \
+  /usr/include/x86_64-linux-gnu/bits/sysmacros.h \
   /usr/include/x86_64-linux-gnu/bits/pthreadtypes.h \
+  /usr/include/x86_64-linux-gnu/bits/thread-shared-types.h \
+  /usr/include/x86_64-linux-gnu/bits/pthreadtypes-arch.h \
   /usr/include/x86_64-linux-gnu/sys/mman.h \
   /usr/include/x86_64-linux-gnu/bits/mman.h \
   /usr/include/x86_64-linux-gnu/bits/mman-linux.h \
+  /usr/include/x86_64-linux-gnu/bits/mman-shared.h \
   /usr/include/x86_64-linux-gnu/sys/stat.h \
   /usr/include/x86_64-linux-gnu/bits/stat.h \
   /usr/include/getopt.h \
+  /usr/include/x86_64-linux-gnu/bits/getopt_core.h \
+  /usr/include/x86_64-linux-gnu/bits/getopt_ext.h \
   /usr/include/elf.h \
-  /usr/lib/gcc/x86_64-linux-gnu/5/include/stdint.h \
+  /usr/lib/gcc/x86_64-linux-gnu/7/include/stdint.h \
   /usr/include/stdint.h \
+  /usr/include/x86_64-linux-gnu/bits/libc-header-start.h \
   /usr/include/x86_64-linux-gnu/bits/wchar.h \
+  /usr/include/x86_64-linux-gnu/bits/stdint-uintn.h \
   /usr/include/x86_64-linux-gnu/bits/auxv.h \
   /usr/include/fcntl.h \
   /usr/include/x86_64-linux-gnu/bits/fcntl.h \
@@ -44,10 +60,13 @@ deps_scripts/sortextable := \
   /usr/include/x86_64-linux-gnu/bits/setjmp.h \
   /usr/include/x86_64-linux-gnu/bits/setjmp2.h \
   /usr/include/stdio.h \
-  /usr/include/libio.h \
-  /usr/include/_G_config.h \
-  /usr/include/wchar.h \
-  /usr/lib/gcc/x86_64-linux-gnu/5/include/stdarg.h \
+  /usr/include/x86_64-linux-gnu/bits/types/__FILE.h \
+  /usr/include/x86_64-linux-gnu/bits/types/FILE.h \
+  /usr/include/x86_64-linux-gnu/bits/libio.h \
+  /usr/include/x86_64-linux-gnu/bits/_G_config.h \
+    $(wildcard include/config/h.h) \
+  /usr/include/x86_64-linux-gnu/bits/types/__mbstate_t.h \
+  /usr/lib/gcc/x86_64-linux-gnu/7/include/stdarg.h \
   /usr/include/x86_64-linux-gnu/bits/stdio_lim.h \
   /usr/include/x86_64-linux-gnu/bits/sys_errlist.h \
   /usr/include/x86_64-linux-gnu/bits/stdio.h \
@@ -55,19 +74,23 @@ deps_scripts/sortextable := \
   /usr/include/stdlib.h \
   /usr/include/x86_64-linux-gnu/bits/waitflags.h \
   /usr/include/x86_64-linux-gnu/bits/waitstatus.h \
+  /usr/include/x86_64-linux-gnu/bits/floatn.h \
+  /usr/include/x86_64-linux-gnu/bits/floatn-common.h \
   /usr/include/alloca.h \
   /usr/include/x86_64-linux-gnu/bits/stdlib-bsearch.h \
   /usr/include/x86_64-linux-gnu/bits/stdlib-float.h \
   /usr/include/x86_64-linux-gnu/bits/stdlib.h \
   /usr/include/string.h \
-  /usr/include/xlocale.h \
-  /usr/include/x86_64-linux-gnu/bits/string.h \
-  /usr/include/x86_64-linux-gnu/bits/string2.h \
-  /usr/include/x86_64-linux-gnu/bits/string3.h \
+  /usr/include/x86_64-linux-gnu/bits/types/locale_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/__locale_t.h \
+  /usr/include/strings.h \
+  /usr/include/x86_64-linux-gnu/bits/strings_fortified.h \
+  /usr/include/x86_64-linux-gnu/bits/string_fortified.h \
   /usr/include/unistd.h \
   /usr/include/x86_64-linux-gnu/bits/posix_opt.h \
   /usr/include/x86_64-linux-gnu/bits/environments.h \
   /usr/include/x86_64-linux-gnu/bits/confname.h \
+  /usr/include/x86_64-linux-gnu/bits/getopt_posix.h \
   /usr/include/x86_64-linux-gnu/bits/unistd.h \
   tools/include/tools/be_byteshift.h \
   tools/include/tools/le_byteshift.h \

+ 10 - 5
board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/scripts/basic/.bin2c.cmd

@@ -5,18 +5,23 @@ source_scripts/basic/bin2c := scripts/basic/bin2c.c
 deps_scripts/basic/bin2c := \
   /usr/include/stdc-predef.h \
   /usr/include/stdio.h \
+  /usr/include/x86_64-linux-gnu/bits/libc-header-start.h \
   /usr/include/features.h \
   /usr/include/x86_64-linux-gnu/sys/cdefs.h \
   /usr/include/x86_64-linux-gnu/bits/wordsize.h \
+  /usr/include/x86_64-linux-gnu/bits/long-double.h \
   /usr/include/x86_64-linux-gnu/gnu/stubs.h \
   /usr/include/x86_64-linux-gnu/gnu/stubs-64.h \
-  /usr/lib/gcc/x86_64-linux-gnu/5/include/stddef.h \
+  /usr/lib/gcc/x86_64-linux-gnu/7/include/stddef.h \
   /usr/include/x86_64-linux-gnu/bits/types.h \
   /usr/include/x86_64-linux-gnu/bits/typesizes.h \
-  /usr/include/libio.h \
-  /usr/include/_G_config.h \
-  /usr/include/wchar.h \
-  /usr/lib/gcc/x86_64-linux-gnu/5/include/stdarg.h \
+  /usr/include/x86_64-linux-gnu/bits/types/__FILE.h \
+  /usr/include/x86_64-linux-gnu/bits/types/FILE.h \
+  /usr/include/x86_64-linux-gnu/bits/libio.h \
+  /usr/include/x86_64-linux-gnu/bits/_G_config.h \
+    $(wildcard include/config/h.h) \
+  /usr/include/x86_64-linux-gnu/bits/types/__mbstate_t.h \
+  /usr/lib/gcc/x86_64-linux-gnu/7/include/stdarg.h \
   /usr/include/x86_64-linux-gnu/bits/stdio_lim.h \
   /usr/include/x86_64-linux-gnu/bits/sys_errlist.h \
   /usr/include/x86_64-linux-gnu/bits/stdio.h \

+ 38 - 20
board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/scripts/basic/.fixdep.cmd

@@ -12,61 +12,81 @@ deps_scripts/basic/fixdep := \
   /usr/include/features.h \
   /usr/include/x86_64-linux-gnu/sys/cdefs.h \
   /usr/include/x86_64-linux-gnu/bits/wordsize.h \
+  /usr/include/x86_64-linux-gnu/bits/long-double.h \
   /usr/include/x86_64-linux-gnu/gnu/stubs.h \
   /usr/include/x86_64-linux-gnu/gnu/stubs-64.h \
   /usr/include/x86_64-linux-gnu/bits/types.h \
   /usr/include/x86_64-linux-gnu/bits/typesizes.h \
-  /usr/include/time.h \
-  /usr/lib/gcc/x86_64-linux-gnu/5/include/stddef.h \
+  /usr/include/x86_64-linux-gnu/bits/types/clock_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/clockid_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/time_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/timer_t.h \
+  /usr/lib/gcc/x86_64-linux-gnu/7/include/stddef.h \
+  /usr/include/x86_64-linux-gnu/bits/stdint-intn.h \
   /usr/include/endian.h \
   /usr/include/x86_64-linux-gnu/bits/endian.h \
   /usr/include/x86_64-linux-gnu/bits/byteswap.h \
   /usr/include/x86_64-linux-gnu/bits/byteswap-16.h \
+  /usr/include/x86_64-linux-gnu/bits/uintn-identity.h \
   /usr/include/x86_64-linux-gnu/sys/select.h \
   /usr/include/x86_64-linux-gnu/bits/select.h \
-  /usr/include/x86_64-linux-gnu/bits/sigset.h \
-  /usr/include/x86_64-linux-gnu/bits/time.h \
+  /usr/include/x86_64-linux-gnu/bits/types/sigset_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/__sigset_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/struct_timeval.h \
+  /usr/include/x86_64-linux-gnu/bits/types/struct_timespec.h \
   /usr/include/x86_64-linux-gnu/bits/select2.h \
   /usr/include/x86_64-linux-gnu/sys/sysmacros.h \
+  /usr/include/x86_64-linux-gnu/bits/sysmacros.h \
   /usr/include/x86_64-linux-gnu/bits/pthreadtypes.h \
+  /usr/include/x86_64-linux-gnu/bits/thread-shared-types.h \
+  /usr/include/x86_64-linux-gnu/bits/pthreadtypes-arch.h \
   /usr/include/x86_64-linux-gnu/sys/stat.h \
   /usr/include/x86_64-linux-gnu/bits/stat.h \
   /usr/include/x86_64-linux-gnu/sys/mman.h \
   /usr/include/x86_64-linux-gnu/bits/mman.h \
   /usr/include/x86_64-linux-gnu/bits/mman-linux.h \
+  /usr/include/x86_64-linux-gnu/bits/mman-shared.h \
   /usr/include/unistd.h \
   /usr/include/x86_64-linux-gnu/bits/posix_opt.h \
   /usr/include/x86_64-linux-gnu/bits/environments.h \
   /usr/include/x86_64-linux-gnu/bits/confname.h \
-  /usr/include/getopt.h \
+  /usr/include/x86_64-linux-gnu/bits/getopt_posix.h \
+  /usr/include/x86_64-linux-gnu/bits/getopt_core.h \
   /usr/include/x86_64-linux-gnu/bits/unistd.h \
   /usr/include/fcntl.h \
   /usr/include/x86_64-linux-gnu/bits/fcntl.h \
   /usr/include/x86_64-linux-gnu/bits/fcntl-linux.h \
   /usr/include/x86_64-linux-gnu/bits/fcntl2.h \
   /usr/include/string.h \
-  /usr/include/xlocale.h \
-  /usr/include/x86_64-linux-gnu/bits/string.h \
-  /usr/include/x86_64-linux-gnu/bits/string2.h \
+  /usr/include/x86_64-linux-gnu/bits/libc-header-start.h \
+  /usr/include/x86_64-linux-gnu/bits/types/locale_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/__locale_t.h \
+  /usr/include/strings.h \
+  /usr/include/x86_64-linux-gnu/bits/strings_fortified.h \
+  /usr/include/x86_64-linux-gnu/bits/string_fortified.h \
   /usr/include/stdlib.h \
-  /usr/include/x86_64-linux-gnu/bits/string3.h \
   /usr/include/x86_64-linux-gnu/bits/waitflags.h \
   /usr/include/x86_64-linux-gnu/bits/waitstatus.h \
+  /usr/include/x86_64-linux-gnu/bits/floatn.h \
+  /usr/include/x86_64-linux-gnu/bits/floatn-common.h \
   /usr/include/alloca.h \
   /usr/include/x86_64-linux-gnu/bits/stdlib-bsearch.h \
   /usr/include/x86_64-linux-gnu/bits/stdlib-float.h \
   /usr/include/x86_64-linux-gnu/bits/stdlib.h \
   /usr/include/stdio.h \
-  /usr/include/libio.h \
-  /usr/include/_G_config.h \
-  /usr/include/wchar.h \
-  /usr/lib/gcc/x86_64-linux-gnu/5/include/stdarg.h \
+  /usr/include/x86_64-linux-gnu/bits/types/__FILE.h \
+  /usr/include/x86_64-linux-gnu/bits/types/FILE.h \
+  /usr/include/x86_64-linux-gnu/bits/libio.h \
+  /usr/include/x86_64-linux-gnu/bits/_G_config.h \
+    $(wildcard include/config/h.h) \
+  /usr/include/x86_64-linux-gnu/bits/types/__mbstate_t.h \
+  /usr/lib/gcc/x86_64-linux-gnu/7/include/stdarg.h \
   /usr/include/x86_64-linux-gnu/bits/stdio_lim.h \
   /usr/include/x86_64-linux-gnu/bits/sys_errlist.h \
   /usr/include/x86_64-linux-gnu/bits/stdio.h \
   /usr/include/x86_64-linux-gnu/bits/stdio2.h \
-  /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/limits.h \
-  /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/syslimits.h \
+  /usr/lib/gcc/x86_64-linux-gnu/7/include-fixed/limits.h \
+  /usr/lib/gcc/x86_64-linux-gnu/7/include-fixed/syslimits.h \
   /usr/include/limits.h \
   /usr/include/x86_64-linux-gnu/bits/posix1_lim.h \
   /usr/include/x86_64-linux-gnu/bits/local_lim.h \
@@ -75,12 +95,9 @@ deps_scripts/basic/fixdep := \
   /usr/include/ctype.h \
   /usr/include/arpa/inet.h \
   /usr/include/netinet/in.h \
-  /usr/lib/gcc/x86_64-linux-gnu/5/include/stdint.h \
-  /usr/include/stdint.h \
-  /usr/include/x86_64-linux-gnu/bits/wchar.h \
+  /usr/include/x86_64-linux-gnu/bits/stdint-uintn.h \
   /usr/include/x86_64-linux-gnu/sys/socket.h \
-  /usr/include/x86_64-linux-gnu/sys/uio.h \
-  /usr/include/x86_64-linux-gnu/bits/uio.h \
+  /usr/include/x86_64-linux-gnu/bits/types/struct_iovec.h \
   /usr/include/x86_64-linux-gnu/bits/socket.h \
   /usr/include/x86_64-linux-gnu/bits/socket_type.h \
   /usr/include/x86_64-linux-gnu/bits/sockaddr.h \
@@ -88,6 +105,7 @@ deps_scripts/basic/fixdep := \
   /usr/include/asm-generic/socket.h \
   /usr/include/x86_64-linux-gnu/asm/sockios.h \
   /usr/include/asm-generic/sockios.h \
+  /usr/include/x86_64-linux-gnu/bits/types/struct_osockaddr.h \
   /usr/include/x86_64-linux-gnu/bits/socket2.h \
   /usr/include/x86_64-linux-gnu/bits/in.h \
 

+ 33 - 14
board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/scripts/mod/.mk_elfconfig.cmd

@@ -5,18 +5,23 @@ source_scripts/mod/mk_elfconfig := scripts/mod/mk_elfconfig.c
 deps_scripts/mod/mk_elfconfig := \
   /usr/include/stdc-predef.h \
   /usr/include/stdio.h \
+  /usr/include/x86_64-linux-gnu/bits/libc-header-start.h \
   /usr/include/features.h \
   /usr/include/x86_64-linux-gnu/sys/cdefs.h \
   /usr/include/x86_64-linux-gnu/bits/wordsize.h \
+  /usr/include/x86_64-linux-gnu/bits/long-double.h \
   /usr/include/x86_64-linux-gnu/gnu/stubs.h \
   /usr/include/x86_64-linux-gnu/gnu/stubs-64.h \
-  /usr/lib/gcc/x86_64-linux-gnu/5/include/stddef.h \
+  /usr/lib/gcc/x86_64-linux-gnu/7/include/stddef.h \
   /usr/include/x86_64-linux-gnu/bits/types.h \
   /usr/include/x86_64-linux-gnu/bits/typesizes.h \
-  /usr/include/libio.h \
-  /usr/include/_G_config.h \
-  /usr/include/wchar.h \
-  /usr/lib/gcc/x86_64-linux-gnu/5/include/stdarg.h \
+  /usr/include/x86_64-linux-gnu/bits/types/__FILE.h \
+  /usr/include/x86_64-linux-gnu/bits/types/FILE.h \
+  /usr/include/x86_64-linux-gnu/bits/libio.h \
+  /usr/include/x86_64-linux-gnu/bits/_G_config.h \
+    $(wildcard include/config/h.h) \
+  /usr/include/x86_64-linux-gnu/bits/types/__mbstate_t.h \
+  /usr/lib/gcc/x86_64-linux-gnu/7/include/stdarg.h \
   /usr/include/x86_64-linux-gnu/bits/stdio_lim.h \
   /usr/include/x86_64-linux-gnu/bits/sys_errlist.h \
   /usr/include/x86_64-linux-gnu/bits/stdio.h \
@@ -24,32 +29,46 @@ deps_scripts/mod/mk_elfconfig := \
   /usr/include/stdlib.h \
   /usr/include/x86_64-linux-gnu/bits/waitflags.h \
   /usr/include/x86_64-linux-gnu/bits/waitstatus.h \
+  /usr/include/x86_64-linux-gnu/bits/floatn.h \
+  /usr/include/x86_64-linux-gnu/bits/floatn-common.h \
+  /usr/include/x86_64-linux-gnu/sys/types.h \
+  /usr/include/x86_64-linux-gnu/bits/types/clock_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/clockid_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/time_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/timer_t.h \
+  /usr/include/x86_64-linux-gnu/bits/stdint-intn.h \
   /usr/include/endian.h \
   /usr/include/x86_64-linux-gnu/bits/endian.h \
   /usr/include/x86_64-linux-gnu/bits/byteswap.h \
   /usr/include/x86_64-linux-gnu/bits/byteswap-16.h \
-  /usr/include/x86_64-linux-gnu/sys/types.h \
-  /usr/include/time.h \
+  /usr/include/x86_64-linux-gnu/bits/uintn-identity.h \
   /usr/include/x86_64-linux-gnu/sys/select.h \
   /usr/include/x86_64-linux-gnu/bits/select.h \
-  /usr/include/x86_64-linux-gnu/bits/sigset.h \
-  /usr/include/x86_64-linux-gnu/bits/time.h \
+  /usr/include/x86_64-linux-gnu/bits/types/sigset_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/__sigset_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/struct_timeval.h \
+  /usr/include/x86_64-linux-gnu/bits/types/struct_timespec.h \
   /usr/include/x86_64-linux-gnu/bits/select2.h \
   /usr/include/x86_64-linux-gnu/sys/sysmacros.h \
+  /usr/include/x86_64-linux-gnu/bits/sysmacros.h \
   /usr/include/x86_64-linux-gnu/bits/pthreadtypes.h \
+  /usr/include/x86_64-linux-gnu/bits/thread-shared-types.h \
+  /usr/include/x86_64-linux-gnu/bits/pthreadtypes-arch.h \
   /usr/include/alloca.h \
   /usr/include/x86_64-linux-gnu/bits/stdlib-bsearch.h \
   /usr/include/x86_64-linux-gnu/bits/stdlib-float.h \
   /usr/include/x86_64-linux-gnu/bits/stdlib.h \
   /usr/include/string.h \
-  /usr/include/xlocale.h \
-  /usr/include/x86_64-linux-gnu/bits/string.h \
-  /usr/include/x86_64-linux-gnu/bits/string2.h \
-  /usr/include/x86_64-linux-gnu/bits/string3.h \
+  /usr/include/x86_64-linux-gnu/bits/types/locale_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/__locale_t.h \
+  /usr/include/strings.h \
+  /usr/include/x86_64-linux-gnu/bits/strings_fortified.h \
+  /usr/include/x86_64-linux-gnu/bits/string_fortified.h \
   /usr/include/elf.h \
-  /usr/lib/gcc/x86_64-linux-gnu/5/include/stdint.h \
+  /usr/lib/gcc/x86_64-linux-gnu/7/include/stdint.h \
   /usr/include/stdint.h \
   /usr/include/x86_64-linux-gnu/bits/wchar.h \
+  /usr/include/x86_64-linux-gnu/bits/stdint-uintn.h \
   /usr/include/x86_64-linux-gnu/bits/auxv.h \
 
 scripts/mod/mk_elfconfig: $(deps_scripts/mod/mk_elfconfig)

+ 39 - 16
board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/usr/.gen_init_cpio.cmd

@@ -5,18 +5,23 @@ source_usr/gen_init_cpio := usr/gen_init_cpio.c
 deps_usr/gen_init_cpio := \
   /usr/include/stdc-predef.h \
   /usr/include/stdio.h \
+  /usr/include/x86_64-linux-gnu/bits/libc-header-start.h \
   /usr/include/features.h \
   /usr/include/x86_64-linux-gnu/sys/cdefs.h \
   /usr/include/x86_64-linux-gnu/bits/wordsize.h \
+  /usr/include/x86_64-linux-gnu/bits/long-double.h \
   /usr/include/x86_64-linux-gnu/gnu/stubs.h \
   /usr/include/x86_64-linux-gnu/gnu/stubs-64.h \
-  /usr/lib/gcc/x86_64-linux-gnu/5/include/stddef.h \
+  /usr/lib/gcc/x86_64-linux-gnu/7/include/stddef.h \
   /usr/include/x86_64-linux-gnu/bits/types.h \
   /usr/include/x86_64-linux-gnu/bits/typesizes.h \
-  /usr/include/libio.h \
-  /usr/include/_G_config.h \
-  /usr/include/wchar.h \
-  /usr/lib/gcc/x86_64-linux-gnu/5/include/stdarg.h \
+  /usr/include/x86_64-linux-gnu/bits/types/__FILE.h \
+  /usr/include/x86_64-linux-gnu/bits/types/FILE.h \
+  /usr/include/x86_64-linux-gnu/bits/libio.h \
+  /usr/include/x86_64-linux-gnu/bits/_G_config.h \
+    $(wildcard include/config/h.h) \
+  /usr/include/x86_64-linux-gnu/bits/types/__mbstate_t.h \
+  /usr/lib/gcc/x86_64-linux-gnu/7/include/stdarg.h \
   /usr/include/x86_64-linux-gnu/bits/stdio_lim.h \
   /usr/include/x86_64-linux-gnu/bits/sys_errlist.h \
   /usr/include/x86_64-linux-gnu/bits/stdio.h \
@@ -24,19 +29,31 @@ deps_usr/gen_init_cpio := \
   /usr/include/stdlib.h \
   /usr/include/x86_64-linux-gnu/bits/waitflags.h \
   /usr/include/x86_64-linux-gnu/bits/waitstatus.h \
+  /usr/include/x86_64-linux-gnu/bits/floatn.h \
+  /usr/include/x86_64-linux-gnu/bits/floatn-common.h \
+  /usr/include/x86_64-linux-gnu/sys/types.h \
+  /usr/include/x86_64-linux-gnu/bits/types/clock_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/clockid_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/time_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/timer_t.h \
+  /usr/include/x86_64-linux-gnu/bits/stdint-intn.h \
   /usr/include/endian.h \
   /usr/include/x86_64-linux-gnu/bits/endian.h \
   /usr/include/x86_64-linux-gnu/bits/byteswap.h \
   /usr/include/x86_64-linux-gnu/bits/byteswap-16.h \
-  /usr/include/x86_64-linux-gnu/sys/types.h \
-  /usr/include/time.h \
+  /usr/include/x86_64-linux-gnu/bits/uintn-identity.h \
   /usr/include/x86_64-linux-gnu/sys/select.h \
   /usr/include/x86_64-linux-gnu/bits/select.h \
-  /usr/include/x86_64-linux-gnu/bits/sigset.h \
-  /usr/include/x86_64-linux-gnu/bits/time.h \
+  /usr/include/x86_64-linux-gnu/bits/types/sigset_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/__sigset_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/struct_timeval.h \
+  /usr/include/x86_64-linux-gnu/bits/types/struct_timespec.h \
   /usr/include/x86_64-linux-gnu/bits/select2.h \
   /usr/include/x86_64-linux-gnu/sys/sysmacros.h \
+  /usr/include/x86_64-linux-gnu/bits/sysmacros.h \
   /usr/include/x86_64-linux-gnu/bits/pthreadtypes.h \
+  /usr/include/x86_64-linux-gnu/bits/thread-shared-types.h \
+  /usr/include/x86_64-linux-gnu/bits/pthreadtypes-arch.h \
   /usr/include/alloca.h \
   /usr/include/x86_64-linux-gnu/bits/stdlib-bsearch.h \
   /usr/include/x86_64-linux-gnu/bits/stdlib-float.h \
@@ -44,16 +61,22 @@ deps_usr/gen_init_cpio := \
   /usr/include/x86_64-linux-gnu/sys/stat.h \
   /usr/include/x86_64-linux-gnu/bits/stat.h \
   /usr/include/string.h \
-  /usr/include/xlocale.h \
-  /usr/include/x86_64-linux-gnu/bits/string.h \
-  /usr/include/x86_64-linux-gnu/bits/string2.h \
-  /usr/include/x86_64-linux-gnu/bits/string3.h \
+  /usr/include/x86_64-linux-gnu/bits/types/locale_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/__locale_t.h \
+  /usr/include/strings.h \
+  /usr/include/x86_64-linux-gnu/bits/strings_fortified.h \
+  /usr/include/x86_64-linux-gnu/bits/string_fortified.h \
   /usr/include/unistd.h \
   /usr/include/x86_64-linux-gnu/bits/posix_opt.h \
   /usr/include/x86_64-linux-gnu/bits/environments.h \
   /usr/include/x86_64-linux-gnu/bits/confname.h \
-  /usr/include/getopt.h \
+  /usr/include/x86_64-linux-gnu/bits/getopt_posix.h \
+  /usr/include/x86_64-linux-gnu/bits/getopt_core.h \
   /usr/include/x86_64-linux-gnu/bits/unistd.h \
+  /usr/include/time.h \
+  /usr/include/x86_64-linux-gnu/bits/time.h \
+  /usr/include/x86_64-linux-gnu/bits/types/struct_tm.h \
+  /usr/include/x86_64-linux-gnu/bits/types/struct_itimerspec.h \
   /usr/include/fcntl.h \
   /usr/include/x86_64-linux-gnu/bits/fcntl.h \
   /usr/include/x86_64-linux-gnu/bits/fcntl-linux.h \
@@ -65,8 +88,8 @@ deps_usr/gen_init_cpio := \
   /usr/include/asm-generic/errno.h \
   /usr/include/asm-generic/errno-base.h \
   /usr/include/ctype.h \
-  /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/limits.h \
-  /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/syslimits.h \
+  /usr/lib/gcc/x86_64-linux-gnu/7/include-fixed/limits.h \
+  /usr/lib/gcc/x86_64-linux-gnu/7/include-fixed/syslimits.h \
   /usr/include/limits.h \
   /usr/include/x86_64-linux-gnu/bits/posix1_lim.h \
   /usr/include/x86_64-linux-gnu/bits/local_lim.h \

+ 802 - 0
board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[Noodoe]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>;
+};

+ 38 - 20
board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/scripts/basic/.fixdep.cmd

@@ -14,61 +14,81 @@ deps_scripts/basic/fixdep := \
   /usr/include/features.h \
   /usr/include/x86_64-linux-gnu/sys/cdefs.h \
   /usr/include/x86_64-linux-gnu/bits/wordsize.h \
+  /usr/include/x86_64-linux-gnu/bits/long-double.h \
   /usr/include/x86_64-linux-gnu/gnu/stubs.h \
   /usr/include/x86_64-linux-gnu/gnu/stubs-64.h \
   /usr/include/x86_64-linux-gnu/bits/types.h \
   /usr/include/x86_64-linux-gnu/bits/typesizes.h \
-  /usr/include/time.h \
-  /usr/lib/gcc/x86_64-linux-gnu/5/include/stddef.h \
+  /usr/include/x86_64-linux-gnu/bits/types/clock_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/clockid_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/time_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/timer_t.h \
+  /usr/lib/gcc/x86_64-linux-gnu/7/include/stddef.h \
+  /usr/include/x86_64-linux-gnu/bits/stdint-intn.h \
   /usr/include/endian.h \
   /usr/include/x86_64-linux-gnu/bits/endian.h \
   /usr/include/x86_64-linux-gnu/bits/byteswap.h \
   /usr/include/x86_64-linux-gnu/bits/byteswap-16.h \
+  /usr/include/x86_64-linux-gnu/bits/uintn-identity.h \
   /usr/include/x86_64-linux-gnu/sys/select.h \
   /usr/include/x86_64-linux-gnu/bits/select.h \
-  /usr/include/x86_64-linux-gnu/bits/sigset.h \
-  /usr/include/x86_64-linux-gnu/bits/time.h \
+  /usr/include/x86_64-linux-gnu/bits/types/sigset_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/__sigset_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/struct_timeval.h \
+  /usr/include/x86_64-linux-gnu/bits/types/struct_timespec.h \
   /usr/include/x86_64-linux-gnu/bits/select2.h \
   /usr/include/x86_64-linux-gnu/sys/sysmacros.h \
+  /usr/include/x86_64-linux-gnu/bits/sysmacros.h \
   /usr/include/x86_64-linux-gnu/bits/pthreadtypes.h \
+  /usr/include/x86_64-linux-gnu/bits/thread-shared-types.h \
+  /usr/include/x86_64-linux-gnu/bits/pthreadtypes-arch.h \
   /usr/include/x86_64-linux-gnu/sys/stat.h \
   /usr/include/x86_64-linux-gnu/bits/stat.h \
   /usr/include/x86_64-linux-gnu/sys/mman.h \
   /usr/include/x86_64-linux-gnu/bits/mman.h \
   /usr/include/x86_64-linux-gnu/bits/mman-linux.h \
+  /usr/include/x86_64-linux-gnu/bits/mman-shared.h \
   /usr/include/unistd.h \
   /usr/include/x86_64-linux-gnu/bits/posix_opt.h \
   /usr/include/x86_64-linux-gnu/bits/environments.h \
   /usr/include/x86_64-linux-gnu/bits/confname.h \
-  /usr/include/getopt.h \
+  /usr/include/x86_64-linux-gnu/bits/getopt_posix.h \
+  /usr/include/x86_64-linux-gnu/bits/getopt_core.h \
   /usr/include/x86_64-linux-gnu/bits/unistd.h \
   /usr/include/fcntl.h \
   /usr/include/x86_64-linux-gnu/bits/fcntl.h \
   /usr/include/x86_64-linux-gnu/bits/fcntl-linux.h \
   /usr/include/x86_64-linux-gnu/bits/fcntl2.h \
   /usr/include/string.h \
-  /usr/include/xlocale.h \
-  /usr/include/x86_64-linux-gnu/bits/string.h \
-  /usr/include/x86_64-linux-gnu/bits/string2.h \
+  /usr/include/x86_64-linux-gnu/bits/libc-header-start.h \
+  /usr/include/x86_64-linux-gnu/bits/types/locale_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/__locale_t.h \
+  /usr/include/strings.h \
+  /usr/include/x86_64-linux-gnu/bits/strings_fortified.h \
+  /usr/include/x86_64-linux-gnu/bits/string_fortified.h \
   /usr/include/stdlib.h \
-  /usr/include/x86_64-linux-gnu/bits/string3.h \
   /usr/include/x86_64-linux-gnu/bits/waitflags.h \
   /usr/include/x86_64-linux-gnu/bits/waitstatus.h \
+  /usr/include/x86_64-linux-gnu/bits/floatn.h \
+  /usr/include/x86_64-linux-gnu/bits/floatn-common.h \
   /usr/include/alloca.h \
   /usr/include/x86_64-linux-gnu/bits/stdlib-bsearch.h \
   /usr/include/x86_64-linux-gnu/bits/stdlib-float.h \
   /usr/include/x86_64-linux-gnu/bits/stdlib.h \
   /usr/include/stdio.h \
-  /usr/include/libio.h \
-  /usr/include/_G_config.h \
-  /usr/include/wchar.h \
-  /usr/lib/gcc/x86_64-linux-gnu/5/include/stdarg.h \
+  /usr/include/x86_64-linux-gnu/bits/types/__FILE.h \
+  /usr/include/x86_64-linux-gnu/bits/types/FILE.h \
+  /usr/include/x86_64-linux-gnu/bits/libio.h \
+  /usr/include/x86_64-linux-gnu/bits/_G_config.h \
+    $(wildcard include/config/h.h) \
+  /usr/include/x86_64-linux-gnu/bits/types/__mbstate_t.h \
+  /usr/lib/gcc/x86_64-linux-gnu/7/include/stdarg.h \
   /usr/include/x86_64-linux-gnu/bits/stdio_lim.h \
   /usr/include/x86_64-linux-gnu/bits/sys_errlist.h \
   /usr/include/x86_64-linux-gnu/bits/stdio.h \
   /usr/include/x86_64-linux-gnu/bits/stdio2.h \
-  /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/limits.h \
-  /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/syslimits.h \
+  /usr/lib/gcc/x86_64-linux-gnu/7/include-fixed/limits.h \
+  /usr/lib/gcc/x86_64-linux-gnu/7/include-fixed/syslimits.h \
   /usr/include/limits.h \
   /usr/include/x86_64-linux-gnu/bits/posix1_lim.h \
   /usr/include/x86_64-linux-gnu/bits/local_lim.h \
@@ -77,12 +97,9 @@ deps_scripts/basic/fixdep := \
   /usr/include/ctype.h \
   /usr/include/arpa/inet.h \
   /usr/include/netinet/in.h \
-  /usr/lib/gcc/x86_64-linux-gnu/5/include/stdint.h \
-  /usr/include/stdint.h \
-  /usr/include/x86_64-linux-gnu/bits/wchar.h \
+  /usr/include/x86_64-linux-gnu/bits/stdint-uintn.h \
   /usr/include/x86_64-linux-gnu/sys/socket.h \
-  /usr/include/x86_64-linux-gnu/sys/uio.h \
-  /usr/include/x86_64-linux-gnu/bits/uio.h \
+  /usr/include/x86_64-linux-gnu/bits/types/struct_iovec.h \
   /usr/include/x86_64-linux-gnu/bits/socket.h \
   /usr/include/x86_64-linux-gnu/bits/socket_type.h \
   /usr/include/x86_64-linux-gnu/bits/sockaddr.h \
@@ -90,6 +107,7 @@ deps_scripts/basic/fixdep := \
   /usr/include/asm-generic/socket.h \
   /usr/include/x86_64-linux-gnu/asm/sockios.h \
   /usr/include/asm-generic/sockios.h \
+  /usr/include/x86_64-linux-gnu/bits/types/struct_osockaddr.h \
   /usr/include/x86_64-linux-gnu/bits/socket2.h \
   /usr/include/x86_64-linux-gnu/bits/in.h \
 

+ 45 - 19
board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/tools/.gen_eth_addr.cmd

@@ -7,15 +7,21 @@ deps_tools/gen_eth_addr := \
   include/libfdt_env.h \
   include/compiler.h \
     $(wildcard include/config/use/stdint.h) \
-  /usr/lib/gcc/x86_64-linux-gnu/5/include/stddef.h \
-  /usr/lib/gcc/x86_64-linux-gnu/5/include/stdint.h \
+  /usr/lib/gcc/x86_64-linux-gnu/7/include/stddef.h \
+  /usr/lib/gcc/x86_64-linux-gnu/7/include/stdint.h \
   /usr/include/stdint.h \
+  /usr/include/x86_64-linux-gnu/bits/libc-header-start.h \
   /usr/include/features.h \
   /usr/include/x86_64-linux-gnu/sys/cdefs.h \
   /usr/include/x86_64-linux-gnu/bits/wordsize.h \
+  /usr/include/x86_64-linux-gnu/bits/long-double.h \
   /usr/include/x86_64-linux-gnu/gnu/stubs.h \
   /usr/include/x86_64-linux-gnu/gnu/stubs-64.h \
+  /usr/include/x86_64-linux-gnu/bits/types.h \
+  /usr/include/x86_64-linux-gnu/bits/typesizes.h \
   /usr/include/x86_64-linux-gnu/bits/wchar.h \
+  /usr/include/x86_64-linux-gnu/bits/stdint-intn.h \
+  /usr/include/x86_64-linux-gnu/bits/stdint-uintn.h \
   /usr/include/errno.h \
   /usr/include/x86_64-linux-gnu/bits/errno.h \
   /usr/include/linux/errno.h \
@@ -25,50 +31,69 @@ deps_tools/gen_eth_addr := \
   /usr/include/stdlib.h \
   /usr/include/x86_64-linux-gnu/bits/waitflags.h \
   /usr/include/x86_64-linux-gnu/bits/waitstatus.h \
+  /usr/include/x86_64-linux-gnu/bits/floatn.h \
+  /usr/include/x86_64-linux-gnu/bits/floatn-common.h \
+  /usr/include/x86_64-linux-gnu/bits/types/locale_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/__locale_t.h \
+  /usr/include/x86_64-linux-gnu/sys/types.h \
+  /usr/include/x86_64-linux-gnu/bits/types/clock_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/clockid_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/time_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/timer_t.h \
   /usr/include/endian.h \
   /usr/include/x86_64-linux-gnu/bits/endian.h \
   /usr/include/x86_64-linux-gnu/bits/byteswap.h \
-  /usr/include/x86_64-linux-gnu/bits/types.h \
-  /usr/include/x86_64-linux-gnu/bits/typesizes.h \
   /usr/include/x86_64-linux-gnu/bits/byteswap-16.h \
-  /usr/include/xlocale.h \
-  /usr/include/x86_64-linux-gnu/sys/types.h \
-  /usr/include/time.h \
+  /usr/include/x86_64-linux-gnu/bits/uintn-identity.h \
   /usr/include/x86_64-linux-gnu/sys/select.h \
   /usr/include/x86_64-linux-gnu/bits/select.h \
-  /usr/include/x86_64-linux-gnu/bits/sigset.h \
-  /usr/include/x86_64-linux-gnu/bits/time.h \
+  /usr/include/x86_64-linux-gnu/bits/types/sigset_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/__sigset_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/struct_timeval.h \
+  /usr/include/x86_64-linux-gnu/bits/types/struct_timespec.h \
   /usr/include/x86_64-linux-gnu/bits/select2.h \
   /usr/include/x86_64-linux-gnu/sys/sysmacros.h \
+  /usr/include/x86_64-linux-gnu/bits/sysmacros.h \
   /usr/include/x86_64-linux-gnu/bits/pthreadtypes.h \
+  /usr/include/x86_64-linux-gnu/bits/thread-shared-types.h \
+  /usr/include/x86_64-linux-gnu/bits/pthreadtypes-arch.h \
   /usr/include/alloca.h \
   /usr/include/x86_64-linux-gnu/bits/stdlib-bsearch.h \
   /usr/include/x86_64-linux-gnu/bits/stdlib-float.h \
   /usr/include/x86_64-linux-gnu/bits/stdlib.h \
   /usr/include/stdio.h \
-  /usr/include/libio.h \
-  /usr/include/_G_config.h \
-  /usr/include/wchar.h \
-  /usr/lib/gcc/x86_64-linux-gnu/5/include/stdarg.h \
+  /usr/include/x86_64-linux-gnu/bits/types/__FILE.h \
+  /usr/include/x86_64-linux-gnu/bits/types/FILE.h \
+  /usr/include/x86_64-linux-gnu/bits/libio.h \
+  /usr/include/x86_64-linux-gnu/bits/_G_config.h \
+    $(wildcard include/config/h.h) \
+  /usr/include/x86_64-linux-gnu/bits/types/__mbstate_t.h \
+  /usr/lib/gcc/x86_64-linux-gnu/7/include/stdarg.h \
   /usr/include/x86_64-linux-gnu/bits/stdio_lim.h \
   /usr/include/x86_64-linux-gnu/bits/sys_errlist.h \
   /usr/include/x86_64-linux-gnu/bits/stdio.h \
   /usr/include/x86_64-linux-gnu/bits/stdio2.h \
   /usr/include/string.h \
-  /usr/include/x86_64-linux-gnu/bits/string.h \
-  /usr/include/x86_64-linux-gnu/bits/string2.h \
-  /usr/include/x86_64-linux-gnu/bits/string3.h \
+  /usr/include/strings.h \
+  /usr/include/x86_64-linux-gnu/bits/strings_fortified.h \
+  /usr/include/x86_64-linux-gnu/bits/string_fortified.h \
   /usr/include/x86_64-linux-gnu/sys/mman.h \
   /usr/include/x86_64-linux-gnu/bits/mman.h \
   /usr/include/x86_64-linux-gnu/bits/mman-linux.h \
+  /usr/include/x86_64-linux-gnu/bits/mman-shared.h \
   /usr/include/fcntl.h \
   /usr/include/x86_64-linux-gnu/bits/fcntl.h \
   /usr/include/x86_64-linux-gnu/bits/fcntl-linux.h \
-  /usr/include/x86_64-linux-gnu/bits/uio.h \
+  /usr/include/x86_64-linux-gnu/bits/types/struct_iovec.h \
+  /usr/include/linux/falloc.h \
   /usr/include/x86_64-linux-gnu/bits/stat.h \
   /usr/include/x86_64-linux-gnu/bits/fcntl2.h \
   /usr/include/byteswap.h \
+  /usr/include/time.h \
+  /usr/include/x86_64-linux-gnu/bits/time.h \
   /usr/include/x86_64-linux-gnu/bits/timex.h \
+  /usr/include/x86_64-linux-gnu/bits/types/struct_tm.h \
+  /usr/include/x86_64-linux-gnu/bits/types/struct_itimerspec.h \
   include/linux/types.h \
     $(wildcard include/config/uid16.h) \
   /usr/include/linux/posix_types.h \
@@ -82,12 +107,13 @@ deps_tools/gen_eth_addr := \
   /usr/include/x86_64-linux-gnu/asm/types.h \
   /usr/include/asm-generic/types.h \
   /usr/include/asm-generic/int-ll64.h \
-  /usr/lib/gcc/x86_64-linux-gnu/5/include/stdbool.h \
+  /usr/lib/gcc/x86_64-linux-gnu/7/include/stdbool.h \
   /usr/include/unistd.h \
   /usr/include/x86_64-linux-gnu/bits/posix_opt.h \
   /usr/include/x86_64-linux-gnu/bits/environments.h \
   /usr/include/x86_64-linux-gnu/bits/confname.h \
-  /usr/include/getopt.h \
+  /usr/include/x86_64-linux-gnu/bits/getopt_posix.h \
+  /usr/include/x86_64-linux-gnu/bits/getopt_core.h \
   /usr/include/x86_64-linux-gnu/bits/unistd.h \
 
 tools/gen_eth_addr: $(deps_tools/gen_eth_addr)

+ 45 - 19
board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/tools/.img2srec.cmd

@@ -7,15 +7,21 @@ deps_tools/img2srec := \
   include/libfdt_env.h \
   include/compiler.h \
     $(wildcard include/config/use/stdint.h) \
-  /usr/lib/gcc/x86_64-linux-gnu/5/include/stddef.h \
-  /usr/lib/gcc/x86_64-linux-gnu/5/include/stdint.h \
+  /usr/lib/gcc/x86_64-linux-gnu/7/include/stddef.h \
+  /usr/lib/gcc/x86_64-linux-gnu/7/include/stdint.h \
   /usr/include/stdint.h \
+  /usr/include/x86_64-linux-gnu/bits/libc-header-start.h \
   /usr/include/features.h \
   /usr/include/x86_64-linux-gnu/sys/cdefs.h \
   /usr/include/x86_64-linux-gnu/bits/wordsize.h \
+  /usr/include/x86_64-linux-gnu/bits/long-double.h \
   /usr/include/x86_64-linux-gnu/gnu/stubs.h \
   /usr/include/x86_64-linux-gnu/gnu/stubs-64.h \
+  /usr/include/x86_64-linux-gnu/bits/types.h \
+  /usr/include/x86_64-linux-gnu/bits/typesizes.h \
   /usr/include/x86_64-linux-gnu/bits/wchar.h \
+  /usr/include/x86_64-linux-gnu/bits/stdint-intn.h \
+  /usr/include/x86_64-linux-gnu/bits/stdint-uintn.h \
   /usr/include/errno.h \
   /usr/include/x86_64-linux-gnu/bits/errno.h \
   /usr/include/linux/errno.h \
@@ -25,50 +31,69 @@ deps_tools/img2srec := \
   /usr/include/stdlib.h \
   /usr/include/x86_64-linux-gnu/bits/waitflags.h \
   /usr/include/x86_64-linux-gnu/bits/waitstatus.h \
+  /usr/include/x86_64-linux-gnu/bits/floatn.h \
+  /usr/include/x86_64-linux-gnu/bits/floatn-common.h \
+  /usr/include/x86_64-linux-gnu/bits/types/locale_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/__locale_t.h \
+  /usr/include/x86_64-linux-gnu/sys/types.h \
+  /usr/include/x86_64-linux-gnu/bits/types/clock_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/clockid_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/time_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/timer_t.h \
   /usr/include/endian.h \
   /usr/include/x86_64-linux-gnu/bits/endian.h \
   /usr/include/x86_64-linux-gnu/bits/byteswap.h \
-  /usr/include/x86_64-linux-gnu/bits/types.h \
-  /usr/include/x86_64-linux-gnu/bits/typesizes.h \
   /usr/include/x86_64-linux-gnu/bits/byteswap-16.h \
-  /usr/include/xlocale.h \
-  /usr/include/x86_64-linux-gnu/sys/types.h \
-  /usr/include/time.h \
+  /usr/include/x86_64-linux-gnu/bits/uintn-identity.h \
   /usr/include/x86_64-linux-gnu/sys/select.h \
   /usr/include/x86_64-linux-gnu/bits/select.h \
-  /usr/include/x86_64-linux-gnu/bits/sigset.h \
-  /usr/include/x86_64-linux-gnu/bits/time.h \
+  /usr/include/x86_64-linux-gnu/bits/types/sigset_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/__sigset_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/struct_timeval.h \
+  /usr/include/x86_64-linux-gnu/bits/types/struct_timespec.h \
   /usr/include/x86_64-linux-gnu/bits/select2.h \
   /usr/include/x86_64-linux-gnu/sys/sysmacros.h \
+  /usr/include/x86_64-linux-gnu/bits/sysmacros.h \
   /usr/include/x86_64-linux-gnu/bits/pthreadtypes.h \
+  /usr/include/x86_64-linux-gnu/bits/thread-shared-types.h \
+  /usr/include/x86_64-linux-gnu/bits/pthreadtypes-arch.h \
   /usr/include/alloca.h \
   /usr/include/x86_64-linux-gnu/bits/stdlib-bsearch.h \
   /usr/include/x86_64-linux-gnu/bits/stdlib-float.h \
   /usr/include/x86_64-linux-gnu/bits/stdlib.h \
   /usr/include/stdio.h \
-  /usr/include/libio.h \
-  /usr/include/_G_config.h \
-  /usr/include/wchar.h \
-  /usr/lib/gcc/x86_64-linux-gnu/5/include/stdarg.h \
+  /usr/include/x86_64-linux-gnu/bits/types/__FILE.h \
+  /usr/include/x86_64-linux-gnu/bits/types/FILE.h \
+  /usr/include/x86_64-linux-gnu/bits/libio.h \
+  /usr/include/x86_64-linux-gnu/bits/_G_config.h \
+    $(wildcard include/config/h.h) \
+  /usr/include/x86_64-linux-gnu/bits/types/__mbstate_t.h \
+  /usr/lib/gcc/x86_64-linux-gnu/7/include/stdarg.h \
   /usr/include/x86_64-linux-gnu/bits/stdio_lim.h \
   /usr/include/x86_64-linux-gnu/bits/sys_errlist.h \
   /usr/include/x86_64-linux-gnu/bits/stdio.h \
   /usr/include/x86_64-linux-gnu/bits/stdio2.h \
   /usr/include/string.h \
-  /usr/include/x86_64-linux-gnu/bits/string.h \
-  /usr/include/x86_64-linux-gnu/bits/string2.h \
-  /usr/include/x86_64-linux-gnu/bits/string3.h \
+  /usr/include/strings.h \
+  /usr/include/x86_64-linux-gnu/bits/strings_fortified.h \
+  /usr/include/x86_64-linux-gnu/bits/string_fortified.h \
   /usr/include/x86_64-linux-gnu/sys/mman.h \
   /usr/include/x86_64-linux-gnu/bits/mman.h \
   /usr/include/x86_64-linux-gnu/bits/mman-linux.h \
+  /usr/include/x86_64-linux-gnu/bits/mman-shared.h \
   /usr/include/fcntl.h \
   /usr/include/x86_64-linux-gnu/bits/fcntl.h \
   /usr/include/x86_64-linux-gnu/bits/fcntl-linux.h \
-  /usr/include/x86_64-linux-gnu/bits/uio.h \
+  /usr/include/x86_64-linux-gnu/bits/types/struct_iovec.h \
+  /usr/include/linux/falloc.h \
   /usr/include/x86_64-linux-gnu/bits/stat.h \
   /usr/include/x86_64-linux-gnu/bits/fcntl2.h \
   /usr/include/byteswap.h \
+  /usr/include/time.h \
+  /usr/include/x86_64-linux-gnu/bits/time.h \
   /usr/include/x86_64-linux-gnu/bits/timex.h \
+  /usr/include/x86_64-linux-gnu/bits/types/struct_tm.h \
+  /usr/include/x86_64-linux-gnu/bits/types/struct_itimerspec.h \
   include/linux/types.h \
     $(wildcard include/config/uid16.h) \
   /usr/include/linux/posix_types.h \
@@ -82,7 +107,7 @@ deps_tools/img2srec := \
   /usr/include/x86_64-linux-gnu/asm/types.h \
   /usr/include/asm-generic/types.h \
   /usr/include/asm-generic/int-ll64.h \
-  /usr/lib/gcc/x86_64-linux-gnu/5/include/stdbool.h \
+  /usr/lib/gcc/x86_64-linux-gnu/7/include/stdbool.h \
   tools/os_support.h \
   include/compiler.h \
   /usr/include/ctype.h \
@@ -92,7 +117,8 @@ deps_tools/img2srec := \
   /usr/include/x86_64-linux-gnu/bits/posix_opt.h \
   /usr/include/x86_64-linux-gnu/bits/environments.h \
   /usr/include/x86_64-linux-gnu/bits/confname.h \
-  /usr/include/getopt.h \
+  /usr/include/x86_64-linux-gnu/bits/getopt_posix.h \
+  /usr/include/x86_64-linux-gnu/bits/getopt_core.h \
   /usr/include/x86_64-linux-gnu/bits/unistd.h \
 
 tools/img2srec: $(deps_tools/img2srec)

+ 62 - 23
board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/tools/.proftool.cmd

@@ -7,15 +7,21 @@ deps_tools/proftool := \
   include/libfdt_env.h \
   include/compiler.h \
     $(wildcard include/config/use/stdint.h) \
-  /usr/lib/gcc/x86_64-linux-gnu/5/include/stddef.h \
-  /usr/lib/gcc/x86_64-linux-gnu/5/include/stdint.h \
+  /usr/lib/gcc/x86_64-linux-gnu/7/include/stddef.h \
+  /usr/lib/gcc/x86_64-linux-gnu/7/include/stdint.h \
   /usr/include/stdint.h \
+  /usr/include/x86_64-linux-gnu/bits/libc-header-start.h \
   /usr/include/features.h \
   /usr/include/x86_64-linux-gnu/sys/cdefs.h \
   /usr/include/x86_64-linux-gnu/bits/wordsize.h \
+  /usr/include/x86_64-linux-gnu/bits/long-double.h \
   /usr/include/x86_64-linux-gnu/gnu/stubs.h \
   /usr/include/x86_64-linux-gnu/gnu/stubs-64.h \
+  /usr/include/x86_64-linux-gnu/bits/types.h \
+  /usr/include/x86_64-linux-gnu/bits/typesizes.h \
   /usr/include/x86_64-linux-gnu/bits/wchar.h \
+  /usr/include/x86_64-linux-gnu/bits/stdint-intn.h \
+  /usr/include/x86_64-linux-gnu/bits/stdint-uintn.h \
   /usr/include/errno.h \
   /usr/include/x86_64-linux-gnu/bits/errno.h \
   /usr/include/linux/errno.h \
@@ -25,50 +31,69 @@ deps_tools/proftool := \
   /usr/include/stdlib.h \
   /usr/include/x86_64-linux-gnu/bits/waitflags.h \
   /usr/include/x86_64-linux-gnu/bits/waitstatus.h \
+  /usr/include/x86_64-linux-gnu/bits/floatn.h \
+  /usr/include/x86_64-linux-gnu/bits/floatn-common.h \
+  /usr/include/x86_64-linux-gnu/bits/types/locale_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/__locale_t.h \
+  /usr/include/x86_64-linux-gnu/sys/types.h \
+  /usr/include/x86_64-linux-gnu/bits/types/clock_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/clockid_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/time_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/timer_t.h \
   /usr/include/endian.h \
   /usr/include/x86_64-linux-gnu/bits/endian.h \
   /usr/include/x86_64-linux-gnu/bits/byteswap.h \
-  /usr/include/x86_64-linux-gnu/bits/types.h \
-  /usr/include/x86_64-linux-gnu/bits/typesizes.h \
   /usr/include/x86_64-linux-gnu/bits/byteswap-16.h \
-  /usr/include/xlocale.h \
-  /usr/include/x86_64-linux-gnu/sys/types.h \
-  /usr/include/time.h \
+  /usr/include/x86_64-linux-gnu/bits/uintn-identity.h \
   /usr/include/x86_64-linux-gnu/sys/select.h \
   /usr/include/x86_64-linux-gnu/bits/select.h \
-  /usr/include/x86_64-linux-gnu/bits/sigset.h \
-  /usr/include/x86_64-linux-gnu/bits/time.h \
+  /usr/include/x86_64-linux-gnu/bits/types/sigset_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/__sigset_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/struct_timeval.h \
+  /usr/include/x86_64-linux-gnu/bits/types/struct_timespec.h \
   /usr/include/x86_64-linux-gnu/bits/select2.h \
   /usr/include/x86_64-linux-gnu/sys/sysmacros.h \
+  /usr/include/x86_64-linux-gnu/bits/sysmacros.h \
   /usr/include/x86_64-linux-gnu/bits/pthreadtypes.h \
+  /usr/include/x86_64-linux-gnu/bits/thread-shared-types.h \
+  /usr/include/x86_64-linux-gnu/bits/pthreadtypes-arch.h \
   /usr/include/alloca.h \
   /usr/include/x86_64-linux-gnu/bits/stdlib-bsearch.h \
   /usr/include/x86_64-linux-gnu/bits/stdlib-float.h \
   /usr/include/x86_64-linux-gnu/bits/stdlib.h \
   /usr/include/stdio.h \
-  /usr/include/libio.h \
-  /usr/include/_G_config.h \
-  /usr/include/wchar.h \
-  /usr/lib/gcc/x86_64-linux-gnu/5/include/stdarg.h \
+  /usr/include/x86_64-linux-gnu/bits/types/__FILE.h \
+  /usr/include/x86_64-linux-gnu/bits/types/FILE.h \
+  /usr/include/x86_64-linux-gnu/bits/libio.h \
+  /usr/include/x86_64-linux-gnu/bits/_G_config.h \
+    $(wildcard include/config/h.h) \
+  /usr/include/x86_64-linux-gnu/bits/types/__mbstate_t.h \
+  /usr/lib/gcc/x86_64-linux-gnu/7/include/stdarg.h \
   /usr/include/x86_64-linux-gnu/bits/stdio_lim.h \
   /usr/include/x86_64-linux-gnu/bits/sys_errlist.h \
   /usr/include/x86_64-linux-gnu/bits/stdio.h \
   /usr/include/x86_64-linux-gnu/bits/stdio2.h \
   /usr/include/string.h \
-  /usr/include/x86_64-linux-gnu/bits/string.h \
-  /usr/include/x86_64-linux-gnu/bits/string2.h \
-  /usr/include/x86_64-linux-gnu/bits/string3.h \
+  /usr/include/strings.h \
+  /usr/include/x86_64-linux-gnu/bits/strings_fortified.h \
+  /usr/include/x86_64-linux-gnu/bits/string_fortified.h \
   /usr/include/x86_64-linux-gnu/sys/mman.h \
   /usr/include/x86_64-linux-gnu/bits/mman.h \
   /usr/include/x86_64-linux-gnu/bits/mman-linux.h \
+  /usr/include/x86_64-linux-gnu/bits/mman-shared.h \
   /usr/include/fcntl.h \
   /usr/include/x86_64-linux-gnu/bits/fcntl.h \
   /usr/include/x86_64-linux-gnu/bits/fcntl-linux.h \
-  /usr/include/x86_64-linux-gnu/bits/uio.h \
+  /usr/include/x86_64-linux-gnu/bits/types/struct_iovec.h \
+  /usr/include/linux/falloc.h \
   /usr/include/x86_64-linux-gnu/bits/stat.h \
   /usr/include/x86_64-linux-gnu/bits/fcntl2.h \
   /usr/include/byteswap.h \
+  /usr/include/time.h \
+  /usr/include/x86_64-linux-gnu/bits/time.h \
   /usr/include/x86_64-linux-gnu/bits/timex.h \
+  /usr/include/x86_64-linux-gnu/bits/types/struct_tm.h \
+  /usr/include/x86_64-linux-gnu/bits/types/struct_itimerspec.h \
   include/linux/types.h \
     $(wildcard include/config/uid16.h) \
   /usr/include/linux/posix_types.h \
@@ -82,32 +107,46 @@ deps_tools/proftool := \
   /usr/include/x86_64-linux-gnu/asm/types.h \
   /usr/include/asm-generic/types.h \
   /usr/include/asm-generic/int-ll64.h \
-  /usr/lib/gcc/x86_64-linux-gnu/5/include/stdbool.h \
+  /usr/lib/gcc/x86_64-linux-gnu/7/include/stdbool.h \
   /usr/include/assert.h \
   /usr/include/ctype.h \
-  /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/limits.h \
-  /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/syslimits.h \
+  /usr/lib/gcc/x86_64-linux-gnu/7/include-fixed/limits.h \
+  /usr/lib/gcc/x86_64-linux-gnu/7/include-fixed/syslimits.h \
   /usr/include/limits.h \
   /usr/include/x86_64-linux-gnu/bits/posix1_lim.h \
   /usr/include/x86_64-linux-gnu/bits/local_lim.h \
   /usr/include/linux/limits.h \
   /usr/include/x86_64-linux-gnu/bits/posix2_lim.h \
   /usr/include/x86_64-linux-gnu/bits/xopen_lim.h \
+  /usr/include/x86_64-linux-gnu/bits/uio_lim.h \
   /usr/include/regex.h \
   /usr/include/unistd.h \
   /usr/include/x86_64-linux-gnu/bits/posix_opt.h \
   /usr/include/x86_64-linux-gnu/bits/environments.h \
   /usr/include/x86_64-linux-gnu/bits/confname.h \
-  /usr/include/getopt.h \
+  /usr/include/x86_64-linux-gnu/bits/getopt_posix.h \
+  /usr/include/x86_64-linux-gnu/bits/getopt_core.h \
   /usr/include/x86_64-linux-gnu/bits/unistd.h \
   /usr/include/x86_64-linux-gnu/sys/param.h \
   /usr/include/signal.h \
   /usr/include/x86_64-linux-gnu/bits/signum.h \
-  /usr/include/x86_64-linux-gnu/bits/siginfo.h \
+  /usr/include/x86_64-linux-gnu/bits/signum-generic.h \
+  /usr/include/x86_64-linux-gnu/bits/types/sig_atomic_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/siginfo_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/__sigval_t.h \
+  /usr/include/x86_64-linux-gnu/bits/siginfo-arch.h \
+  /usr/include/x86_64-linux-gnu/bits/siginfo-consts.h \
+  /usr/include/x86_64-linux-gnu/bits/siginfo-consts-arch.h \
+  /usr/include/x86_64-linux-gnu/bits/types/sigval_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/sigevent_t.h \
+  /usr/include/x86_64-linux-gnu/bits/sigevent-consts.h \
   /usr/include/x86_64-linux-gnu/bits/sigaction.h \
   /usr/include/x86_64-linux-gnu/bits/sigcontext.h \
-  /usr/include/x86_64-linux-gnu/bits/sigstack.h \
+  /usr/include/x86_64-linux-gnu/bits/types/stack_t.h \
   /usr/include/x86_64-linux-gnu/sys/ucontext.h \
+  /usr/include/x86_64-linux-gnu/bits/sigstack.h \
+  /usr/include/x86_64-linux-gnu/bits/ss_flags.h \
+  /usr/include/x86_64-linux-gnu/bits/types/struct_sigstack.h \
   /usr/include/x86_64-linux-gnu/bits/sigthread.h \
   /usr/include/x86_64-linux-gnu/bits/param.h \
   /usr/include/linux/param.h \

+ 1 - 1
run_gen_make_script.sh

@@ -47,7 +47,7 @@ echo -e "\t@echo     Building User rootfs"
 echo -e "\t@echo ================================="
 echo -e "#\t@cd EVSE/GPL;make Project=$1 all"
 echo -e "\t@cd EVSE/Modularization;make Project=$1 all"
-echo -e "\t@cd EVSE/Projects/$1/Apps;make all"
+echo -e "\t@cd EVSE/Projects/$1/Apps;make Project=$1 all"
 echo -e "\t@rm -f EVSE/Projects/$1/Images/ramdisk.gz"
 echo -e "\t@dd if=/dev/zero of=/dev/ram0 bs=1k count=131072"
 echo -e "\t@mke2fs -vm0 /dev/ram0 131072"

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