liyi 1 год назад
Родитель
Сommit
ed850835ed

+ 36 - 28
truing_control/PDU-AC/common/common.c

@@ -2,39 +2,47 @@
 #include "board_cfg.h"
 
 
-typedef union {
-	uint8_t 	data[500];
-	uint16_t 	relay_status[15];
-	delay_t   input_delay[12];
-	threshold_t input[3];
-	threshold_t output[12];
-	uint16_t    input_over_func[3];
-	uint16_t    output_over_func[12];
-}read_data_t;
 
 
 void read_config_from_eeprom(void)
 {
 	board_t *board = get_board();
-	/* read status of relay */
-	board->read_eeprom(EEPROM_RELAY_STARTUS_ADDR,(uint8_t *)(&board->relay_staging_staus[0]),sizeof(uint16_t) * RelaySlaveChaNum);
-	/* read delay of relay */
-	board->read_eeprom(EEPROM_DELAY_ADDR,(uint8_t *)(&board->md_data.rw_data.delay_chn[0]),sizeof(delay_t) * RelaySlaveChaNum);
-	
-#if SURPPORT_2_PT
-	/* read input threshold */
-	board->read_eeprom(EEPROM_THRESHOLD_INPUT_ADDR,(uint8_t *)(&board->md_data.rw_data.th_in[0]),sizeof(threshold_t) * 2);
-	for(int i = 0; i < 2;i++)
-		board->check_threshold(THRESHOLD_IN,i);
-	/* input over func */
-	board->read_eeprom(EEPROM_INPUT_OVER_FUNC_ADDR,(uint8_t *)(&board->md_data.rw_data.over_fun_in[0]),sizeof(uint16_t) * 2);
+	if(board)
+	{
+		uint16_t device = 0;
+		board->read_eeprom(EEPROM_DEVICES_ADDR,(uint8_t *)&device,EEPROM_DEVICES_LENTH);
+		if(device != board->md_data.r_data.r_d.dev_chn)
+		{
+			//default write eeprom
+			board->write_eeprom(EEPROM_DEVICES_ADDR,(uint8_t *)&board->md_data.r_data.r_d.dev_chn,EEPROM_DEVICES_LENTH);
+			board->write_eeprom(EEPROM_STATUS_ADDR,(uint8_t *)&board->relay_staging_staus[0],EEPROM_STATUS_LENTH);
+			board->write_eeprom(EEPROM_OTHER_ADDR,(uint8_t *)&board->md_data.rw_data.rw_d.delay_chn[0],START_RW_LENTH-EEPROM_STATUS_LENTH);
+			//config phase information
+			uint8_t buff[EEPROM_CHANNEL_LENTH] = {0};
+			board->write_eeprom(EEPROM_CHANNEL_PHASE,buff,EEPROM_CHANNEL_LENTH);
+		}else
+		{
+			board->read_eeprom(EEPROM_STATUS_ADDR,(uint8_t *)&board->relay_staging_staus[0],EEPROM_STATUS_LENTH);
+			board->read_eeprom(EEPROM_OTHER_ADDR,(uint8_t *)&board->md_data.rw_data.rw_d.delay_chn[0],START_RW_LENTH-EEPROM_STATUS_LENTH);
+						//get phase information
+			uint8_t buff[EEPROM_CHANNEL_LENTH] = {0};
+			board->read_eeprom(EEPROM_CHANNEL_PHASE,buff,EEPROM_CHANNEL_LENTH);
+#if POWER_AC_3_3
+			for(int i = 0; i < 3; i++)
+			{
+				board->check_threshold(THRESHOLD_IN,i);
+			}
 #else
-	/* read input threshold */
-	board->read_eeprom(EEPROM_THRESHOLD_INPUT_ADDR,(uint8_t *)(&board->md_data.rw_data.th_in[0]),sizeof(threshold_t) * 1);
-	board->check_threshold(THRESHOLD_IN,0);
-	/* input over func */
-	board->read_eeprom(EEPROM_INPUT_OVER_FUNC_ADDR,(uint8_t *)(&board->md_data.rw_data.over_fun_in[0]),sizeof(uint16_t) * 1);
+			for(int i = 0 ; i < INPUT_PT_NUM;i++)
+			{
+				board->check_threshold(THRESHOLD_IN,i);
+			}
 #endif
-	board->read_eeprom(EEPROM_INPUT_OVER_FUNC_ADDR,(uint8_t *)(&board->md_data.rw_data.over_func_out[0]),sizeof(uint16_t) * RelaySlaveChaNum);
-	
+			for(int i = 0; i < RelaySlaveChaNum; i++)
+			{
+				board->md_data.r_data.r_d.ele_out[i].resever = buff[i];   //config phase information
+				board->check_threshold(THRESHOLD_OUT,i);
+			}
+		}
+	}
 }

+ 109 - 28
truing_control/PDU-AC/common/common.h

@@ -17,10 +17,22 @@
 
 
 
-#define START_REGISTER            4000
+#define START_R_REGISTER            			4000
+
+#define START_R_LENTH             				(250)
+
+
+
+#define START_RW_REGISTER         				(START_R_REGISTER + START_R_LENTH)
+
+#define START_RW_LENTH            				(350)
+
+
+#define START_W_REGISTER          				(START_RW_REGISTER+START_RW_LENTH)
+
+#define START_W_LENTH             				(100)
 
 
-#define START_RW_REGISTER         4284
 
 
 //#define 
@@ -167,10 +179,33 @@
 
 
 
+
+#define EEPROM_DEVICES_ADDR                   (0)				//device signal
+#define EEPROM_DEVICES_LENTH                  (2)
+
+
+#define EEPROM_STATUS_ADDR                    (64)			// one page
+#define EEPROM_STATUS_LENTH                   (16*2)
+
+
+#define EEPROM_OTHER_ADDR                     (128)
+#define EEPROM_OTHER_LENTH                    (32*30)   // 30 page    
+
+
+#define EEPROM_CHANNEL_PHASE                  (2048)
+#define EEPROM_CHANNEL_LENTH                  (9)
+
+
+
+
 #define THRESHOLD_IN             							0
 #define THRESHOLD_OUT            							1
 
 
+#define ELE_INPUT                             0
+#define ELE_OUTPUT                            1
+
+
 #define Default_Consum_Max   (4000000000)
 #define Default_Voltage_Max  (1000000000)
 #define Default_Current_Max  (1000000000)
@@ -178,6 +213,49 @@
 
 #define THRESHOULD_JUDGMENT    		(50)
 
+
+
+
+
+/* relay controller */
+#define RL_STATUS                             (1 << 0)
+#define RL_COUNTER_END_FLAG            				(1 << 1)
+#define RL_COUNTER_BEGIN_FLAG         				(1 << 2)
+#define RL_ORDER_FLAG                  				(1 << 3)
+#define RL_ON_FLAG                     				(1 << 4)
+#define RL_OFF_FLAG                    				(1 << 5)
+#define RL_ON_DELAY_FLAG               				(1 << 6)
+#define RL_OFF_DELAY_FLAG              				(1 << 7)
+
+#define GET_RL_STATUS(reg)                       (reg & (RL_STATUS))    
+#define IS_RL_ORDER_FLAG_EN(reg)  						   (reg & RL_ORDER_FLAG)
+#define IS_RL_COUNTER_END_FLAG_EN(reg)					 (reg & RL_COUNTER_END_FLAG)
+#define IS_RL_COUNTER_BEGINE_FLAG_EN(reg)        (reg & RL_COUNTER_BEGIN_FLAG)
+#define IS_RL_ON_FLAG_EN(reg) 									 (reg & RL_ON_FLAG)
+#define IS_RL_OFF_FLAG_EN(reg) 									 (reg & RL_OFF_FLAG)
+#define IS_RL_ON_DELAY_FLAG_EN(reg) 						 (reg & RL_ON_DELAY_FLAG)
+#define IS_RL_OFF_DELAY_FLAG_EN(reg) 						 (reg & RL_OFF_DELAY_FLAG)
+
+
+#define SET_RL_ORDER_FLAG(reg)                   (reg |= RL_ORDER_FLAG)
+#define SET_RL_COUNTER_END_FLAG(reg)             (reg |= RL_COUNTER_END_FLAG)
+#define SET_RL_COUNTER_BEGIN_FLAG(reg)          (reg |= RL_COUNTER_BEGIN_FLAG )
+#define SET_RL_ON_FLAG(reg)                      (reg |= RL_ON_FLAG)
+#define SET_RL_OFF_FLAG(reg)                     (reg |= RL_OFF_FLAG)
+#define SET_RL_ON_DELAY_FLAG(reg)                (reg |= RL_ON_DELAY_FLAG)
+#define SET_RL_OFF_DELAY_FLAG(reg)               (reg |= RL_OFF_DELAY_FLAG)
+
+
+#define CLEAR_RL_ORDER_FLAG(reg)                     (reg &= (~(RL_ORDER_FLAG)))
+#define CLEAR_RL_COUNTER_END_FLAG(reg)               (reg &= (~(RL_COUNTER_END_FLAG)))
+#define CLEAR_RL_COUNTER_BEGIN_FLAG(reg)            (reg &= (~(RL_COUNTER_BEGIN_FLAG)))
+#define CLEAR_RL_ON_FLAG(reg)                        (reg &= (~(RL_ON_FLAG)))
+#define CLEAR_RL_OFF_FLAG(reg)                       (reg &= (~(RL_OFF_FLAG)))
+#define CLEAR_RL_ON_DELAY_FLAG(reg)                  (reg &= (~(RL_ON_DELAY_FLAG)))
+#define CLEAR_RL_OFF_DELAY_FLAG(reg)                 (reg &= (~(RL_OFF_DELAY_FLAG))) 
+
+
+
 #pragma pack (2)
 typedef struct {
 	uint32_t uniq_3;
@@ -200,6 +278,8 @@ typedef struct {
 	uint16_t resever;
 }elect_info_t;
 
+
+
 typedef struct{
 	elect_info_t info[3];
 }elect_3_info_t;
@@ -218,8 +298,6 @@ typedef struct{
 	uint32_t th_consumer_max;
 	uint32_t reserve1;
 	uint32_t reserve2;
-	uint32_t reserve3;
-	uint32_t reserve4;
 }threshold_t;
 
 
@@ -227,35 +305,43 @@ typedef struct{
 typedef struct {
 	uint16_t 						dev_chn;
 	board_info_t				b_info;
-	elect_info_t        ele_in[MAX_INPUT_CAHNNEL];
+	elect_3_info_t      ele_3_in;
 	elect_info_t        ele_out[MAX_CHANNEL];
-	//// todo
-	elect_3_info_t      ele_3_out[3];
-	////
 	uint16_t            detection;
 }r_data_t;
 
 
 
+
 typedef struct {
 	uint16_t            relay_status[MAX_CHANNEL];
-	uint16_t            combin_relay_status[3];
+	uint16_t            combin_relay_status[4];
 	uint16_t            zero_relay_status[3];
 	delay_t             delay_chn[MAX_CHANNEL];
-  delay_t             combin_chn[3];
+  delay_t             combin_chn[4];
+	delay_t             zero_chn[3];
 	threshold_t         th_in[MAX_INPUT_CAHNNEL];
 	threshold_t         th_out[MAX_CHANNEL];
-	//// todo
-	threshold_t         th_3_out[3];
-	////
+	threshold_t         th_combin_out[4];
 	uint16_t            over_fun_in[3];
 	uint16_t            over_func_out[MAX_CHANNEL];
-	uint16_t            combin_over_func[3];
+	uint16_t            combin_over_func[4];
 }rw_data_t;
 
+
+typedef union{
+	uint16_t data[START_R_LENTH];
+	r_data_t r_d;
+}mod_bus_r;
+
+typedef union{
+	uint16_t 	data[START_RW_LENTH];
+	rw_data_t rw_d;
+}mod_bus_rw;
+
 typedef struct {
-	r_data_t r_data;
-	rw_data_t rw_data;
+	mod_bus_r r_data;
+	mod_bus_rw rw_data;
 }mod_data_t;
 
 #pragma pack ()
@@ -291,11 +377,6 @@ typedef struct {
 
 typedef struct {
 	mod_data_t md_data;
-	uint8_t 	all_switch_stu;
-	uint8_t   all_switch_count;
-	#define 	ALL_IDLE     0
-	#define 	ALL_ON       1
-	#define 	ALL_OFF      2
 	uint8_t 	flag_1s;													
 	uint8_t   eeprom_write_flag;
 	uint8_t   jlink_flag;																				/* jugement jlink insert and programe process       */
@@ -305,17 +386,15 @@ typedef struct {
 	uint8_t   in_wanning_en[MAX_INPUT_CAHNNEL];
 	uint8_t   over_func[MAX_CHANNEL];
 	uint16_t  relay_staging_staus[MAX_CHANNEL];
-#if (POWER_TYPE == POWER_AC_3_3)
-	uint16_t  relay_combin_staging_status[3];
-#endif
-#if (ZERO_CONTRL != ZERO_LINE_CTRL_NO)
+	uint16_t  relay_combin_staging_status[4];
 	uint16_t  relay_zero_staging_status[3];
-#endif
+	uint16_t  relay_limit_counter[MAX_CHANNEL];
+	uint16_t  relay_zero_limit_counter[3];
+
 	uint8_t   haddr;
 	uint8_t   detection_1_value;
 	uint32_t  detection_1_count;
 	uint32_t  timer_count;
-	//eeprom_write_cache_t cache[16];
 	queue_t    q_cache;
 #if SURPPORT_2_PT
 	uint8_t   detection_2_value;
@@ -372,11 +451,13 @@ typedef struct {
 
 	void (*open)(uint8_t channel);
 	void (*close)(uint8_t channel);
+	void (*zero_open)(uint8_t channel);
+	void (*zero_close)(uint8_t channel);
 	void (*read_ele)(uint8_t channel);
 	void (*led_flash)();
 	void (*read_eeprom)(uint16_t addr,uint8_t *r_buff,uint16_t lenth);
 	void (*write_eeprom)(uint16_t addr,uint8_t *w_buff,uint16_t lenth);
-	void (*check_out_wanning)(uint8_t channel);
+	void (*check_wanning)(uint8_t in_out, uint8_t channel);
 	void (*detection)();
 	void (*opt_detection)();
 	void (*erase_consumer)();

+ 42 - 46
truing_control/PDU-AC/hardware/detection/detection.c

@@ -123,13 +123,8 @@ void EXTI4_15_IRQHandler(void){
 		{
 			if(gpio_input_bit_get(KEY_TEST_IO,KEY_TEST) != 0)
 			{
-				for(int i = 0; i < RelaySlaveChaNum;i++)
-				{
-					board->relay_staging_staus[i] = RELAY_CLOSE;
-				}
-				board->all_switch_stu = ALL_OFF;
-				board->timer_count = 0;
 				//todo write to eeprom cache
+				
 			}
 			exti_interrupt_flag_clear(KEY_RST_EXTI);
 		}
@@ -156,31 +151,7 @@ void EXTI2_3_IRQHandler(void)
 		{
 			if(gpio_input_bit_get(KEY_RST_IO,KEY_RST) != 0)
 			{
-#if (SURPPORT_2_PT)
-				uint8_t val = (RelaySlaveChaNum % 2) ? (RelaySlaveChaNum/2 + 1) : (RelaySlaveChaNum/2);
-				if(board->md_data.r_data.detection & 0X1)
-				{
-					for(int i = 0; i < val;i++)
-					{
-						board->relay_staging_staus[i] = RELAY_OPEN;
-					}
-				}
-				if(board->md_data.r_data.detection & 0X2)
-				{
-					for(int i = val; i < RelaySlaveChaNum;i++)
-					{
-						board->relay_staging_staus[i] = RELAY_OPEN;
-					}
-				}		
-#else	
-				for(int i = 0; i < RelaySlaveChaNum;i++)
-				{
-					board->relay_staging_staus[i] = RELAY_OPEN;
-				}
-#endif
-				board->all_switch_stu = ALL_ON;
-				board->timer_count = 0;
-				//todo  write to eeprom cache
+				
 			}
 			exti_interrupt_flag_clear(KEY_TEST_EXTI);
 		}
@@ -214,7 +185,7 @@ static void get_detection()
 			data  |= (1 << 1);
 		}		
 #endif
-		board->md_data.r_data.detection = data;
+		board->md_data.r_data.r_d.detection = data;
 	}
 }
 
@@ -223,8 +194,8 @@ static void detection_opt(void)
 	if(board)
 	{
 #if RELAY_REMENBER
-	#if SURPPORT_2_PT
-			if(board->md_data.r_data.detection & 0x1)
+	#if( SURPPORT_2_PT && (!SUPPORT_TWIN_FIRE))
+			if(board->md_data.r_data.r_d.detection & 0x1)
 			{
 				if(board->handle_input_pt[0] == 0)
 				{
@@ -233,9 +204,18 @@ static void detection_opt(void)
 					for(uint8_t k = 0; k < val;k++)
 					{
 						board->relay_staging_staus[k] = board->handle_status[k];
+						if(board->relay_staging_staus[k])
+						{
+							SET_RL_COUNTER_BEGIN_FLAG(board->relay_staging_staus[k]);
+							CLEAR_RL_COUNTER_END_FLAG(board->relay_staging_staus[k]);
+						}else
+						{
+							CLEAR_RL_COUNTER_BEGIN_FLAG(board->relay_staging_staus[k]);
+							SET_RL_COUNTER_END_FLAG(board->relay_staging_staus[k]);
+						}
+						SET_RL_ORDER_FLAG(board->relay_staging_staus[k]);
 					}
-					board->input_1_10ms_count = 0;
-					board->input_1_en = 1;
+					
 				}
 			}else
 			{
@@ -244,14 +224,16 @@ static void detection_opt(void)
 					uint8_t val = (RelaySlaveChaNum % 2) ? (RelaySlaveChaNum / 2 + 1) : (RelaySlaveChaNum/2);
 					for(uint8_t k = 0; k < val;k++)
 					{
-						board->handle_status[k] = board->md_data.rw_data.relay_status[k];
+						board->handle_status[k] = board->md_data.rw_data.rw_d.relay_status[k];
 						board->relay_staging_staus[k] = RELAY_CLOSE;
-						board->close(k);
+						CLEAR_RL_COUNTER_BEGIN_FLAG(board->relay_staging_staus[k]);
+						SET_RL_COUNTER_END_FLAG(board->relay_staging_staus[k]);
+						SET_RL_ORDER_FLAG(board->relay_staging_staus[k]);
 					}
 					board->handle_input_pt[0] = 0;
 				}
 			}
-			if(board->md_data.r_data.detection & 0x2)
+			if(board->md_data.r_data.r_d.detection & 0x2)
 			{
 				if(board->handle_input_pt[1] == 0)
 				{
@@ -260,9 +242,17 @@ static void detection_opt(void)
 					for(uint8_t k = val; k < RelaySlaveChaNum;k++)
 					{
 						board->relay_staging_staus[k] = board->handle_status[k];
+						if(board->relay_staging_staus[k])
+						{
+							SET_RL_COUNTER_BEGIN_FLAG(board->relay_staging_staus[k]);
+							CLEAR_RL_COUNTER_END_FLAG(board->relay_staging_staus[k]);
+						}else
+						{
+							CLEAR_RL_COUNTER_BEGIN_FLAG(board->relay_staging_staus[k]);
+							SET_RL_COUNTER_END_FLAG(board->relay_staging_staus[k]);
+						}
+						SET_RL_ORDER_FLAG(board->relay_staging_staus[k]);
 					}
-					board->input_2_10ms_count = 0;
-					board->input_2_en = 1;
 				}
 			}else
 			{
@@ -271,18 +261,24 @@ static void detection_opt(void)
 					uint8_t val = (RelaySlaveChaNum % 2) ? (RelaySlaveChaNum / 2 + 1) : (RelaySlaveChaNum/2);
 					for(uint8_t k = val; k < RelaySlaveChaNum;k++)
 					{
-						board->handle_status[k] = board->md_data.rw_data.relay_status[k];
+						board->handle_status[k] = board->md_data.rw_data.rw_d.relay_status[k];
 						board->relay_staging_staus[k] = RELAY_CLOSE;
-						board->close(k);
+						CLEAR_RL_COUNTER_BEGIN_FLAG(board->relay_staging_staus[k]);
+						SET_RL_COUNTER_END_FLAG(board->relay_staging_staus[k]);
+						SET_RL_ORDER_FLAG(board->relay_staging_staus[k]);					
 					}
 					board->handle_input_pt[1] = 0;
 				}
 			}		
-	#else
-			
+	#elif SUPPORT_TWIN_FIRE
+			//todo
+//			if(board->md_data.r_data.r_d.detection & 0x3)
+//			{
+//			
+//			}
 	#endif
 #else
-		
+		//todo
 		
 #endif
 	}

+ 20 - 20
truing_control/PDU-AC/hardware/eeprom/eeprom.c

@@ -332,32 +332,32 @@ static void check_threshold(uint8_t in_out,uint8_t channel)
 		board_t *board = get_board();
 		if(channel < 3)
 		{
-			if(board->md_data.rw_data.th_in[channel].th_voltage_max > Default_Voltage_Max) board->md_data.rw_data.th_in[channel].th_voltage_max  = 0;
-			if(board->md_data.rw_data.th_in[channel].th_voltage_min > Default_Voltage_Max) board->md_data.rw_data.th_in[channel].th_voltage_min  = 0;
-			if(board->md_data.rw_data.th_in[channel].th_current_max > Default_Current_Max) board->md_data.rw_data.th_in[channel].th_current_max  = 0;
-			if(board->md_data.rw_data.th_in[channel].th_power_max > Default_Power_Max)     board->md_data.rw_data.th_in[channel].th_power_max    = 0;
-			if(board->md_data.rw_data.th_in[channel].th_consumer_max > Default_Consum_Max) board->md_data.rw_data.th_in[channel].th_consumer_max = 0;
+			if(board->md_data.rw_data.rw_d.th_in[channel].th_voltage_max > Default_Voltage_Max) board->md_data.rw_data.rw_d.th_in[channel].th_voltage_max  = 0;
+			if(board->md_data.rw_data.rw_d.th_in[channel].th_voltage_min > Default_Voltage_Max) board->md_data.rw_data.rw_d.th_in[channel].th_voltage_min  = 0;
+			if(board->md_data.rw_data.rw_d.th_in[channel].th_current_max > Default_Current_Max) board->md_data.rw_data.rw_d.th_in[channel].th_current_max  = 0;
+			if(board->md_data.rw_data.rw_d.th_in[channel].th_power_max > Default_Power_Max)     board->md_data.rw_data.rw_d.th_in[channel].th_power_max    = 0;
+			if(board->md_data.rw_data.rw_d.th_in[channel].th_consumer_max > Default_Consum_Max) board->md_data.rw_data.rw_d.th_in[channel].th_consumer_max = 0;
 			
-			if(board->md_data.rw_data.th_in[channel].th_voltage_max <= THRESHOULD_JUDGMENT) 
+			if(board->md_data.rw_data.rw_d.th_in[channel].th_voltage_max <= THRESHOULD_JUDGMENT) 
 				UNSET_VOLTAGE_MAX_EN(board->in_wanning_en[channel]);
 			else 
 				SET_VOLTAGE_MAX_EN(board->in_wanning_en[channel]);
-			if(board->md_data.rw_data.th_in[channel].th_voltage_min <= THRESHOULD_JUDGMENT) 
+			if(board->md_data.rw_data.rw_d.th_in[channel].th_voltage_min <= THRESHOULD_JUDGMENT) 
 				UNSET_VOLTAGE_MIN_EN(board->in_wanning_en[channel]);
 			else 
 				SET_VOLTAGE_MIN_EN(board->in_wanning_en[channel]);
 			
-			if(board->md_data.rw_data.th_in[channel].th_current_max <= THRESHOULD_JUDGMENT) 
+			if(board->md_data.rw_data.rw_d.th_in[channel].th_current_max <= THRESHOULD_JUDGMENT) 
 				UNSET_CURRENT_MAX_EN(board->in_wanning_en[channel]);
 			else 
 				SET_CURRENT_MAX_EN(board->in_wanning_en[channel]);
 			
-			if(board->md_data.rw_data.th_in[channel].th_power_max <= THRESHOULD_JUDGMENT) 
+			if(board->md_data.rw_data.rw_d.th_in[channel].th_power_max <= THRESHOULD_JUDGMENT) 
 				UNSET_POWER_MAX_EN(board->in_wanning_en[channel]);
 			else 
 				SET_POWER_MAX_EN(board->in_wanning_en[channel]);
 			
-			if(board->md_data.rw_data.th_in[channel].th_consumer_max <= THRESHOULD_JUDGMENT) 
+			if(board->md_data.rw_data.rw_d.th_in[channel].th_consumer_max <= THRESHOULD_JUDGMENT) 
 				UNSET_CONSUMER_MAX_EN(board->in_wanning_en[channel]);
 			else 
 				SET_CONSUMER_MAX_EN(board->in_wanning_en[channel]);			
@@ -367,32 +367,32 @@ static void check_threshold(uint8_t in_out,uint8_t channel)
 		board_t *board = get_board();
 		if(channel < RelaySlaveChaNum)
 		{
-			if(board->md_data.rw_data.th_out[channel].th_voltage_max > Default_Voltage_Max) board->md_data.rw_data.th_out[channel].th_voltage_max  = 0;
-			if(board->md_data.rw_data.th_out[channel].th_voltage_min > Default_Voltage_Max) board->md_data.rw_data.th_out[channel].th_voltage_min  = 0;
-			if(board->md_data.rw_data.th_out[channel].th_current_max > Default_Current_Max) board->md_data.rw_data.th_out[channel].th_current_max  = 0;
-			if(board->md_data.rw_data.th_out[channel].th_power_max > Default_Power_Max)     board->md_data.rw_data.th_out[channel].th_power_max    = 0;
-			if(board->md_data.rw_data.th_out[channel].th_consumer_max > Default_Consum_Max) board->md_data.rw_data.th_out[channel].th_consumer_max = 0;
+			if(board->md_data.rw_data.rw_d.th_out[channel].th_voltage_max > Default_Voltage_Max) board->md_data.rw_data.rw_d.th_out[channel].th_voltage_max  = 0;
+			if(board->md_data.rw_data.rw_d.th_out[channel].th_voltage_min > Default_Voltage_Max) board->md_data.rw_data.rw_d.th_out[channel].th_voltage_min  = 0;
+			if(board->md_data.rw_data.rw_d.th_out[channel].th_current_max > Default_Current_Max) board->md_data.rw_data.rw_d.th_out[channel].th_current_max  = 0;
+			if(board->md_data.rw_data.rw_d.th_out[channel].th_power_max > Default_Power_Max)     board->md_data.rw_data.rw_d.th_out[channel].th_power_max    = 0;
+			if(board->md_data.rw_data.rw_d.th_out[channel].th_consumer_max > Default_Consum_Max) board->md_data.rw_data.rw_d.th_out[channel].th_consumer_max = 0;
 			
-			if(board->md_data.rw_data.th_out[channel].th_voltage_max <= THRESHOULD_JUDGMENT) 
+			if(board->md_data.rw_data.rw_d.th_out[channel].th_voltage_max <= THRESHOULD_JUDGMENT) 
 				UNSET_VOLTAGE_MAX_EN(board->out_wanning_en[channel]);
 			else 
 				SET_VOLTAGE_MAX_EN(board->in_wanning_en[channel]);
-			if(board->md_data.rw_data.th_out[channel].th_voltage_min <= THRESHOULD_JUDGMENT) 
+			if(board->md_data.rw_data.rw_d.th_out[channel].th_voltage_min <= THRESHOULD_JUDGMENT) 
 				UNSET_VOLTAGE_MIN_EN(board->out_wanning_en[channel]);
 			else 
 				SET_VOLTAGE_MIN_EN(board->out_wanning_en[channel]);
 			
-			if(board->md_data.rw_data.th_out[channel].th_current_max <= THRESHOULD_JUDGMENT) 
+			if(board->md_data.rw_data.rw_d.th_out[channel].th_current_max <= THRESHOULD_JUDGMENT) 
 				UNSET_CURRENT_MAX_EN(board->out_wanning_en[channel]);
 			else 
 				SET_CURRENT_MAX_EN(board->out_wanning_en[channel]);
 			
-			if(board->md_data.rw_data.th_out[channel].th_power_max <= THRESHOULD_JUDGMENT) 
+			if(board->md_data.rw_data.rw_d.th_out[channel].th_power_max <= THRESHOULD_JUDGMENT) 
 				UNSET_POWER_MAX_EN(board->out_wanning_en[channel]);
 			else 
 				SET_POWER_MAX_EN(board->out_wanning_en[channel]);
 			
-			if(board->md_data.rw_data.th_out[channel].th_consumer_max <= THRESHOULD_JUDGMENT) 
+			if(board->md_data.rw_data.rw_d.th_out[channel].th_consumer_max <= THRESHOULD_JUDGMENT) 
 				UNSET_CONSUMER_MAX_EN(board->out_wanning_en[channel]);
 			else 
 				SET_CONSUMER_MAX_EN(board->out_wanning_en[channel]);				

+ 46 - 16
truing_control/PDU-AC/hardware/relay/relay.c

@@ -95,6 +95,8 @@
 static void relay_open(uint8_t channel);
 static void relay_close(uint8_t channel);
 static void relay_sync(void);
+static void relay_zero_open(uint8_t channel);
+static void relay_zero_close(uint8_t channel);
 
 
 void relay_init(void)
@@ -149,16 +151,14 @@ void relay_init(void)
 	
 	board->open = relay_open;
 	board->close = relay_close;
-	board->relay_sync = relay_sync;
+	board->zero_close = relay_zero_close;
+	board->zero_open = relay_zero_open;
+	//board->relay_sync = relay_sync;
 }
 
 static void relay_open(uint8_t channel)
 {
 	board_t * board = get_board();
-	if(channel >= RelaySlaveChaNum)
-		return;
-	if(board->relay_staging_staus[channel] == RELAY_OPEN && (board->md_data.rw_data.relay_status[channel] != RELAY_OPEN))
-	{
 		switch(channel)
 		{
 	#if (RelaySlaveChaNum >= 1)
@@ -203,22 +203,16 @@ static void relay_open(uint8_t channel)
 	#endif
 
 			default:
-				break;
+				return;
 		}
-		board->md_data.rw_data.relay_status[channel] = RELAY_OPEN;
 		board->unlock();
 		board->lock();
-	}
+		board->md_data.rw_data.rw_d.relay_status[channel] = RELAY_OPEN;
 }
 
 static void relay_close(uint8_t channel)
 {
 	board_t * board = get_board();
-	if(channel >= RelaySlaveChaNum)
-		return;
-
-	if((board->relay_staging_staus[channel] == RELAY_CLOSE) && (board->md_data.rw_data.relay_status[channel] != RELAY_CLOSE))
-	{
 		switch(channel)
 		{
 	#if (RelaySlaveChaNum >= 1)
@@ -263,12 +257,11 @@ static void relay_close(uint8_t channel)
 				break;
 	#endif
 			default:
-				break;
+				return;
 		}
-		board->md_data.rw_data.relay_status[channel] = RELAY_CLOSE;
 		board->unlock();
 		board->lock();
-	}
+		board->md_data.rw_data.rw_d.relay_status[channel] = RELAY_CLOSE;
 }
 
 static void relay_sync(void)
@@ -288,3 +281,40 @@ static void relay_sync(void)
 		}
 	}
 }
+
+static void relay_zero_open(uint8_t channel)
+{
+	board_t * board = get_board();
+	if(channel >= ZERO_CTRL_NUM)
+		return;
+	switch(channel)
+	{
+	#if (ZERO_CTRL_NUM >= 1)
+		case 0:
+		RELAY_4_ON;
+		break;
+	#endif
+		default:
+			return;
+	}
+	board->unlock();
+	board->lock();
+	board->md_data.rw_data.rw_d.zero_relay_status[channel] = RELAY_OPEN;
+}
+static void relay_zero_close(uint8_t channel)
+{
+	board_t * board = get_board();
+	switch(channel)
+	{
+	#if (ZERO_CTRL_NUM >= 1)
+		case 0:
+		RELAY_4_OFF;
+		break;
+	#endif
+		default:
+			return;
+	}
+	board->unlock();
+	board->lock();
+	board->md_data.rw_data.rw_d.zero_relay_status[channel] = RELAY_CLOSE;
+}

+ 37 - 91
truing_control/PDU-AC/hardware/timer/timer.c

@@ -19,6 +19,11 @@ static void relay_remember(void);
 
 static  uint16_t count_1s = 0;
 static  uint16_t count_3s = 0;
+
+static uint16_t rl_delay_cnt[RelaySlaveChaNum] = {0};
+static uint16_t rl_delay_zero_cnt[ZERO_CTRL_NUM] = {0};
+
+
 void time_init(void)
 {
 	timer14_config(9999,71);
@@ -60,13 +65,43 @@ void TIMER14_IRQHandler(void)
 			board->detection_1_count = 0;
 		}
 #if SURPPORT_2_PT
+		board->detection_2_count ++;
 		if(board->detection_2_count >= 100)
 		{
 			board->detection_2_value  = 0;
 			 board->detection_2_count = 0;		
-		}		
-		
+		}			
 #endif
+		for(int i = 0 ; i < RelaySlaveChaNum;i++)
+		{
+			if(IS_RL_COUNTER_BEGINE_FLAG_EN(board->relay_staging_staus[i]))
+			{
+				if(rl_delay_cnt[i] < board->relay_limit_counter[i])
+				{
+					rl_delay_cnt[i]++;
+				}else
+				{
+					rl_delay_cnt[i] = 0;
+					CLEAR_RL_COUNTER_BEGIN_FLAG(board->relay_staging_staus[i]);
+					SET_RL_COUNTER_END_FLAG(board->relay_staging_staus[i]);
+				}
+			}
+		}
+		for(int i = 0 ; i < ZERO_CTRL_NUM;i++)
+		{
+			if(IS_RL_COUNTER_BEGINE_FLAG_EN(board->relay_zero_staging_status[i]))
+			{
+				if(rl_delay_zero_cnt[i] < board->relay_limit_counter[i])
+				{
+					rl_delay_zero_cnt[i]++;
+				}else
+				{
+					rl_delay_zero_cnt[i] = 0;
+					CLEAR_RL_COUNTER_BEGIN_FLAG(board->relay_zero_staging_status[i]);
+					SET_RL_COUNTER_END_FLAG(board->relay_zero_staging_status[i]);
+				}
+			}
+		}		
 		
 		if(count_1s == 100)
 		{
@@ -79,97 +114,8 @@ void TIMER14_IRQHandler(void)
 				count_3s = 0;
 			}
 		}
-		
-		if(board->all_switch_stu == ALL_OFF)
-		{
-			board->timer_count++;
-			for(int i = 0; i < RelaySlaveChaNum;i++)
-			{
-				if(board->md_data.rw_data.delay_chn[i].delay_close == board->timer_count 
-					|| board->md_data.rw_data.delay_chn[i].delay_close == 0 
-					|| board->md_data.rw_data.delay_chn[i].delay_close == 0XFFFF)
-				{
-					board->close(i);
-					board->all_switch_count ++;
-				}
-			}
-			if(board->all_switch_count == RelaySlaveChaNum)
-			{
-				board->all_switch_stu == ALL_IDLE;
-				board->all_switch_count = 0;
-			}
-		}else if(board->all_switch_stu == ALL_ON)
-		{
-			board->timer_count++;
-			for(int i = 0; i < RelaySlaveChaNum;i++)
-			{
-				if(board->md_data.rw_data.delay_chn[i].delay_open == board->timer_count 
-					|| board->md_data.rw_data.delay_chn[i].delay_open == 0 
-					|| board->md_data.rw_data.delay_chn[i].delay_open == 0XFFFF)
-				{
-					board->open(i);
-					board->all_switch_count ++;
-				}			
-			}		
-			if(board->all_switch_count == RelaySlaveChaNum)
-			{
-				board->all_switch_stu == ALL_IDLE;
-				board->all_switch_count = 0;
-			}				
-		}	
 	}
 	
-#if (SURPPORT_2_PT && RELAY_REMENBER)
-		relay_remember();
-#endif
 }
 
 
-#if (SURPPORT_2_PT && RELAY_REMENBER)
-
-static void relay_remember(void)
-{
-	if(board)
-	{
-		if(board->input_1_en == 1)
-		{
-			board->input_1_10ms_count ++;
-			for(int i = 0; i < RelaySlaveChaNum / 2;i++)
-			{
-				if(board->md_data.rw_data.delay_chn[i].delay_open == board->input_1_10ms_count 
-					|| board->md_data.rw_data.delay_chn[i].delay_open == 0 
-					|| board->md_data.rw_data.delay_chn[i].delay_open == 0XFFFF)	
-				{
-					board->open(i);
-					board->count1++;
-				}				
-			}
-			if(board->count1 == RelaySlaveChaNum / 2)
-			{
-				board->input_1_en = 0;
-				board->input_1_10ms_count = 0;
-			}
-		}
-		if(board->input_2_en == 1)
-		{
-			board->input_2_10ms_count ++;
-			for(int i = RelaySlaveChaNum / 2; i < RelaySlaveChaNum;i++)
-			{
-				if(board->md_data.rw_data.delay_chn[i].delay_open == board->input_2_10ms_count 
-					|| board->md_data.rw_data.delay_chn[i].delay_open == 0 
-					|| board->md_data.rw_data.delay_chn[i].delay_open == 0XFFFF)	
-				{
-					board->open(i);
-					board->count2++;
-				}				
-			}
-			if(board->count2 == (RelaySlaveChaNum / 2))
-			{
-				board->input_2_en = 0;
-				board->input_2_10ms_count = 0;
-			}
-		}		
-	}
-}
-
-#endif

+ 8 - 7
truing_control/PDU-AC/modbus/BARE/port/port.c

@@ -34,7 +34,7 @@
 #define REG_INPUT_NREGS  1
 
 //保持寄存器
-#define REG_HOLD_START   START_REGISTER
+#define REG_HOLD_START   START_R_REGISTER
 #define REG_HOLD_NREGS   700
 
 //线圈
@@ -127,6 +127,8 @@ uint8_t cmd_cnt = 0;
 //extern information_t infomation;
 
 
+#define  AC_1_STATUS 0
+#define  AC_9_STATUS 8
 
 eMBErrorCode
 eMBRegHoldingCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs, eMBRegisterMode eMode )
@@ -144,12 +146,12 @@ eMBRegHoldingCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs, eMBRegi
         {
 					case MB_REG_READ://读寄存器
 					{
-						 if(usAddress >= REG_HOLD_START && usAddress <= (REG_HOLD_START+ (sizeof(mod_data_t)/2)))
+						 if(usAddress >= REG_HOLD_START && usAddress < START_W_REGISTER)
 						 {
 							 T_cnt = usAddress - REG_HOLD_START;
-							 if((sizeof(mod_data_t) / 2 - T_cnt) < usNRegs)
+							 if((START_W_REGISTER - T_cnt) < usNRegs)
 							 {
-								 usNRegs = (sizeof(mod_data_t) / 2 - T_cnt);
+								 usNRegs = (START_W_REGISTER - T_cnt);
 							 }
 							 memcpy(&usRegHoldBuf[iRegIndex],(void *)(&(board->md_data) + T_cnt),usNRegs * 2);
 						 }else
@@ -177,7 +179,7 @@ eMBRegHoldingCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs, eMBRegi
 							usNRegs--;
 						}
 						{
-							if(usAddress >= START_RW_REGISTER && usAddress <= (REG_HOLD_START+ (sizeof(mod_data_t)/2)))
+							if(usAddress >= START_RW_REGISTER && usAddress < START_W_REGISTER)
 							{
 								T_cnt = usAddress - START_RW_REGISTER;
 
@@ -202,8 +204,7 @@ eMBRegHoldingCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs, eMBRegi
 									break;
 									default:
 									{
-										memcpy((uint8_t *)(&board->md_data.rw_data.delay_chn[0]+T_cnt),usRegHoldBuf[iRegIndex],WusNRegs * 2);
-										
+										memcpy((uint8_t *)(&board->md_data.rw_data.rw_d.delay_chn[0]+T_cnt),usRegHoldBuf[iRegIndex],WusNRegs * 2);
 									}
 										break;
 

+ 9 - 4
truing_control/PDU-AC/user/board_cfg.h

@@ -15,8 +15,9 @@
 
 #define  POWER_DC           0
 #define  POWER_AC           1
-#define  POWER_AC_3_3       2
-#define  POWER_AC_3_1       3
+#define  POWER_AC_3_3       4
+#define  POWER_AC_3_1       2
+#define  POWER_AC_3_2       3
 
 
 #define  INPUT_PT_NONE      0			/* detect module count */
@@ -39,7 +40,12 @@
 
 
 
-#define DEIVECE(va1,va2,va3,va4,va5) ((va1 << 6)|(va2 << 4)|(va3<< 3)|(va4 << 1)|(va5 << 0))
+#define DEIVECE(elec_type,input_pt,ctrl_zero_flag,zero_count,ctrl_output_flag,relay_count) ((elec_type        << 12)\
+																																													 |(input_pt         << 10)\
+																																													 |(ctrl_zero_flag   << 9)\
+																																													 |(zero_count       << 7)\
+																																													 |(ctrl_output_flag << 6)\
+																																													 |relay_count)
 
 
 #define  	PRJ_4_BASE                0
@@ -100,7 +106,6 @@
 	#define   ZERO_CONTRL               (ZERO_LINE_CTRL_NO)
 	#define   ZERO_CTRL_NUM             (ZERO_LINE_NONE)
 	#define   OUTPUT_CONTRL             (OUTPUT_CTRL_YES)
-	#define   DEVICE_TYPE               DEIVECE(POWER_TYPE,INPUT_PT_NUM,ZERO_CONTRL,ZERO_CTRL_NUM,OUTPUT_CONTRL)
 	#define 	RelaySlaveChaNum 					8
 	#define 	RELAY_REMENBER						1
 	#define   SURPPORT_2_PT             1

+ 227 - 7
truing_control/PDU-AC/user/main.c

@@ -31,6 +31,9 @@ static void task_1s(void);
 
 
 
+static void relay_ctrl(void);
+
+
 
 
 int main(){
@@ -46,19 +49,23 @@ int main(){
 	time_init();
 	electricity_init();
 	query_init();
-	
 	eMBInit(MB_RTU, ac_board.haddr, 0, 115200, MB_PAR_NONE);
 	eMBEnable();
+	//device
+	ac_board.md_data.r_data.r_d.dev_chn = DEIVECE(POWER_TYPE,INPUT_PT_NUM,ZERO_CONTRL,ZERO_CTRL_NUM,OUTPUT_CONTRL,RelaySlaveChaNum);
+	//
+	
 	read_config_from_eeprom();
 	
-	strcpy(&(ac_board.md_data.r_data.b_info.date),__DATE__);
-	strcat(&(ac_board.md_data.r_data.b_info.date)," ");
-	strcat(&(ac_board.md_data.r_data.b_info.date),__TIME__);
-	strcpy(&(ac_board.md_data.r_data.b_info.version),VERSION);
+	strcpy(&(ac_board.md_data.r_data.r_d.b_info.date),__DATE__);
+	strcat(&(ac_board.md_data.r_data.r_d.b_info.date)," ");
+	strcat(&(ac_board.md_data.r_data.r_d.b_info.date),__TIME__);
+	strcpy(&(ac_board.md_data.r_data.r_d.b_info.version),VERSION);
 	
-	flash_get_infomation(&ac_board.md_data.r_data.b_info);
+	flash_get_infomation(&ac_board.md_data.r_data.r_d.b_info);
 	while(1)
 	{
+		relay_ctrl();
 		task_query();
 		task_1s();
 		eMBPoll();
@@ -87,11 +94,224 @@ static void task_1s(void)
 			ac_board.led_flash();
 			ac_board.detection();
 			ac_board.read_ele(channel);
-			ac_board.check_out_wanning(channel);
+			ac_board.check_wanning(ELE_OUTPUT,channel);
 			channel++;
 			if(channel == RelaySlaveChaNum)
 			{
+				//check input wanning
+		//calculate input
+#if (POWER_TYPE == POWER_AC_3_3)
+		for(int i = 0 ;i < 3;i++)
+		{
+			uint32_t data_voltage = 0;
+			uint32_t data_current = 0;
+			uint32_t data_power = 0;
+			uint32_t data_consumer = 0;
+			for(int j =i;j < RelaySlaveChaNum;i+=3)
+			{
+				data_voltage = ac_board.md_data.r_data.r_d.ele_out[j].voltage > data_voltage ? ac_board.md_data.r_data.r_d.ele_out[j].voltage : data_voltage;
+				data_current += ac_board.md_data.r_data.r_d.ele_out[j].current;
+				data_consumer += ac_board.md_data.r_data.r_d.ele_out[j].consumer;
+				data_power += ac_board.md_data.r_data.r_d.ele_out[j].power;
+			}
+			ac_board.md_data.r_data.r_d.ele_3_in.info[i].voltage = data_voltage;
+			ac_board.md_data.r_data.r_d.ele_3_in.info[i].current = data_current;
+			ac_board.md_data.r_data.r_d.ele_3_in.info[i].power = data_power;
+			ac_board.md_data.r_data.r_d.ele_3_in.info[i].consumer = data_consumer;		
+			ac_board.md_data.r_data.r_d.ele_3_in.info[i].resever = ac_board.md_data.r_data.r_d.ele_out[i*=3].resever;
+			ac_board.check_wanning(ELE_INPUT,i);
+		}
+
+#else
+		uint8_t avi =  (RelaySlaveChaNum % INPUT_PT_NUM) ? (RelaySlaveChaNum / INPUT_PT_NUM + 1) : (RelaySlaveChaNum / INPUT_PT_NUM );
+		uint32_t data_voltage = 0;
+	  uint32_t data_current = 0;
+		uint32_t data_power = 0;
+		uint32_t data_consumer = 0;
+		if(avi == RelaySlaveChaNum)
+		{
+			for(int i = 0 ; i < avi;i++)
+			{
+				data_voltage = ac_board.md_data.r_data.r_d.ele_out[i].voltage > data_voltage ? ac_board.md_data.r_data.r_d.ele_out[i].voltage : data_voltage;
+				data_current += ac_board.md_data.r_data.r_d.ele_out[i].current;
+				data_consumer += ac_board.md_data.r_data.r_d.ele_out[i].consumer;
+				data_power += ac_board.md_data.r_data.r_d.ele_out[i].power;
+			}
+			ac_board.md_data.r_data.r_d.ele_3_in.info[0].voltage = data_voltage;
+			ac_board.md_data.r_data.r_d.ele_3_in.info[0].current = data_current;
+			ac_board.md_data.r_data.r_d.ele_3_in.info[0].power = data_power;
+			ac_board.md_data.r_data.r_d.ele_3_in.info[0].consumer = data_consumer;
+			ac_board.md_data.r_data.r_d.ele_3_in.info[0].resever = ac_board.md_data.r_data.r_d.ele_out[0].resever;
+			//check input wanning
+			ac_board.check_wanning(ELE_INPUT,0);
+		}else
+		{
+			for(int i = 0 ; i < avi;i++)
+			{
+				data_voltage = ac_board.md_data.r_data.r_d.ele_out[i].voltage > data_voltage ? ac_board.md_data.r_data.r_d.ele_out[i].voltage : data_voltage;
+				data_current += ac_board.md_data.r_data.r_d.ele_out[i].current;
+				data_consumer += ac_board.md_data.r_data.r_d.ele_out[i].consumer;
+				data_power += ac_board.md_data.r_data.r_d.ele_out[i].power;				
+			}
+			
+			ac_board.md_data.r_data.r_d.ele_3_in.info[0].voltage = data_voltage;
+			ac_board.md_data.r_data.r_d.ele_3_in.info[0].current = data_current;
+			ac_board.md_data.r_data.r_d.ele_3_in.info[0].power = data_power;
+			ac_board.md_data.r_data.r_d.ele_3_in.info[0].consumer = data_consumer;
+			ac_board.md_data.r_data.r_d.ele_3_in.info[0].resever = ac_board.md_data.r_data.r_d.ele_out[0].resever;
+			//check input wanning
+			ac_board.check_wanning(ELE_INPUT,0);
+			data_voltage = data_current = data_power = data_consumer =0;
+			for(int i = avi ; i < RelaySlaveChaNum;i++)
+			{
+				data_voltage = ac_board.md_data.r_data.r_d.ele_out[i].voltage > data_voltage ? ac_board.md_data.r_data.r_d.ele_out[i].voltage : data_voltage;
+				data_current += ac_board.md_data.r_data.r_d.ele_out[i].current;
+				data_consumer += ac_board.md_data.r_data.r_d.ele_out[i].consumer;
+				data_power += ac_board.md_data.r_data.r_d.ele_out[i].power;				
+			}	
+			ac_board.md_data.r_data.r_d.ele_3_in.info[1].voltage = data_voltage;
+			ac_board.md_data.r_data.r_d.ele_3_in.info[1].current = data_current;
+			ac_board.md_data.r_data.r_d.ele_3_in.info[1].power = data_power;
+			ac_board.md_data.r_data.r_d.ele_3_in.info[1].consumer = data_consumer;	
+			ac_board.md_data.r_data.r_d.ele_3_in.info[1].resever = ac_board.md_data.r_data.r_d.ele_out[avi].resever;				//phase infomation
+			//check input wanning
+			ac_board.check_wanning(ELE_INPUT,1);
+		}
+#endif
 				channel = 0;
 			}
 	}
+}
+
+
+static void relay_ctrl(void)
+{
+	for(int i = 0; i < RelaySlaveChaNum;i++)
+	{
+		if(IS_RL_ORDER_FLAG_EN(ac_board.relay_staging_staus[i]))
+		{
+			uint8_t rl_old_state = GET_RL_STATUS(ac_board.md_data.rw_data.rw_d.relay_status[i]);
+			uint8_t rl_now_state = GET_RL_STATUS(ac_board.relay_staging_staus[i]);
+			if(rl_now_state > rl_old_state)
+			{
+				SET_RL_ON_FLAG(ac_board.relay_staging_staus[i]);
+				CLEAR_RL_OFF_FLAG(ac_board.relay_staging_staus[i]);
+				if(IS_RL_ON_DELAY_FLAG_EN(ac_board.relay_staging_staus[i]))
+				{
+					ac_board.relay_limit_counter[i] = ac_board.md_data.rw_data.rw_d.delay_chn[i].delay_open;
+					CLEAR_RL_COUNTER_END_FLAG(ac_board.relay_staging_staus[i]);
+					SET_RL_COUNTER_BEGIN_FLAG(ac_board.relay_staging_staus[i]);
+				}else
+				{
+					ac_board.relay_limit_counter[i] = 0;
+					SET_RL_COUNTER_END_FLAG(ac_board.relay_staging_staus[i]);
+					CLEAR_RL_COUNTER_BEGIN_FLAG(ac_board.relay_staging_staus[i]);
+				}
+				
+			}else if (rl_now_state < rl_old_state)
+			{
+				CLEAR_RL_ON_FLAG(ac_board.relay_staging_staus[i]);
+				SET_RL_OFF_FLAG(ac_board.relay_staging_staus[i]);
+				if(IS_RL_OFF_DELAY_FLAG_EN(ac_board.relay_staging_staus[i]))
+				{
+					ac_board.relay_limit_counter[i] = ac_board.md_data.rw_data.rw_d.delay_chn[i].delay_close;
+					CLEAR_RL_COUNTER_END_FLAG(ac_board.relay_staging_staus[i]);
+					SET_RL_COUNTER_BEGIN_FLAG(ac_board.relay_staging_staus[i]);
+				}else
+				{
+					ac_board.relay_limit_counter[i] = 0;
+					SET_RL_COUNTER_END_FLAG(ac_board.relay_staging_staus[i]);
+					CLEAR_RL_COUNTER_BEGIN_FLAG(ac_board.relay_staging_staus[i]);
+				}
+			}else{
+					ac_board.relay_limit_counter[i] = 0;
+					CLEAR_RL_COUNTER_END_FLAG(ac_board.relay_staging_staus[i]);
+					CLEAR_RL_COUNTER_BEGIN_FLAG(ac_board.relay_staging_staus[i]);
+					CLEAR_RL_ON_FLAG(ac_board.relay_staging_staus[i]);				
+				  CLEAR_RL_OFF_FLAG(ac_board.relay_staging_staus[i]);
+			}
+			CLEAR_RL_ORDER_FLAG(ac_board.relay_staging_staus[i]);
+		}
+	}
+	for(int i = 0; i < ZERO_CTRL_NUM;i++)
+	{
+		if(IS_RL_ORDER_FLAG_EN(ac_board.relay_zero_staging_status[i]))
+		{
+			uint8_t rl_old_state = GET_RL_STATUS(ac_board.md_data.rw_data.rw_d.zero_relay_status[i]);
+			uint8_t rl_now_state = GET_RL_STATUS(ac_board.relay_zero_staging_status[i]);
+			if(rl_now_state > rl_old_state)
+			{
+				SET_RL_ON_FLAG(ac_board.relay_zero_staging_status[i]);
+				CLEAR_RL_OFF_FLAG(ac_board.relay_zero_staging_status[i]);
+				if(IS_RL_ON_DELAY_FLAG_EN(ac_board.relay_zero_staging_status[i]))
+				{
+					ac_board.relay_zero_limit_counter[i] = ac_board.md_data.rw_data.rw_d.zero_chn[i].delay_open;
+					CLEAR_RL_COUNTER_END_FLAG(ac_board.relay_zero_staging_status[i]);
+					SET_RL_COUNTER_BEGIN_FLAG(ac_board.relay_zero_staging_status[i]);
+				}else
+				{
+					ac_board.relay_zero_limit_counter[i] = 0;
+					SET_RL_COUNTER_END_FLAG(ac_board.relay_zero_staging_status[i]);
+					CLEAR_RL_COUNTER_BEGIN_FLAG(ac_board.relay_zero_staging_status[i]);
+				}
+				
+			}else if (rl_now_state < rl_old_state)
+			{
+				CLEAR_RL_ON_FLAG(ac_board.relay_zero_staging_status[i]);
+				SET_RL_OFF_FLAG(ac_board.relay_zero_staging_status[i]);
+				if(IS_RL_OFF_DELAY_FLAG_EN(ac_board.relay_zero_staging_status[i]))
+				{
+					ac_board.relay_zero_limit_counter[i] = ac_board.md_data.rw_data.rw_d.zero_chn[i].delay_close;
+					CLEAR_RL_COUNTER_END_FLAG(ac_board.relay_zero_staging_status[i]);
+					SET_RL_COUNTER_BEGIN_FLAG(ac_board.relay_zero_staging_status[i]);
+				}else
+				{
+					ac_board.relay_zero_limit_counter[i] = 0;
+					SET_RL_COUNTER_END_FLAG(ac_board.relay_staging_staus[i]);
+					CLEAR_RL_COUNTER_BEGIN_FLAG(ac_board.relay_staging_staus[i]);
+				}
+			}else{
+					ac_board.relay_zero_limit_counter[i] = 0;
+					CLEAR_RL_COUNTER_END_FLAG(ac_board.relay_staging_staus[i]);
+					CLEAR_RL_COUNTER_BEGIN_FLAG(ac_board.relay_staging_staus[i]);
+					CLEAR_RL_ON_FLAG(ac_board.relay_staging_staus[i]);				
+				  CLEAR_RL_OFF_FLAG(ac_board.relay_staging_staus[i]);
+			}
+			CLEAR_RL_ORDER_FLAG(ac_board.relay_staging_staus[i]);
+		}		
+	}
+	for(int i = 0; i < RelaySlaveChaNum;i++)
+	{
+		if(IS_RL_COUNTER_END_FLAG_EN(ac_board.relay_staging_staus[i]))
+		{
+			CLEAR_RL_COUNTER_END_FLAG(ac_board.relay_staging_staus[i]);
+			if(IS_RL_ON_FLAG_EN(ac_board.relay_staging_staus[i]))
+			{
+				CLEAR_RL_ON_FLAG(ac_board.relay_staging_staus[i]);
+				ac_board.open(i);
+			}else if(IS_RL_OFF_FLAG_EN(ac_board.relay_staging_staus[i]))
+			{
+				CLEAR_RL_OFF_FLAG(ac_board.relay_staging_staus[i]);
+				ac_board.close(i);
+			}
+			//todo insert data to iic flash chache and wait write to eepeom
+		}
+	}
+	for(int i = 0; i < ZERO_CTRL_NUM;i++)
+	{
+		if(IS_RL_COUNTER_END_FLAG_EN(ac_board.relay_zero_staging_status[i]))
+		{
+			CLEAR_RL_COUNTER_END_FLAG(ac_board.relay_zero_staging_status[i]);
+			if(IS_RL_ON_FLAG_EN(ac_board.relay_zero_staging_status[i]))
+			{
+				CLEAR_RL_ON_FLAG(ac_board.relay_zero_staging_status[i]);
+				ac_board.zero_open(i);
+			}else if(IS_RL_OFF_FLAG_EN(ac_board.relay_zero_staging_status[i]))
+			{
+				CLEAR_RL_OFF_FLAG(ac_board.relay_zero_staging_status[i]);
+				ac_board.zero_close(i);
+			}
+			//todo insert data to iic flash chache and wait write to eepeom
+		}
+	}
 }