Parcourir la source

新寄存器整合双火线最新功能。

liyi il y a 1 an
Parent
commit
a6ca30c93c

+ 179 - 12
truing_control/PDU-AC/common/common.c

@@ -17,13 +17,44 @@ void reset_config_for_eeprom(void)
 	{
 		//board->write_eeprom_page(EEPROM_DEVICES_ADDR,(uint8_t *)&board->md_data.r_data.r_d.dev_chn,EEPROM_DEVICES_LENTH);
 		
-		board->write_eeprom_page(EEPROM_STATUS_ADDR,(uint8_t *)&board->relay_staging_staus[0],EEPROM_STATUS_LENTH);
-		for(int i = 0; i < RelaySlaveChaNum;i++)
-		{
-			board->md_data.rw_data.rw_d.delay_chn[i].delay_open  = (1+i) *100;
-			board->md_data.rw_data.rw_d.delay_chn[i].delay_close = (1+i) *100;
-		}
-		board->write_eeprom_page(EEPROM_OTHER_ADDR,(uint8_t *)&board->md_data.rw_data.rw_d.delay_chn[0],START_RW_LENTH-EEPROM_STATUS_LENTH);
+		//board->write_eeprom_page(EEPROM_STATUS_ADDR,(uint8_t *)&board->relay_staging_staus[0],EEPROM_STATUS_LENTH);
+#if (POWER_TYPE == POWER_AC_3_3)
+			int p = 0;
+			for(int i = 0; i < MAX_CHANNEL;i+=3)
+			{
+				board->md_data.rw_data.rw_d.delay_chn[i].delay_open  = (1+p) *100;
+				board->md_data.rw_data.rw_d.delay_chn[i].delay_close = (1+p) *100;
+				
+				board->md_data.rw_data.rw_d.delay_chn[i+1].delay_open  = (1+p) *100;
+				board->md_data.rw_data.rw_d.delay_chn[i+1].delay_close = (1+p) *100;
+				
+				board->md_data.rw_data.rw_d.delay_chn[i+2].delay_open  = (1+p) *100;
+				board->md_data.rw_data.rw_d.delay_chn[i+2].delay_close = (1+p) *100;
+
+				board->md_data.rw_data.rw_d.combin_chn[i/3].delay_open = (1+p) *100;
+				board->md_data.rw_data.rw_d.combin_chn[i/3].delay_close = (1+p) *100;
+				
+				p++;
+			}
+	#if (ZERO_CONTRL == ZERO_LINE_CTRL_YES)
+			for(int i = 0; i < 3;i++)
+			{
+				board->md_data.rw_data.rw_d.zero_chn[i].delay_open  = (1+i) *100;
+				board->md_data.rw_data.rw_d.zero_chn[i].delay_close = (1+i) *100;				
+			}
+	#endif
+#elif (POWER_TYPE == POWER_AC_3_2)
+			
+			
+#else
+			for(int i = 0; i < MAX_CHANNEL;i++)
+			{
+				board->md_data.rw_data.rw_d.delay_chn[i].delay_open  = (1+i) *100;
+				board->md_data.rw_data.rw_d.delay_chn[i].delay_close = (1+i) *100;
+			}
+#endif
+		memset(&board->md_data.rw_data.rw_d.delay_chn[0],0,sizeof(rw_data_t)-EEPROM_STATUS_LENTH);
+		board->write_eeprom_page(EEPROM_OTHER_ADDR,(uint8_t *)&board->md_data.rw_data.rw_d.delay_chn[0], sizeof(rw_data_t)-EEPROM_STATUS_LENTH);
 			//config phase information
 		uint8_t buff[EEPROM_CHANNEL_LENTH] = {0};
 		board->write_eeprom_page(EEPROM_CHANNEL_PHASE,buff,EEPROM_CHANNEL_LENTH);
@@ -59,21 +90,71 @@ void read_config_from_eeprom(void)
 			//default write eeprom
 			board->write_eeprom_page(EEPROM_DEVICES_ADDR,(uint8_t *)&board->md_data.r_data.r_d.dev_chn,EEPROM_DEVICES_LENTH);
 			board->write_eeprom_page(EEPROM_STATUS_ADDR,(uint8_t *)&board->relay_staging_staus[0],EEPROM_STATUS_LENTH);
-			for(int i = 0; i < RelaySlaveChaNum;i++)
+			
+#if (POWER_TYPE == POWER_AC_3_3)
+			int p = 0;
+			for(int i = 0; i < MAX_CHANNEL;i+=3)
+			{
+				board->md_data.rw_data.rw_d.delay_chn[i].delay_open  = (1+p) *100;
+				board->md_data.rw_data.rw_d.delay_chn[i].delay_close = (1+p) *100;
+				
+				board->md_data.rw_data.rw_d.delay_chn[i+1].delay_open  = (1+p) *100;
+				board->md_data.rw_data.rw_d.delay_chn[i+1].delay_close = (1+p) *100;
+				
+				board->md_data.rw_data.rw_d.delay_chn[i+2].delay_open  = (1+p) *100;
+				board->md_data.rw_data.rw_d.delay_chn[i+2].delay_close = (1+p) *100;
+
+				board->md_data.rw_data.rw_d.combin_chn[i/3].delay_open = (1+p) *100;
+				board->md_data.rw_data.rw_d.combin_chn[i/3].delay_close = (1+p) *100;
+				
+				p++;
+				
+			}
+	#if (ZERO_CONTRL == ZERO_LINE_CTRL_YES)
+			for(int i = 0; i < 3;i++)
+			{
+				board->md_data.rw_data.rw_d.zero_chn[i].delay_open  = (1+i) *100;
+				board->md_data.rw_data.rw_d.zero_chn[i].delay_close = (1+i) *100;				
+			}
+	#endif
+#elif (POWER_TYPE == POWER_AC_3_2)
+			int p = 0;
+			for(int i = 0; i < PT_SUB_COUNT;i++)
+			{
+				board->md_data.rw_data.rw_d.delay_chn[i].delay_open  = (1+p) *100;
+				board->md_data.rw_data.rw_d.delay_chn[i].delay_close = (1+p) *100;
+				
+				board->md_data.rw_data.rw_d.delay_chn[i+PT_SUB_COUNT].delay_open  = (1+p) *100;
+				board->md_data.rw_data.rw_d.delay_chn[i+PT_SUB_COUNT].delay_close = (1+p) *100;
+				
+				board->md_data.rw_data.rw_d.combin_chn[i].delay_open = (1+p) *100;
+				board->md_data.rw_data.rw_d.combin_chn[i].delay_close = (1+p) *100;
+				p++;
+			}
+#else
+			for(int i = 0; i < MAX_CHANNEL;i++)
 			{
 				board->md_data.rw_data.rw_d.delay_chn[i].delay_open  = (1+i) *100;
 				board->md_data.rw_data.rw_d.delay_chn[i].delay_close = (1+i) *100;
 			}
-			board->write_eeprom_page(EEPROM_OTHER_ADDR,(uint8_t *)&board->md_data.rw_data.rw_d.delay_chn[0],START_RW_LENTH-EEPROM_STATUS_LENTH);
+#endif
+			board->write_eeprom_page(EEPROM_OTHER_ADDR,(uint8_t *)&board->md_data.rw_data.rw_d.delay_chn[0], sizeof(rw_data_t)-EEPROM_STATUS_LENTH);
 			//config phase information
 			uint8_t buff[EEPROM_CHANNEL_LENTH] = {0};
 			board->write_eeprom_page(EEPROM_CHANNEL_PHASE,buff,EEPROM_CHANNEL_LENTH);
+			
+			iic_data chache={0};
 			for(int i = 0 ; i < MAX_ROW;i++)
-				board->write_eeprom_page(EEPROM_CONSUMER_ADDR +(CONSUM_PAGE*i),&board->con_da.iic_da.iic_con,CONSUM_PAGE);
+				board->write_eeprom_page(EEPROM_CONSUMER_ADDR +(CONSUM_PAGE*i),(uint8_t*)&chache.data[0],CONSUM_PAGE);
+			
+			for(int i = 0;i < MAX_CHANNEL;i++)
+			{
+				board->md_data.rw_data.rw_d.chn_ctrl[i] = CTRL_YES;
+			}
 		}
 		{
 			//channel open or close
-			board->read_eeprom_page(EEPROM_STATUS_ADDR,(uint8_t *)&board->relay_staging_staus[0],2*RelaySlaveChaNum);
+			board->read_eeprom_page(EEPROM_STATUS_ADDR,(uint8_t *)&board->relay_staging_staus[0],2*EEPROM_STATUS_LENTH);
 			{
 				for(int i =0 ;i < RelaySlaveChaNum;i++)
 				{
@@ -84,8 +165,19 @@ void read_config_from_eeprom(void)
 						SET_RL_ORDER_FLAG(board->relay_staging_staus[i]);
 					}
 				}
+#if (ZERO_CONTRL == ZERO_LINE_CTRL_YES)
+				for(int i = 0; i < ZERO_CTRL_NUM;i++)
+				{
+					if(board->relay_zero_staging_status[i])
+					{
+						SET_RL_ON_DELAY_FLAG(board->relay_zero_staging_status[i]);
+						CLEAR_RL_OFF_DELAY_FLAG(board->relay_zero_staging_status[i]);
+						SET_RL_ORDER_FLAG(board->relay_zero_staging_status[i]);						
+					}
+				}		
+#endif
 			}
-			board->read_eeprom_page(EEPROM_OTHER_ADDR,(uint8_t *)&board->md_data.rw_data.rw_d.delay_chn[0],START_RW_LENTH-EEPROM_STATUS_LENTH);
+			board->read_eeprom_page(EEPROM_OTHER_ADDR,(uint8_t *)&board->md_data.rw_data.rw_d.delay_chn[0],2*(START_RW_LENTH-EEPROM_STATUS_LENTH));
 						//get phase information
 			uint8_t buff[EEPROM_CHANNEL_LENTH] = {0};
 			board->read_eeprom_page(EEPROM_CHANNEL_PHASE,buff,EEPROM_CHANNEL_LENTH);
@@ -104,6 +196,10 @@ void read_config_from_eeprom(void)
 			{
 				board->md_data.r_data.r_d.ele_out[i].resever = buff[i];   //config phase information
 				board->check_threshold(THRESHOLD_OUT,i);
+				if(board->md_data.rw_data.rw_d.chn_ctrl[i] > 2)
+				{
+					board->md_data.rw_data.rw_d.chn_ctrl[i] = 0;
+				}					
 			}
 			iic_data chache={0};
 			for(int i = 0 ; i < MAX_ROW;i++)
@@ -135,11 +231,82 @@ void read_config_from_eeprom(void)
 				for(int i = 0 ; i < MAX_ROW;i++)
 					board->write_eeprom_page(EEPROM_CONSUMER_ADDR +(CONSUM_PAGE*i),&chache1,CONSUM_PAGE);
 			}
+			//read chn ctrl
 		}
 	}
 }
 
 
+void set_relay_sta_async(async_data *data)
+{
+	if(!data)
+		goto failed;
+	board_t *board = get_board();
+	if(board)
+	{
+		if(data->fire_or_zero == _FIRE)
+		{
+			//if(board->md_data.rw_data.rw_d.chn_ctrl[data->channel] != 0)  goto failed;
+			if(data->w_eep_flag == FLAG_W_EEP)
+			{
+				w_eeprom_data_t da = {0};
+				da.lenth =2;
+				memcpy(&da.data,&data->status,2);
+				da.start_addr = (EEPROM_STATUS_ADDR+(data->channel*2));
+				board->q_cache.en_queue(&da);
+			}
+		}
+		else if(data->fire_or_zero == _ZERO)
+		{
+	#if (ZERO_CONTRL == ZERO_LINE_CTRL_YES)
+			if(data->w_eep_flag == FLAG_W_EEP)
+			{
+				w_eeprom_data_t da = {0};
+				da.lenth =2;
+				memcpy(&da.data,&data->status,2);
+				da.start_addr = (EEPROM_STATUS_ADDR+((data->channel+13)*2));
+				board->q_cache.en_queue(&da);	
+			}			
+	#else
+				goto failed;
+	#endif			
+		}
+		else
+		{
+			goto failed;
+		}
+		SET_RL_STATUS(*data->reg,data->status);
+		if(data->method == DELAY_CTRL)
+		{
+				if(data->status)
+				{
+					SET_RL_ON_DELAY_FLAG(*(data->reg));
+					CLEAR_RL_OFF_DELAY_FLAG(*(data->reg));
+				}else
+				{
+					CLEAR_RL_ON_DELAY_FLAG(*(data->reg));
+					SET_RL_OFF_DELAY_FLAG(*(data->reg));
+				}						
+		}else
+		{
+			if(data->status)
+			{
+				CLEAR_RL_ON_DELAY_FLAG(*(data->reg));
+				CLEAR_RL_OFF_DELAY_FLAG(*(data->reg));
+			}else
+			{
+				CLEAR_RL_ON_DELAY_FLAG(*(data->reg));
+				CLEAR_RL_OFF_DELAY_FLAG(*(data->reg));
+			}						
+		}
+		SET_RL_ORDER_FLAG(*(data->reg));
+	}
+failed:
+	return;
+}
+
+
+
 void set_relay_status_async(uint16_t *reg,uint8_t method,uint16_t status)
 {
 	board_t *board = get_board();

+ 31 - 3
truing_control/PDU-AC/common/common.h

@@ -197,6 +197,9 @@
 #define EEPROM_CHANNEL_LENTH                  (9)
 
 
+//#define EEPROM_CHN_CTRL                       (2080)
+//#define EEPROM_CHN_CTRL_LENTH                 (32)     //one page
+
 #define CONSUM_PAGE                           (64)
 #define MAX_ROW                               (40)
 
@@ -211,6 +214,8 @@
 #define ELE_INPUT                             0
 #define ELE_OUTPUT                            1
 
+#define AC3PPDU_Lack_Voltage			(30000)
+
 
 #define Default_Consum_Max   (4000000000)
 #define Default_Voltage_Max  (1000000000)
@@ -279,6 +284,7 @@ typedef struct {
 	uint32_t dev_chn;
 	uint16_t version[6];
 	uint16_t date[16];
+	uint64_t keep_running_time;    
 }board_info_t;
 
 
@@ -325,8 +331,7 @@ typedef struct {
 	uint16_t            detection;
 	uint16_t            wanning_lock_L1;
 	uint16_t            wanning_lock_L2;
-	uint16_t            wanning_lock_L3;
-	uint64_t            keep_running_time;            
+	uint16_t            wanning_lock_L3; 
 }r_data_t;
 
 
@@ -345,6 +350,10 @@ typedef struct {
 	uint16_t            over_fun_in[3];
 	uint16_t            over_func_out[MAX_CHANNEL];
 	uint16_t            combin_over_func[4];
+	uint16_t            chn_ctrl[MAX_CHANNEL];
+	#define            	CTRL_YES    			0
+	#define             CTRL_HARD_OPEN    1
+	#define             CTRL_HARD_CLOSE   2
 }rw_data_t;
 
 
@@ -369,7 +378,7 @@ typedef struct {
 	uint64_t recode_index1;
 }iic_consumer_chache_t;
 
-typedef struct{
+typedef union{
 	uint8_t  data[64];
 	iic_consumer_chache_t iic_con;
 }iic_data;
@@ -414,6 +423,20 @@ typedef struct {
 }queue_t;
 
 
+typedef struct {
+	uint8_t fire_or_zero;
+#define _FIRE   0
+#define _ZERO   1
+	uint8_t channel;
+	uint16_t *reg;
+	uint8_t method;
+	uint16_t status;
+	uint8_t  w_eep_flag;
+#define FLAG_N_W_EEP 0
+#define FLAG_W_EEP   1
+}async_data;
+
+
 
 typedef struct {
 	mod_data_t md_data;
@@ -422,6 +445,7 @@ typedef struct {
 	uint8_t   clear_flag; 															/* erase consumer and all successful this flag is 0 */
 	uint8_t   out_wanning_en[MAX_CHANNEL];
 	uint8_t   in_wanning_en[MAX_INPUT_CAHNNEL];
+	uint8_t   in_over_func[3];
 	uint8_t   over_func[MAX_CHANNEL];
 	uint16_t  relay_staging_staus[MAX_CHANNEL];
 	uint16_t  relay_combin_staging_status[4];
@@ -471,6 +495,9 @@ typedef struct {
 	#else
 		uint8_t  handle_input_pt[1];
 	#endif
+	#if (ZERO_CONTRL == ZERO_LINE_CTRL_YES)
+		uint8_t handle_status_N[3];
+	#endif
 #endif
 
 #if SUPPORT_SELF_LOCK
@@ -517,5 +544,6 @@ board_t *get_board();
 void set_relay_status_async(uint16_t *reg,uint8_t method,uint16_t status);
 void read_config_from_eeprom(void);
 void reset_config_for_eeprom(void);
+void set_relay_sta_async(async_data *data);
 #endif
 

+ 372 - 74
truing_control/PDU-AC/hardware/detection/detection.c

@@ -67,6 +67,10 @@ static void detection_opt(void);
 void detection_init(void)
 {
 	board = get_board();
+	
+#if(POWER_TYPE == POWER_DC)
+	
+#else
 	rcu_periph_clock_enable(RCU_CFGCMP);
 	rcu_periph_clock_enable(DETECTION_1_RCU);
 	gpio_mode_set(DETECTION_1_IO, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, DETECTION_1);
@@ -75,20 +79,22 @@ void detection_init(void)
 	exti_init(DERECTION_1_EXTI,EXTI_INTERRUPT,EXTI_TRIG_FALLING);
 	exti_interrupt_flag_clear(DERECTION_1_EXTI);
 
-#if SURPPORT_2_PT
-	rcu_periph_clock_enable(DETECTION_2_RCU);
-	gpio_mode_set(DETECTION_2_IO, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, DETECTION_2);
-	nvic_irq_enable(EXTI2_3_IRQn,2);
-	syscfg_exti_line_config(DETECIION_2_EXTI_SOURCE,DERECTION_2_EXTI_IO);
-	exti_init(DERECTION_2_EXTI,EXTI_INTERRUPT,EXTI_TRIG_FALLING);
-	exti_interrupt_flag_clear(DERECTION_2_EXTI);	
-#endif	
+	#if SURPPORT_2_PT
+		rcu_periph_clock_enable(DETECTION_2_RCU);
+		gpio_mode_set(DETECTION_2_IO, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, DETECTION_2);
+		nvic_irq_enable(EXTI2_3_IRQn,2);
+		syscfg_exti_line_config(DETECIION_2_EXTI_SOURCE,DERECTION_2_EXTI_IO);
+		exti_init(DERECTION_2_EXTI,EXTI_INTERRUPT,EXTI_TRIG_FALLING);
+		exti_interrupt_flag_clear(DERECTION_2_EXTI);	
+	#endif	
+#endif
 	board->detection = get_detection;
 	board->opt_detection = detection_opt;
 	
 }
 void key_init(void)
 {
+
 #if SUPPORT_ALL_ON_OFF
 	rcu_periph_clock_enable(RCU_CFGCMP);
 	rcu_periph_clock_enable(KEY_RST_RCU);
@@ -119,14 +125,25 @@ void EXTI4_15_IRQHandler(void){
 #if SUPPORT_ALL_ON_OFF
 	if(RESET != exti_interrupt_flag_get(KEY_RST_EXTI))
 	{
+		exti_interrupt_flag_clear(KEY_RST_EXTI);
 		if(board)
 		{
 			if(gpio_input_bit_get(KEY_TEST_IO,KEY_TEST) != 0)
 			{
-				//todo write to eeprom cache
+					for(uint8_t k = 0; k < RelaySlaveChaNum;k++)
+					{
+						async_data da = {0};
+						da.channel =k;
+						da.fire_or_zero = _FIRE;
+						da.method = DELAY_CTRL;
+						da.reg = &board->relay_staging_staus[k];
+						da.status = RELAY_CLOSE;
+						da.w_eep_flag = FLAG_W_EEP;
+						set_relay_sta_async(&da);
+					}				
 				
 			}
-			exti_interrupt_flag_clear(KEY_RST_EXTI);
+			
 		}
 	}
 #endif
@@ -147,13 +164,23 @@ void EXTI2_3_IRQHandler(void)
 #if SUPPORT_ALL_ON_OFF
 	if(RESET != exti_interrupt_flag_get(KEY_TEST_EXTI))
 	{
+		exti_interrupt_flag_clear(KEY_TEST_EXTI);
 		if(board)
 		{
 			if(gpio_input_bit_get(KEY_RST_IO,KEY_RST) != 0)
 			{
-				
+					for(uint8_t k = 0; k < RelaySlaveChaNum;k++)
+					{
+						async_data da = {0};
+						da.channel =k;
+						da.fire_or_zero = _FIRE;
+						da.method = DELAY_CTRL;
+						da.reg = &board->relay_staging_staus[k];
+						da.status = RELAY_OPEN;
+						da.w_eep_flag = FLAG_W_EEP;
+						set_relay_sta_async(&da);
+					}						
 			}
-			exti_interrupt_flag_clear(KEY_TEST_EXTI);
 		}
 	}
 #endif	
@@ -174,6 +201,9 @@ static void get_detection()
 {
 	if(board)
 	{
+#if (POWER_TYPE == POWER_DC)
+		
+#else
 		uint16_t data = 0;
 		if(board->detection_1_value > 0)
 		{
@@ -184,6 +214,7 @@ static void get_detection()
 		{
 			data  |= (1 << 1);
 		}		
+#endif
 #endif
 		board->md_data.r_data.r_d.detection = data;
 	}
@@ -194,92 +225,359 @@ static void detection_opt(void)
 	if(board)
 	{
 #if RELAY_REMENBER
-	#if( SURPPORT_2_PT && (!SUPPORT_TWIN_FIRE))
-			if(board->md_data.r_data.r_d.detection & 0x1)
+		#if ((POWER_TYPE == POWER_AC) || (POWER_TYPE == POWER_DC) || (POWER_TYPE == POWER_AC_3_1))
+				if(board->md_data.r_data.r_d.detection & 0x1)
+				{
+					if(board->handle_input_pt[0] == 0)
+					{
+						board->handle_input_pt[0] = 1;
+						for(uint8_t k = 0; k < PT_SUB_COUNT;k++)
+						{
+							if(board->md_data.rw_data.rw_d.chn_ctrl[k] == 2)
+								continue;
+							else if(board->md_data.rw_data.rw_d.chn_ctrl[k] == 1)							
+							{
+								if(board->md_data.rw_data.rw_d.relay_status == RELAY_OPEN)
+									continue;
+							}
+							async_data da = {0};
+							da.channel =k;
+							da.fire_or_zero = _FIRE;
+							da.method = DELAY_CTRL;
+							da.reg = &board->relay_staging_staus[k];
+							da.status = board->handle_status[k];
+							da.w_eep_flag = FLAG_N_W_EEP;
+							set_relay_sta_async(&da);
+						//	set_relay_status_async(&board->relay_staging_staus[k],DELAY_CTRL,board->handle_status[k]);
+						}
+					}
+				}else
+				{
+					if(board->handle_input_pt[0] == 1)
+					{
+						for(uint8_t k = 0; k < PT_SUB_COUNT;k++)
+						{
+							if(board->md_data.rw_data.rw_d.chn_ctrl[k] == 1)
+								continue;
+							else if(board->md_data.rw_data.rw_d.chn_ctrl[k] == 2)							
+							{
+								if(board->md_data.rw_data.rw_d.relay_status == RELAY_CLOSE)
+									continue;
+							}
+							board->handle_status[k] = board->md_data.rw_data.rw_d.relay_status[k];
+							async_data da = {0};
+							da.channel =k;
+							da.fire_or_zero = _FIRE;
+							da.method = PROMPT_CTRL;
+							da.reg = &board->relay_staging_staus[k];
+							da.status = RELAY_CLOSE;
+							da.w_eep_flag = FLAG_N_W_EEP;
+							set_relay_sta_async(&da);
+						 //	set_relay_status_async(&board->relay_staging_staus[k],PROMPT_CTRL,RELAY_CLOSE);
+						}
+						board->handle_input_pt[0] = 0;
+					}
+				}		
+			#if SURPPORT_2_PT
+				if(board->md_data.r_data.r_d.detection & 0x2)
+				{
+					if(board->handle_input_pt[1] == 0)
+					{
+						board->handle_input_pt[1] = 1;
+						for(uint8_t k = PT_SUB_COUNT; k < RelaySlaveChaNum;k++)
+						{
+							if(board->md_data.rw_data.rw_d.chn_ctrl[k] == 2)
+								continue;
+							else if(board->md_data.rw_data.rw_d.chn_ctrl[k] == 1)							
+							{
+								if(board->md_data.rw_data.rw_d.relay_status == RELAY_OPEN)
+									continue;
+							}
+							async_data da = {0};
+							da.channel =k;
+							da.fire_or_zero = _FIRE;
+							da.method = DELAY_CTRL;
+							da.reg = &board->relay_staging_staus[k];
+							da.status = board->handle_status[k];
+							da.w_eep_flag = FLAG_N_W_EEP;
+							set_relay_sta_async(&da);
+						//	set_relay_status_async(&board->relay_staging_staus[k],DELAY_CTRL,board->handle_status[k]);
+						}
+					}
+				}else
+				{
+					if(board->handle_input_pt[1] == 1)
+					{
+						for(uint8_t k = PT_SUB_COUNT; k < RelaySlaveChaNum;k++)
+						{
+							if(board->md_data.rw_data.rw_d.chn_ctrl[k] == 1)
+								continue;
+							else if(board->md_data.rw_data.rw_d.chn_ctrl[k] == 2)							
+							{
+								if(board->md_data.rw_data.rw_d.relay_status == RELAY_CLOSE)
+									continue;
+							}
+							board->handle_status[k] = board->md_data.rw_data.rw_d.relay_status[k];
+							async_data da = {0};
+							da.channel = k;
+							da.fire_or_zero = _FIRE;
+							da.method = PROMPT_CTRL;
+							da.reg = &board->relay_staging_staus[k];
+							da.status = RELAY_CLOSE;
+							da.w_eep_flag = FLAG_N_W_EEP;
+							set_relay_sta_async(&da);
+							//set_relay_status_async(&board->relay_staging_staus[k],PROMPT_CTRL,RELAY_CLOSE);			
+						}
+						board->handle_input_pt[1] = 0;
+					}
+				}				
+			#endif
+		#elif (POWER_TYPE == POWER_AC_3_2)
+		uint8_t sync_buff[PT_SUB_COUNT] = {0};
+		async_data da = {0};
+		if(board->md_data.r_data.r_d.detection != 0x3)
+		{
+			if((board->md_data.r_data.r_d.detection & 0x1) == 0)
 			{
-				if(board->handle_input_pt[0] == 0)
+				if(board->handle_input_pt[0] == 1)
 				{
-					board->handle_input_pt[0] = 1;
-//					uint8_t val = (RelaySlaveChaNum % 2) ? (RelaySlaveChaNum / 2 + 1) : (RelaySlaveChaNum / 2);
-//					uint16_t value = 0;
+					board->handle_input_pt[0] = 0;
+					
 					for(uint8_t k = 0; k < PT_SUB_COUNT;k++)
 					{
-						//board->relay_staging_staus[k] = board->handle_status[k];
-//						value = board->handle_status[k];
-						set_relay_status_async(&board->relay_staging_staus[k],DELAY_CTRL,board->handle_status[k]);
-//						w_eeprom_data_t data = {0};
-//						data.lenth =2;
-//						memcpy(&data.data,&value,2);
-//						data.start_addr = (EEPROM_STATUS_ADDR+(k*2));
-//						board->q_cache.en_queue(&data);
+						if(board->md_data.rw_data.rw_d.chn_ctrl[k] == 0 && board->md_data.rw_data.rw_d.chn_ctrl[k+PT_SUB_COUNT] == 0)		//double fire ctrl
+						{
+							board->handle_status[k] = board->md_data.rw_data.rw_d.relay_status[k] & 0x1;
+							board->handle_status[k+PT_SUB_COUNT] = board->md_data.rw_data.rw_d.relay_status[k+PT_SUB_COUNT] & 0x1;
+							da.channel = k+PT_SUB_COUNT;
+							da.fire_or_zero = _FIRE;
+							da.method = PROMPT_CTRL;
+							da.reg = &board->relay_staging_staus[k+PT_SUB_COUNT];
+							da.status = RELAY_CLOSE;
+							da.w_eep_flag = FLAG_N_W_EEP;
+							set_relay_sta_async(&da);
+							sync_buff[k] = 1;
+						}else
+						{
+							if(board->md_data.rw_data.rw_d.chn_ctrl[k] == 0)
+							{
+								board->handle_status[k] = board->md_data.rw_data.rw_d.relay_status[k] & 0x1;
+							}else if(board->md_data.rw_data.rw_d.chn_ctrl[k] == 2)
+							{
+								if(board->md_data.rw_data.rw_d.relay_status == RELAY_CLOSE)
+									continue;
+							}else
+							{
+								continue;
+							}
+						}
+						da.channel = k;
+						da.fire_or_zero = _FIRE;
+						da.method = PROMPT_CTRL;
+						da.reg = &board->relay_staging_staus[k];
+						da.status = RELAY_CLOSE;
+						da.w_eep_flag = FLAG_N_W_EEP;
+						set_relay_sta_async(&da);			
 					}
-					
 				}
-			}else
+			}
+			if((board->md_data.r_data.r_d.detection & 0x2) == 0)
 			{
-				if(board->handle_input_pt[0] == 1)
+				if(board->handle_input_pt[1] == 1)
 				{
-//					uint8_t val = (RelaySlaveChaNum % 2) ? (RelaySlaveChaNum / 2 + 1) : (RelaySlaveChaNum/2);
-//					uint16_t value = RELAY_CLOSE;
+					board->handle_input_pt[1] = 0;
 					for(uint8_t k = 0; k < PT_SUB_COUNT;k++)
 					{
-						board->handle_status[k] = board->md_data.rw_data.rw_d.relay_status[k];
-						set_relay_status_async(&board->relay_staging_staus[k],PROMPT_CTRL,RELAY_CLOSE);
-//						w_eeprom_data_t data = {0};
-//						data.lenth =2;
-//						memcpy(&data.data,&value,2);
-//						data.start_addr = (EEPROM_STATUS_ADDR+(k*2));
-//						board->q_cache.en_queue(&data);
+						if(board->md_data.rw_data.rw_d.chn_ctrl[k] == 0 && board->md_data.rw_data.rw_d.chn_ctrl[k+PT_SUB_COUNT] == 0)	
+						{
+							if(sync_buff[k])
+								continue;
+							else
+							{
+								board->handle_status[k] = board->md_data.rw_data.rw_d.relay_status[k] & 0x1;
+								board->handle_status[k+PT_SUB_COUNT] = board->md_data.rw_data.rw_d.relay_status[k+PT_SUB_COUNT] & 0x1;
+								da.channel = k;
+								da.fire_or_zero = _FIRE;
+								da.method = PROMPT_CTRL;
+								da.reg = &board->relay_staging_staus[k];
+								da.status = RELAY_CLOSE;
+								da.w_eep_flag = FLAG_N_W_EEP;
+								set_relay_sta_async(&da);								
+							}
+						}else
+						{
+							if(board->md_data.rw_data.rw_d.chn_ctrl[k+PT_SUB_COUNT] == 0)
+							{
+								board->handle_status[k+PT_SUB_COUNT] = board->md_data.rw_data.rw_d.relay_status[k+PT_SUB_COUNT] & 0x1;
+							}else if(board->md_data.rw_data.rw_d.chn_ctrl[k+PT_SUB_COUNT] == 2)
+							{
+								if(board->md_data.rw_data.rw_d.relay_status[k+PT_SUB_COUNT] == RELAY_CLOSE)
+									continue;								
+							}else
+							{
+								continue;
+							}
+						}
+						da.channel = k+PT_SUB_COUNT;
+						da.fire_or_zero = _FIRE;
+						da.method = PROMPT_CTRL;
+						da.reg = &board->relay_staging_staus[k+PT_SUB_COUNT];
+						da.status = RELAY_CLOSE;
+						da.w_eep_flag = FLAG_N_W_EEP;
+						set_relay_sta_async(&da);									
 					}
-					board->handle_input_pt[0] = 0;
+				}
+			}	
+		}else
+		{
+			if(board->handle_input_pt[0] == 0)
+			{
+				board->handle_input_pt[0] = 1;
+				for(uint8_t k = 0; k < PT_SUB_COUNT;k++)
+				{
+					if(board->md_data.rw_data.rw_d.chn_ctrl[k] == 0 && board->md_data.rw_data.rw_d.chn_ctrl[k+PT_SUB_COUNT] == 0)	
+					{
+						da.channel = k+PT_SUB_COUNT;
+						da.fire_or_zero = _FIRE;
+						da.method = DELAY_CTRL;
+						da.reg = &board->relay_staging_staus[k+PT_SUB_COUNT];
+						da.status = board->handle_status[k+PT_SUB_COUNT];
+						da.w_eep_flag = FLAG_N_W_EEP;
+						set_relay_sta_async(&da);	
+						sync_buff[k] = 1;
+					}else 
+					{
+						if(board->md_data.rw_data.rw_d.chn_ctrl[k] == 0)
+						{
+							
+						}else if(board->md_data.rw_data.rw_d.chn_ctrl[k] == 1)
+						{
+							if(board->md_data.rw_data.rw_d.relay_status[k] == RELAY_OPEN)
+								continue;
+						}else
+						{
+							continue;
+						}
+					}
+					da.channel = k;
+					da.fire_or_zero = _FIRE;
+					da.method = DELAY_CTRL;
+					da.reg = &board->relay_staging_staus[k];
+					da.status = board->handle_status[k];
+					da.w_eep_flag = FLAG_N_W_EEP;
+					set_relay_sta_async(&da);	
 				}
 			}
-			if(board->md_data.r_data.r_d.detection & 0x2)
+			if(board->handle_input_pt[1] == 0)
+			{
+				board->handle_input_pt[1] = 1;
+				for(uint8_t k = 0; k < PT_SUB_COUNT;k++)
+				{
+					if(board->md_data.rw_data.rw_d.chn_ctrl[k] == 0 && board->md_data.rw_data.rw_d.chn_ctrl[k+PT_SUB_COUNT] == 0)	
+					{
+						if(sync_buff[k])
+							continue;
+						da.channel = k;
+						da.fire_or_zero = _FIRE;
+						da.method = DELAY_CTRL;
+						da.reg = &board->relay_staging_staus[k];
+						da.status = board->handle_status[k];
+						da.w_eep_flag = FLAG_N_W_EEP;
+						set_relay_sta_async(&da);	
+
+					}else 
+					{
+						if(board->md_data.rw_data.rw_d.chn_ctrl[k+PT_SUB_COUNT] == 0)
+						{
+							
+						}else if(board->md_data.rw_data.rw_d.chn_ctrl[k+PT_SUB_COUNT] == 1)
+						{
+							if(board->md_data.rw_data.rw_d.relay_status[k+PT_SUB_COUNT] == RELAY_OPEN)
+								continue;
+						}else
+						{
+							continue;
+						}
+					}
+					da.channel = k+PT_SUB_COUNT;
+					da.fire_or_zero = _FIRE;
+					da.method = DELAY_CTRL;
+					da.reg = &board->relay_staging_staus[k+PT_SUB_COUNT];
+					da.status = board->handle_status[k+PT_SUB_COUNT];
+					da.w_eep_flag = FLAG_N_W_EEP;
+					set_relay_sta_async(&da);	
+				}
+			}			
+		}
+		#elif (POWER_TYPE == POWER_AC_3_3)
+			if(board->md_data.r_data.r_d.detection)
 			{
-				if(board->handle_input_pt[1] == 0)
+				if(board->handle_input_pt[0] == 0)
 				{
-					board->handle_input_pt[1] = 1;
-//					uint8_t val = (RelaySlaveChaNum % 2) ? (RelaySlaveChaNum / 2 + 1) : (RelaySlaveChaNum/2);
-//					uint16_t value = 0;
-					for(uint8_t k = PT_SUB_COUNT; k < RelaySlaveChaNum;k++)
+					board->handle_input_pt[0] = 1;
+					for(uint8_t k = 0; k < RelaySlaveChaNum;k++)
+					{
+							async_data da = {0};
+							da.channel =k;
+							da.fire_or_zero = _FIRE;
+							da.method = DELAY_CTRL;
+							da.reg = &board->relay_staging_staus[k];
+							da.status = board->handle_status[k];
+							da.w_eep_flag = FLAG_N_W_EEP;
+							set_relay_sta_async(&da);
+						//	set_relay_status_async(&board->relay_staging_staus[k],DELAY_CTRL,board->handle_status[k]);
+					}
+#if (ZERO_CONTRL  == ZERO_LINE_CTRL_YES)		
+					for(uint8_t k = 0; k < ZERO_CTRL_NUM;k++)
 					{
-						set_relay_status_async(&board->relay_staging_staus[k],DELAY_CTRL,board->handle_status[k]);
-//						w_eeprom_data_t data = {0};
-//						data.lenth =2;
-//						memcpy(&data.data,&value,2);
-//						data.start_addr = (EEPROM_STATUS_ADDR+(k*2));
-//						board->q_cache.en_queue(&data);
+							async_data da = {0};
+							da.channel =k;
+							da.fire_or_zero = _ZERO;
+							da.method = DELAY_CTRL;
+							da.reg = &board->relay_zero_staging_status[k];
+							da.status = board->handle_status_N[k];
+							da.w_eep_flag = FLAG_N_W_EEP;
+							set_relay_sta_async(&da);						
 					}
+#endif
 				}
 			}else
 			{
-				if(board->handle_input_pt[1] == 1)
+				if(board->handle_input_pt[0] == 1)
 				{
-//					uint8_t val = (RelaySlaveChaNum % 2) ? (RelaySlaveChaNum / 2 + 1) : (RelaySlaveChaNum/2);
-//					uint16_t value = RELAY_CLOSE;
-					for(uint8_t k = PT_SUB_COUNT; k < RelaySlaveChaNum;k++)
+					board->handle_input_pt[0] = 0;
+					for(uint8_t k = 0; k < RelaySlaveChaNum;k++)
 					{
-						board->handle_status[k] = board->md_data.rw_data.rw_d.relay_status[k];
-						set_relay_status_async(&board->relay_staging_staus[k],PROMPT_CTRL,RELAY_CLOSE);
-//						w_eeprom_data_t data = {0};
-//						data.lenth =2;
-//						memcpy(&data.data,&value,2);
-//						data.start_addr = (EEPROM_STATUS_ADDR+(k*2));
-//						board->q_cache.en_queue(&data);						
+							board->handle_status[k] = board->md_data.rw_data.rw_d.relay_status[k];
+							async_data da = {0};
+							da.channel =k;
+							da.fire_or_zero = _FIRE;
+							da.method = PROMPT_CTRL;
+							da.reg = &board->relay_staging_staus[k];
+							da.status = RELAY_CLOSE;
+							da.w_eep_flag = FLAG_N_W_EEP;
+							set_relay_sta_async(&da);
+						 //	set_relay_status_async(&board->relay_staging_staus[k],PROMPT_CTRL,RELAY_CLOSE);
 					}
-					board->handle_input_pt[1] = 0;
+#if (ZERO_CONTRL  == ZERO_LINE_CTRL_YES)
+					for(uint8_t k = 0; k < ZERO_CTRL_NUM;k++)
+					{
+							board->handle_status_N[k] = board->md_data.rw_data.rw_d.zero_relay_status[k];
+							async_data da = {0};
+							da.channel =k;
+							da.fire_or_zero = _ZERO;
+							da.method = PROMPT_CTRL;
+							da.reg = &board->relay_zero_staging_status[k];
+							da.status = RELAY_CLOSE;
+							da.w_eep_flag = FLAG_N_W_EEP;
+							set_relay_sta_async(&da);						
+					}
+#endif
 				}
-			}		
-	#elif SUPPORT_TWIN_FIRE
-			//todo
-//			if(board->md_data.r_data.r_d.detection & 0x3)
-//			{
-//			
-//			}
-	#endif
-#else
-		//todo
+			}
 		
-#endif
+		
+		#endif
+#endif		
 	}
 }

+ 97 - 1
truing_control/PDU-AC/hardware/electricity/electricity.c

@@ -3,11 +3,12 @@
 #include "common.h"
 #include "board_cfg.h"
 #include "Hlw8110.h"
+#include "relay.h"
 
 static board_t *board = 0;
 static void read_ele(uint8_t channel);
 static void check_wanning(uint8_t in_out,uint8_t channel);
-
+static void opt_over_func(uint8_t channel);
 
 extern float   F_AC_V;													
 extern float   F_AC_I;													
@@ -31,6 +32,7 @@ void electricity_init(void)
 	}
 	board->read_ele = read_ele;
 	board->check_wanning = check_wanning;
+	board->opt_overfunc = opt_over_func;
 }
 
 
@@ -122,6 +124,10 @@ static void check_wanning(uint8_t in_out,uint8_t channel)
 								board->md_data.r_data.r_d.ele_out[channel].voltage > board->md_data.rw_data.rw_d.th_out[channel].th_voltage_max)
 				{
 					SET_WANNING_VOLTAGE_MAX(board->md_data.r_data.r_d.ele_out[channel].wanning);
+					if(IS_OVERFUNC_VOLTAGE_MAX(board->md_data.rw_data.rw_d.over_func_out[channel]))
+					{
+						board->over_func[channel] = 1;
+					}
 				}else
 				{
 					UNSET_WANNING_VOLTAGE_MAX(board->md_data.r_data.r_d.ele_out[channel].wanning);
@@ -131,6 +137,10 @@ static void check_wanning(uint8_t in_out,uint8_t channel)
 								board->md_data.r_data.r_d.ele_out[channel].voltage < board->md_data.rw_data.rw_d.th_out[channel].th_voltage_min)
 				{
 					SET_WANNING_VOLTAGE_MIN(board->md_data.r_data.r_d.ele_out[channel].wanning);
+					if(IS_OVERFUNC_VOLTAGE_MIN(board->md_data.rw_data.rw_d.over_func_out[channel]))
+					{
+						board->over_func[channel] = 1;
+					}
 				}else
 				{
 					UNSET_WANNING_VOLTAGE_MIN(board->md_data.r_data.r_d.ele_out[channel].wanning);
@@ -140,6 +150,10 @@ static void check_wanning(uint8_t in_out,uint8_t channel)
 								board->md_data.r_data.r_d.ele_out[channel].current > board->md_data.rw_data.rw_d.th_out[channel].th_current_max)
 				{
 					SET_WANNING_CURRENT_MAX(board->md_data.r_data.r_d.ele_out[channel].wanning);
+					if(IS_OVERFUNC_CURRENT_MAX(board->md_data.rw_data.rw_d.over_func_out[channel]))
+					{
+						board->over_func[channel] = 1;
+					}
 				}else
 				{
 					UNSET_WANNING_CURRENT_MAX(board->md_data.r_data.r_d.ele_out[channel].wanning);
@@ -149,6 +163,10 @@ static void check_wanning(uint8_t in_out,uint8_t channel)
 								board->md_data.r_data.r_d.ele_out[channel].voltage > board->md_data.rw_data.rw_d.th_out[channel].th_power_max)
 				{
 					SET_WANNING_POWER_MAX(board->md_data.r_data.r_d.ele_out[channel].wanning);
+					if(IS_OVERFUNC_POWER_MAX(board->md_data.rw_data.rw_d.over_func_out[channel]))
+					{
+						board->over_func[channel] = 1;
+					}
 				}else
 				{
 					UNSET_WANNING_POWER_MAX(board->md_data.r_data.r_d.ele_out[channel].wanning);
@@ -158,10 +176,88 @@ static void check_wanning(uint8_t in_out,uint8_t channel)
 								board->md_data.r_data.r_d.ele_out[channel].voltage > board->md_data.rw_data.rw_d.th_out[channel].th_consumer_max)
 				{
 					SET_WANNING_CONSUMER_MAX(board->md_data.r_data.r_d.ele_out[channel].wanning);
+					if(IS_OVERFUNC_CONSUMER_MAX(board->md_data.rw_data.rw_d.over_func_out[channel]))
+					{
+						board->over_func[channel] = 1;
+					}
 				}else
 				{
 					UNSET_WANNING_CONSUMER_MAX(board->md_data.r_data.r_d.ele_out[channel].wanning);
 				}
 			}
 	}
+}
+
+
+static void opt_over_func(uint8_t channel)
+{
+#if (POWER_TYPE == POWER_AC_3_1 || POWER_TYPE == POWER_AC || POWER_TYPE == POWER_DC)
+	if(board->over_func[channel])
+	{
+		board->over_func[channel] = 0;
+		if(board->md_data.rw_data.rw_d.relay_status[channel] == RELAY_OPEN && board->md_data.rw_data.rw_d.chn_ctrl[channel] == 0)
+		{
+				async_data da = {0};
+				da.channel = channel;
+				da.fire_or_zero = _FIRE;
+				da.method = PROMPT_CTRL;
+				da.reg = &board->relay_staging_staus[channel];
+				da.status = RELAY_CLOSE;
+				da.w_eep_flag = FLAG_N_W_EEP;
+				set_relay_sta_async(&da);				
+		}
+	}
+#elif (POWER_TYPE == POWER_AC_3_3)
+	if((channel+1) % 3 == 0)
+	{
+		if(board->over_func[channel] || board->over_func[channel-1] || board->over_func[channel-2])
+		{
+			if(	board->md_data.rw_data.rw_d.relay_status[channel ] == RELAY_OPEN ||
+					board->md_data.rw_data.rw_d.relay_status[channel-1] == RELAY_OPEN ||
+					board->md_data.rw_data.rw_d.relay_status[channel-2] == RELAY_OPEN)
+			{
+				async_data da = {0};
+				if(board->md_data.rw_data.rw_d.relay_status[channel ] == RELAY_OPEN && 
+						board->md_data.rw_data.rw_d.chn_ctrl[channel] == 0)
+				{
+					da.channel = channel;
+					da.fire_or_zero = _FIRE;
+					da.method = PROMPT_CTRL;
+					da.reg = &board->relay_staging_staus[channel];
+					da.status = RELAY_CLOSE;
+					da.w_eep_flag = FLAG_N_W_EEP;
+					set_relay_sta_async(&da);
+				}
+				if(board->md_data.rw_data.rw_d.relay_status[channel-1]  == RELAY_OPEN && 
+						board->md_data.rw_data.rw_d.chn_ctrl[channel-1] == 0)
+				{				
+					da.channel = channel-1;
+					da.fire_or_zero = _FIRE;
+					da.method = PROMPT_CTRL;
+					da.reg = &board->relay_staging_staus[channel-1];
+					da.status = RELAY_CLOSE;
+					da.w_eep_flag = FLAG_N_W_EEP;
+					set_relay_sta_async(&da);	
+				}					
+				if(board->md_data.rw_data.rw_d.relay_status[channel-2] == RELAY_OPEN && 
+						board->md_data.rw_data.rw_d.chn_ctrl[channel-2] == 0)
+				{
+					da.channel = channel-2;
+					da.fire_or_zero = _FIRE;
+					da.method = PROMPT_CTRL;
+					da.reg = &board->relay_staging_staus[channel-2];
+					da.status = RELAY_CLOSE;
+					da.w_eep_flag = FLAG_N_W_EEP;
+					set_relay_sta_async(&da);	
+				}
+			}
+				board->over_func[channel] = 0;
+				board->over_func[channel-1] =0;
+				board->over_func[channel-2] =0;
+		}
+	}
+	
+	
+	
+#endif
 }

+ 13 - 21
truing_control/PDU-AC/hardware/relay/relay.c

@@ -17,23 +17,6 @@
 #define RELAY_RCU  				RCU_GPIOB
 #define RELAY_GPIO   			GPIOB
 
-#if SUPPORT_TWIN_FIRE
-	#if (RelaySlaveChaNum >=1)
-		#define RELAY_1           (GPIO_PIN_8 | GPIO_PIN_12)
-	#endif
-	#if (RelaySlaveChaNum >=2)
-		#define RELAY_2           (GPIO_PIN_9 | GPIO_PIN_13)
-	#endif
-
-	#if (RelaySlaveChaNum >=3)
-		#define RELAY_3           (GPIO_PIN_10 | GPIO_PIN_14)
-	#endif
-
-	#if (RelaySlaveChaNum >=4)
-		#define RELAY_4           (GPIO_PIN_11 | GPIO_PIN_15)
-	#endif
-#else
-
 	#if (RelaySlaveChaNum >= 1)
 		#define RELAY_1           GPIO_PIN_8
 	#endif
@@ -43,6 +26,11 @@
 	#if (RelaySlaveChaNum >= 3)
 		#define RELAY_3           GPIO_PIN_10
 	#endif
+	
+#if ((POWER_TYPE == POWER_AC_3_3) && (ZERO_CTRL_NUM == ZERO_LINE_1))
+	#define RELAY_4           GPIO_PIN_11
+#endif
+
 	#if (RelaySlaveChaNum >= 4)
 		#define RELAY_4           GPIO_PIN_11
 	#endif
@@ -58,7 +46,7 @@
 	#if (RelaySlaveChaNum >= 8)
 		#define RELAY_8           GPIO_PIN_15
 	#endif
-#endif
+
 
 
 #define RELAY_1_ON         gpio_bit_set(RELAY_GPIO,RELAY_1);
@@ -104,6 +92,12 @@ void relay_init(void)
 	board_t * board = get_board();
 	rcu_periph_clock_enable(RELAY_RCU);
 	
+	#if ((POWER_TYPE == POWER_AC_3_3) && (ZERO_CTRL_NUM == ZERO_LINE_1))
+		gpio_mode_set(RELAY_GPIO,GPIO_MODE_OUTPUT,GPIO_PUPD_NONE,RELAY_4);
+		gpio_output_options_set(RELAY_GPIO, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, RELAY_4);
+		gpio_bit_reset(RELAY_GPIO, RELAY_4);	
+	#endif
+	
 	#if (RelaySlaveChaNum >=1)
 		gpio_mode_set(RELAY_GPIO,GPIO_MODE_OUTPUT,GPIO_PUPD_NONE,RELAY_1);
 		gpio_output_options_set(RELAY_GPIO, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, RELAY_1);
@@ -125,8 +119,6 @@ void relay_init(void)
 		gpio_bit_reset(RELAY_GPIO, RELAY_4);
 	#endif
 	
-
-#if (!SUPPORT_TWIN_FIRE)
 	#if (RelaySlaveChaNum >=5)
 		gpio_mode_set(RELAY_GPIO,GPIO_MODE_OUTPUT,GPIO_PUPD_PULLDOWN,RELAY_5);
 		gpio_output_options_set(RELAY_GPIO, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, RELAY_5);
@@ -147,7 +139,7 @@ void relay_init(void)
 		gpio_output_options_set(RELAY_GPIO, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, RELAY_8);
 		gpio_bit_reset(RELAY_GPIO, RELAY_8);
 	#endif	
-#endif
+
 	
 	board->open = relay_open;
 	board->close = relay_close;

+ 1 - 1
truing_control/PDU-AC/hardware/timer/timer.c

@@ -91,7 +91,7 @@ void TIMER14_IRQHandler(void)
 		{
 			if(IS_RL_COUNTER_BEGINE_FLAG_EN(board->relay_zero_staging_status[i]))
 			{
-				if(rl_delay_zero_cnt[i] < board->relay_limit_counter[i])
+				if(rl_delay_zero_cnt[i] < board->relay_zero_limit_counter[i])
 				{
 					rl_delay_zero_cnt[i]++;
 				}else

+ 303 - 61
truing_control/PDU-AC/modbus/BARE/port/port.c

@@ -28,6 +28,7 @@
 #include "common.h"
 #include "flash.h"
 #include "gd32e23x.h"
+#include "relay.h"
 
 
 /* ----------------------- Defines ------------------------------------------*/
@@ -60,7 +61,7 @@ static uint8_t  usRegCoilsBuf[REG_COILS_NREGS];
 static USHORT   usRegDiscreteStart = REG_DISCRETE_START;
 static uint8_t  usRegDiscreteBuf[REG_DISCRETE_NREGS];
 
-
+#define  offsetof(type,member)   ((int) &((type *)0)->member)
 
 /****************************************************************************
 * Ãû	  ³Æ£ºeMBRegInputCB
@@ -160,8 +161,12 @@ unsigned int WiRegIndex;
 #define RW_OUT_Com_OVERFUNC_CHN_LEN      (4)
 
 
-#define RW_RESERVE                       (RW_OUT_Com_OVERFUNC_CHN + RW_OUT_Com_OVERFUNC_CHN_LEN)
-#define RW_RESERVE_LEN                   (62)
+#define RW_OUT_CTRL_ENABLE               (RW_OUT_Com_OVERFUNC_CHN + RW_OUT_Com_OVERFUNC_CHN_LEN)
+#define RW_OUT_CTRL_ENABLE_LEN					 (9)
+
+
+#define RW_RESERVE                       (RW_OUT_CTRL_ENABLE + RW_OUT_CTRL_ENABLE_LEN)
+#define RW_RESERVE_LEN                   (53)
 
 
 #define W_ALL_ON                         (START_W_REGISTER)
@@ -259,55 +264,90 @@ eMBRegHoldingCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs, eMBRegi
 						}
 						{
 							
-							if(usAddress >= RW_RELAY_CHN_STU && usAddress < RW_Com_RELAY_CHN_STU)   										//
+							if(usAddress >= RW_RELAY_CHN_STU && usAddress < RW_Com_RELAY_CHN_STU)   										
 							{
 								T_cnt = usAddress - RW_RELAY_CHN_STU;
-#if (SURPPORT_2_PT )			
-		#if (!SUPPORT_TWIN_FIRE)
 								for(uint8_t j = 0; j < WusNRegs;j++)
 								{
-									if(T_cnt >= PT_SUB_COUNT)
-									{
-										if(board->md_data.r_data.r_d.detection & 0x2)
-										{
-											set_relay_status_async(&board->relay_staging_staus[j+T_cnt],PROMPT_CTRL,usRegHoldBuf[WiRegIndex+j]);
-										}
-									}else
+									async_data da = {0};
+									da.channel = T_cnt+j;
+									da.fire_or_zero = _FIRE;
+									da.method = PROMPT_CTRL;
+									da.reg = &board->relay_staging_staus[T_cnt+j];
+									da.status = usRegHoldBuf[WiRegIndex+j];
+									da.w_eep_flag = FLAG_W_EEP;
+									set_relay_sta_async(&da);
+								}		
+							}else if(usAddress >= RW_Com_RELAY_CHN_STU && usAddress < RW_Zero_RELAY_CHN_STU)
+							{
+								// todo
+								T_cnt = usAddress - RW_Com_RELAY_CHN_STU;
+								
+#if ((POWER_TYPE == POWER_AC_3_3))
+								for(uint8_t j = 0; j < WusNRegs;j++)
+								{
+									uint16_t temp = (T_cnt+j) * 3;
+									if(
+										board->md_data.rw_data.rw_d.chn_ctrl[temp  ] == 0 &&
+										board->md_data.rw_data.rw_d.chn_ctrl[temp+1] == 0 &&
+										board->md_data.rw_data.rw_d.chn_ctrl[temp+2] == 0  )
 									{
-										if(board->md_data.r_data.r_d.detection & 0x1)
+										for(int i = 0; i < 3; i++)
 										{
-											set_relay_status_async(&board->relay_staging_staus[j+T_cnt],PROMPT_CTRL,usRegHoldBuf[WiRegIndex+j]);
+											async_data da = {0};
+											da.channel = temp+i;
+											da.fire_or_zero = _FIRE;
+											da.method = PROMPT_CTRL;
+											da.reg = &board->relay_staging_staus[temp+i];
+											da.status = usRegHoldBuf[WiRegIndex+j];
+											da.w_eep_flag = FLAG_W_EEP;
+											set_relay_sta_async(&da);											
 										}
+										board->relay_combin_staging_status[j+T_cnt] = usRegHoldBuf[WiRegIndex+j];
+									//	board->md_data.rw_data.rw_d.combin_relay_status[j+T_cnt] = board->relay_combin_staging_status[j+T_cnt];
 									}
 								}
-		#else
-								for(uint8_t j = 0; j < WusNRegs;j += PT_SUB_COUNT)
+#elif ((POWER_TYPE == POWER_AC_3_2))
+							for(uint8_t j = 0; j < WusNRegs;j++)
+							{
+								if(board->md_data.rw_data.rw_d.chn_ctrl[j  ] == 0 && 
+											board->md_data.rw_data.rw_d.chn_ctrl[j + PT_SUB_COUNT] == 0)
 								{
-									if(board->md_data.r_data.r_d.detection & 0x3)
-									{
-										set_relay_status_async(&board->relay_staging_staus[j+],PROMPT_CTRL,usRegHoldBuf[WiRegIndex+j]);
-										set_relay_status_async(&board->relay_staging_staus[j+PT_SUB_COUNT],PROMPT_CTRL,usRegHoldBuf[WiRegIndex+j]);
-									}
+											async_data da = {0};
+											da.channel = j;
+											da.fire_or_zero = _FIRE;
+											da.method = PROMPT_CTRL;
+											da.reg = &board->relay_staging_staus[j];
+											da.status = usRegHoldBuf[WiRegIndex+j];
+											da.w_eep_flag = FLAG_W_EEP;
+											set_relay_sta_async(&da);
+											
+											da.channel = j+PT_SUB_COUNT;
+											da.fire_or_zero = _FIRE;
+											da.method = PROMPT_CTRL;
+											da.reg = &board->relay_staging_staus[j+PT_SUB_COUNT];
+											da.status = usRegHoldBuf[WiRegIndex+j];
+											da.w_eep_flag = FLAG_W_EEP;
+											set_relay_sta_async(&da);												
 								}
-								
-		#endif
-#else
-									
-									if(board->md_data.r_data.r_d.detection)
-									{
-										set_relay_status_async(&board->relay_staging_staus[j+T_cnt],PROMPT_CTRL,usRegHoldBuf[WiRegIndex+j]);
-									}
-#endif						
-								
-							}else if(usAddress >= RW_Com_RELAY_CHN_STU && usAddress < RW_Zero_RELAY_CHN_STU)
-							{
-								// todo
-								T_cnt = usAddress - RW_Com_RELAY_CHN_STU;
-
+							}
+#endif								
 							}else if(usAddress >= RW_Zero_RELAY_CHN_STU && usAddress < RW_DELAY_CHN)
 							{
 								// todo
 								T_cnt = usAddress - RW_Zero_RELAY_CHN_STU;
+								for(uint8_t j = 0; j < WusNRegs;j++)
+								{
+										async_data da = {0};
+										da.channel = j+T_cnt;
+										da.fire_or_zero = _ZERO;
+										da.method = PROMPT_CTRL;
+										da.reg = &board->relay_zero_staging_status[j+T_cnt];
+										da.status = usRegHoldBuf[WiRegIndex+j];
+										da.w_eep_flag = FLAG_W_EEP;
+										set_relay_sta_async(&da);											
+								}
+								
 							}else if(usAddress >= RW_DELAY_CHN && usAddress < RW_RESERVE)
 							{
 								T_cnt = usAddress - RW_DELAY_CHN;
@@ -317,7 +357,30 @@ eMBRegHoldingCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs, eMBRegi
 								memcpy(&data.data,&usRegHoldBuf[WiRegIndex],2*WusNRegs);
 								data.start_addr = (EEPROM_OTHER_ADDR+(T_cnt*2));
 								board->q_cache.en_queue(&data);
-								if(usAddress >= RW_IN_THRESHOLD_CHN && usAddress < RW_OUT_THRESHOLD_CHN)
+								if(usAddress >= RW_Comb_DELAY_CHN &&  usAddress < RW_Zero_DELAY_CHN)
+								{
+#if ((POWER_TYPE == POWER_AC_3_3))
+									for(int i = 0; i < RelaySlaveChaNum;i++)
+									{
+										uint8_t index = i / 3;
+										board->md_data.rw_data.rw_d.delay_chn[i] = board->md_data.rw_data.rw_d.combin_chn[index];
+		#if (ZERO_CONTRL == ZERO_LINE_CTRL_YES)
+										board->md_data.rw_data.rw_d.zero_chn[index] = board->md_data.rw_data.rw_d.combin_chn[index];							
+		#endif
+									}		
+#elif (POWER_TYPE == POWER_AC_3_2)	
+									for(int i = 0; i < PT_SUB_COUNT;i++)
+									{
+										board->md_data.rw_data.rw_d.delay_chn[i] =board->md_data.rw_data.rw_d.combin_chn[i] ;
+										board->md_data.rw_data.rw_d.delay_chn[i+PT_SUB_COUNT] =board->md_data.rw_data.rw_d.combin_chn[i];
+									}									
+#endif					
+									w_eeprom_data_t data = {0};
+									data.start_addr = (EEPROM_OTHER_ADDR);
+									data.lenth = RW_DELAY_CHN_LEN;
+									board->q_cache.en_queue(&data);									
+								}
+								else if(usAddress >= RW_IN_THRESHOLD_CHN && usAddress < RW_OUT_THRESHOLD_CHN)
 								{
 									board->check_threshold(THRESHOLD_IN,0);
 									board->check_threshold(THRESHOLD_IN,1);
@@ -329,8 +392,95 @@ eMBRegHoldingCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs, eMBRegi
 								}else if(usAddress >= RW_OUT_Com_THRESHOLD_CHN && usAddress < RW_IN_OVERFUNC_CHN)
 								{
 									//conbin  to do
-								}else
+									uint32_t eep_base_addr = EEPROM_OTHER_ADDR+(RW_DELAY_CHN_LEN+RW_Comb_DELAY_CHN_LEN+RW_Zero_DELAY_CHN_LEN+RW_IN_THRESHOLD_CHN_LEN)*2;
+#if ((POWER_TYPE == POWER_AC_3_3))			//check combin channel				
+									for(int i = 0; i < RelaySlaveChaNum;i++)
+									{
+										uint8_t index = i / 3;
+										board->md_data.rw_data.rw_d.th_out[i] = board->md_data.rw_data.rw_d.th_combin_out[index];
+									}
+#elif ((POWER_TYPE == POWER_AC_3_2))
+									for(int i = 0; i < PT_SUB_COUNT;i++)
+									{
+										board->md_data.rw_data.rw_d.th_out[i] =board->md_data.rw_data.rw_d.th_combin_out[i] ;
+										board->md_data.rw_data.rw_d.th_out[i+PT_SUB_COUNT] =board->md_data.rw_data.rw_d.th_combin_out[i];
+									}	
+#endif									
+									for(int i = 0; i < RelaySlaveChaNum;i++)
+									{
+										w_eeprom_data_t data = {0};
+										memcpy(&data.data,&board->md_data.rw_data.rw_d.th_out[i],sizeof(threshold_t));
+										data.lenth = sizeof(threshold_t);
+										data.start_addr = eep_base_addr+i*sizeof(threshold_t);
+										board->q_cache.en_queue(&data);
+									}
+									for(uint8_t j = 0; j < RelaySlaveChaNum;j++)
+										board->check_threshold(THRESHOLD_OUT,j);
+
+								}else if(usAddress >= RW_OUT_Com_OVERFUNC_CHN && usAddress < RW_OUT_CTRL_ENABLE)
+								{
+									uint32_t eep_base_addr = EEPROM_OTHER_ADDR+  ( RW_DELAY_CHN_LEN
+																																+RW_Comb_DELAY_CHN_LEN
+																																+RW_Zero_DELAY_CHN_LEN 
+									                                              +RW_IN_THRESHOLD_CHN_LEN
+									                                              +RW_OUT_THRESHOLD_CHN_LEN
+																																+RW_OUT_Com_THRESHOLD_CHN_LEN
+																																+RW_IN_OVERFUNC_CHN_LEN) * 2;									
+#if ((POWER_TYPE == POWER_AC_3_3))
+									for(int i = 0; i < RelaySlaveChaNum;i++)
+									{
+										uint8_t index = i / 3;
+										board->md_data.rw_data.rw_d.over_func_out[i] =board->md_data.rw_data.rw_d.combin_over_func[index] ;
+									}
+#elif ((POWER_TYPE == POWER_AC_3_2))	
+									for(int i = 0; i < PT_SUB_COUNT;i++)
+									{
+										board->md_data.rw_data.rw_d.over_func_out[i] =board->md_data.rw_data.rw_d.combin_over_func[i] ;
+										board->md_data.rw_data.rw_d.over_func_out[i+PT_SUB_COUNT] =board->md_data.rw_data.rw_d.combin_over_func[i];
+									}
+#endif
+									w_eeprom_data_t data = {0};
+									memcpy(&data.data,&board->md_data.rw_data.rw_d.over_func_out[0],RW_OUT_OVERFUNC_CHN_LEN*2);
+									data.lenth = RW_OUT_OVERFUNC_CHN_LEN*2;
+									data.start_addr = eep_base_addr;
+									board->q_cache.en_queue(&data);		
+									
+								}else if(usAddress >= RW_OUT_CTRL_ENABLE && usAddress < RW_RESERVE)
 								{
+									T_cnt = usAddress - RW_OUT_CTRL_ENABLE;
+									
+									for(int i = T_cnt; i < RelaySlaveChaNum;i++)
+									{
+										if(board->md_data.rw_data.rw_d.chn_ctrl[i] == 1)
+										{
+											if(board->md_data.rw_data.rw_d.relay_status[i] != RELAY_OPEN)
+											{
+												async_data da = {0};
+												da.channel = i;
+												da.fire_or_zero = _FIRE;
+												da.method = PROMPT_CTRL;
+												da.reg = &board->relay_staging_staus[i];
+												da.status = RELAY_OPEN;
+												da.w_eep_flag = FLAG_W_EEP;
+												set_relay_sta_async(&da);												
+											}
+										}else if(board->md_data.rw_data.rw_d.chn_ctrl[i] == 2)
+										{
+											if(board->md_data.rw_data.rw_d.relay_status[i] != RELAY_CLOSE)
+											{
+												async_data da = {0};
+												da.channel = i;
+												da.fire_or_zero = _FIRE;
+												da.method = PROMPT_CTRL;
+												da.reg = &board->relay_staging_staus[i];
+												da.status = RELAY_CLOSE;
+												da.w_eep_flag = FLAG_W_EEP;
+												set_relay_sta_async(&da);	
+											}												
+										}
+									}
+								}
+								else{
 									;;
 								}
 								
@@ -338,52 +488,144 @@ eMBRegHoldingCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs, eMBRegi
 							{
 								if(usRegHoldBuf[WiRegIndex] == 1)
 								{
-#if (SURPPORT_2_PT)	
-			#if (!SUPPORT_TWIN_FIRE)
-									for(uint8_t j = 0; j < RelaySlaveChaNum;j++)
+
+#if (POWER_TYPE == POWER_AC_3_2)
+									uint8_t sync_buff[PT_SUB_COUNT] = {0};
+									if(board->md_data.r_data.r_d.detection != 0x3)
 									{
-										if(j >= PT_SUB_COUNT)
+										if(board->md_data.r_data.r_d.detection & 0x1)
 										{
-											if(board->md_data.r_data.r_d.detection & 0x2)
+											for(int i = 0;i < PT_SUB_COUNT;i++)
 											{
-												set_relay_status_async(&board->relay_staging_staus[j],DELAY_CTRL,1);
+												if(board->md_data.rw_data.rw_d.chn_ctrl[i] == 0 && board->md_data.rw_data.rw_d.chn_ctrl[i+PT_SUB_COUNT] == 0)	
+												{
+													continue;
+												}else
+												{
+													if(board->md_data.rw_data.rw_d.chn_ctrl[i] == 0)
+													{
+														async_data da = {0};
+														da.channel = i;
+														da.fire_or_zero = _FIRE;
+														da.method = DELAY_CTRL;
+														da.reg = &board->relay_staging_staus[i];
+														da.status = RELAY_OPEN;
+														da.w_eep_flag = FLAG_W_EEP;
+														set_relay_sta_async(&da);															
+													}
+												}
 											}
-										}else
+										}
+										if(board->md_data.r_data.r_d.detection & 0x2)
 										{
-											if(board->md_data.r_data.r_d.detection & 0x1)
+											for(int i = 0;i < PT_SUB_COUNT;i++)
 											{
-												set_relay_status_async(&board->relay_staging_staus[j],DELAY_CTRL,1);
+												if(board->md_data.rw_data.rw_d.chn_ctrl[i] == 0 && board->md_data.rw_data.rw_d.chn_ctrl[i+PT_SUB_COUNT] == 0)	
+												{
+													continue;
+												}else
+												{
+													if(board->md_data.rw_data.rw_d.chn_ctrl[i+PT_SUB_COUNT] == 0)
+													{
+														async_data da = {0};
+														da.channel = i+PT_SUB_COUNT;
+														da.fire_or_zero = _FIRE;
+														da.method = DELAY_CTRL;
+														da.reg = &board->relay_staging_staus[i+PT_SUB_COUNT];
+														da.status = RELAY_OPEN;
+														da.w_eep_flag = FLAG_W_EEP;
+														set_relay_sta_async(&da);															
+													}
+												}
 											}
 										}
-									}
-			#else
-									for(uint8_t j = 0; j < RelaySlaveChaNum;j += PT_SUB_COUNT)
+									}else
 									{
-										if(board->md_data.r_data.r_d.detection & 0x3)
+										async_data da = {0};
+										for(int i = 0;i < PT_SUB_COUNT;i++)
 										{
-											set_relay_status_async(&board->relay_staging_staus[j],DELAY_CTRL,usRegHoldBuf[WiRegIndex+j]);
-											set_relay_status_async(&board->relay_staging_staus[j+PT_SUB_COUNT],DELAY_CTRL,usRegHoldBuf[WiRegIndex+j]);
+											if(board->md_data.rw_data.rw_d.chn_ctrl[i] == 0)
+											{
+															da.channel = i;
+															da.fire_or_zero = _FIRE;
+															da.method = DELAY_CTRL;
+															da.reg = &board->relay_staging_staus[i];
+															da.status = RELAY_OPEN;
+															da.w_eep_flag = FLAG_W_EEP;
+															set_relay_sta_async(&da);		
+												
+											}
+											if(board->md_data.rw_data.rw_d.chn_ctrl[i+PT_SUB_COUNT] == 0)
+											{
+															da.channel = i+PT_SUB_COUNT;
+															da.fire_or_zero = _FIRE;
+															da.method = DELAY_CTRL;
+															da.reg = &board->relay_staging_staus[i+PT_SUB_COUNT];
+															da.status = RELAY_OPEN;
+															da.w_eep_flag = FLAG_W_EEP;
+															set_relay_sta_async(&da);		
+												
+											}											
 										}
-									}										
-			#endif
+									}
+
 #else
 									for(uint8_t j = 0; j < RelaySlaveChaNum;j++)
 									{
-										if(board->md_data.r_data.r_d.detection)
+										if(board->md_data.rw_data.rw_d.chn_ctrl[j] == 0)
 										{
-											set_relay_status_async(&board->relay_staging_staus[j],DELAY_CTRL,1);
+											async_data da = {0};
+											da.channel =j;
+											da.fire_or_zero = _FIRE;
+											da.method = DELAY_CTRL;
+											da.reg = &board->relay_staging_staus[j];
+											da.status = 1;
+											da.w_eep_flag = FLAG_W_EEP;
+											set_relay_sta_async(&da);
 										}
 									}
-#endif											
+									for(uint8_t j = 0; j < ZERO_CTRL_NUM;j++)
+									{
+										async_data da = {0};
+										da.channel =j;
+										da.fire_or_zero = _ZERO;
+										da.method = DELAY_CTRL;
+										da.reg = &board->relay_zero_staging_status[j];
+										da.status = 1;
+										da.w_eep_flag = FLAG_W_EEP;
+										set_relay_sta_async(&da);										
+									}
+#endif	
 								}
-								
+				
 							}else if(usAddress == W_ALL_OFF)
 							{
 								if(usRegHoldBuf[WiRegIndex] == 1)
 								{
 									for(uint8_t j = 0; j < RelaySlaveChaNum;j++)
 									{
-										set_relay_status_async(&board->relay_staging_staus[j],DELAY_CTRL,0);
+										if(board->md_data.rw_data.rw_d.chn_ctrl[j] == 0)
+										{
+											async_data da = {0};
+											da.channel =j;
+											da.fire_or_zero = _FIRE;
+											da.method = DELAY_CTRL;
+											da.reg = &board->relay_staging_staus[j];
+											da.status = 0;
+											da.w_eep_flag = FLAG_W_EEP;
+											set_relay_sta_async(&da);
+										}
+									}
+									for(uint8_t j = 0; j < ZERO_CTRL_NUM;j++)
+									{
+										async_data da = {0};
+										da.channel =j;
+										da.fire_or_zero = _ZERO;
+										da.method = DELAY_CTRL;
+										da.reg = &board->relay_zero_staging_status[j];
+										da.status = 0;
+										da.w_eep_flag = FLAG_W_EEP;
+										set_relay_sta_async(&da);										
 									}
 								}
 							}else if(usAddress == W_CHN_CONSUMER_CLAEAR)

+ 24 - 62
truing_control/PDU-AC/user/board_cfg.h

@@ -50,60 +50,13 @@
 #define PT_SUB_COUNT_3             3
 #define PT_SUB_COUNT_4             4
 
+#define   PRJ_8_NEW									0
+#define   PRJ_3_4                   0
+#define   PRJ_3_2                   1
 
-#define  	PRJ_4_BASE                0
-#define 	PRJ_4_ALL_O_ALL_C					0
-#define   PRJ_4_SELF_LOCK_SWITCH    0
-#define 	PRJ_6_BASE								0
-#define 	PRJ_8_BASE								0
-#define   PRJ_1_ALL_O_ALL_C         0
-#define   PRJ_1_SELF_LOCK_SWITCH    0
-#define   PRJ_TWIN_FIRE             0
-#define 	PRJ_ITK_8_CHANNEL					0
-#define   PRJ_2_2_BASE              0
-#define   PRJ_8_NEW									1
-#define   PRJ_1_All_OLD             0
-#define   PRJ_7                     0
-#define   PRJ_3_ALL_O_ALL_C         0
-
-
-#if PRJ_4_BASE
-	#define 	RelaySlaveChaNum 					4
-	#define 	SUPPORT_SWITCH_REMENBER		1
-#elif PRJ_4_ALL_O_ALL_C
-	#define 	RelaySlaveChaNum 					4
-	#define   SUPPORT_SWITCH_REMENBER   1
-	#define 	SUPPORT_ALL_ON_OFF        1 
-#elif PRJ_4_SELF_LOCK_SWITCH
-	#define 	RelaySlaveChaNum 					4
-	#define 	SUPPORT_SWITCH_REMENBER		1
-	#define 	SUPPORT_SELF_LOCK         1
-#elif PRJ_6_BASE
-	#define 	RelaySlaveChaNum 					6
-	#define 	SUPPORT_SWITCH_REMENBER		1
-#elif PRJ_8_BASE
-	#define 	RelaySlaveChaNum 					8
-	#define 	SUPPORT_SWITCH_REMENBER		1
-#elif PRJ_1_ALL_O_ALL_C
-	#define 	RelaySlaveChaNum 					1
-	#define 	SUPPORT_SWITCH_REMENBER		1
-	#define 	SUPPORT_ALL_ON_OFF        1
-#elif PRJ_1_SELF_LOCK_SWITCH
-	#define 	RelaySlaveChaNum 					1
-	#define 	SUPPORT_SELF_LOCK         1
-#elif PRJ_TWIN_FIRE
-	#define 	RelaySlaveChaNum 					4
-	#define 	SUPPORT_TWIN_FIRE					1
-	#define 	SUPPORT_SWITCH_REMENBER		1
-#elif PRJ_ITK_8_CHANNEL
-	#define 	RelaySlaveChaNum 					8
-	#define 	SUPPORT_SWITCH_REMENBER		0
-#elif 	PRJ_2_2_BASE
-	#define 	RelaySlaveChaNum 					2
-	#define 	SURPPORT_2_2							1
-	#define   SUPPORT_SWITCH_REMENBER   1
-	#define 	SUPPORT_ALL_ON_OFF        1
-#elif    PRJ_8_NEW					
+
+
+#if PRJ_8_NEW					
 	#define   POWER_TYPE                (POWER_AC)
 	#define   INPUT_PT_NUM              (INPUT_PT_2)
 	#define   ZERO_CONTRL               (ZERO_LINE_CTRL_NO)
@@ -114,17 +67,26 @@
 	#define   SURPPORT_2_PT             1
 	#define 	SUPPORT_ALL_ON_OFF        1
 	#define   PT_SUB_COUNT              (PT_SUB_COUNT_4)
-#elif   PRJ_1_All_OLD
-	#define 	RelaySlaveChaNum 					1
-	#define   SUPPORT_4_KEY             1
-	#define 	ACSingCurrid 							2 
-#elif   PRJ_7
-	#define 	RelaySlaveChaNum 					7
-	#define 	SUPPORT_SWITCH_REMENBER		1
-#elif PRJ_3_ALL_O_ALL_C 
+#elif PRJ_3_4
+	#define   POWER_TYPE                (POWER_AC_3_3)
+	#define   INPUT_PT_NUM              (INPUT_PT_1)
+	#define   ZERO_CONTRL               (ZERO_LINE_CTRL_YES)
+	#define   ZERO_CTRL_NUM             (ZERO_LINE_1)
+	#define   OUTPUT_CONTRL             (OUTPUT_CTRL_YES)
 	#define 	RelaySlaveChaNum 					3
-	#define   SUPPORT_SWITCH_REMENBER   1
 	#define 	SUPPORT_ALL_ON_OFF        1
+	#define 	RELAY_REMENBER						1
+#elif PRJ_3_2             
+	#define   POWER_TYPE                (POWER_AC_3_2)
+	#define   INPUT_PT_NUM              (INPUT_PT_2)
+	#define   ZERO_CONTRL               (ZERO_LINE_CTRL_NO)
+	#define   ZERO_CTRL_NUM             (ZERO_LINE_NONE)
+	#define   OUTPUT_CONTRL             (OUTPUT_CTRL_YES)
+	#define 	RelaySlaveChaNum 					8
+	#define 	SUPPORT_ALL_ON_OFF        1
+	#define 	RELAY_REMENBER						1
+	#define   SURPPORT_2_PT             1
+	#define   PT_SUB_COUNT              (PT_SUB_COUNT_4)
 #endif
 
 

+ 151 - 43
truing_control/PDU-AC/user/main.c

@@ -67,22 +67,72 @@ int main(){
 	flash_get_infomation(&ac_board.md_data.r_data.r_d.b_info);
 	
 	ac_board.detection();
-#if( SURPPORT_2_PT && (!SUPPORT_TWIN_FIRE))
-	if(ac_board.md_data.r_data.r_d.detection & 0x1)
+
+#if (POWER_TYPE  ==  POWER_AC_3_2)
+	if(ac_board.md_data.r_data.r_d.detection == 0x3)
 	{
-		for(uint8_t i = 0; i < PT_SUB_COUNT;i++)
+		for(int i = 0 ; i < PT_SUB_COUNT;i++)
 		{
-			ac_board.handle_status[i] = ac_board.relay_staging_staus[i];
+			if(ac_board.md_data.rw_data.rw_d.chn_ctrl[i] == 0 && ac_board.md_data.rw_data.rw_d.chn_ctrl[i+PT_SUB_COUNT] == 0)
+			{
+				ac_board.handle_status[i] = ac_board.relay_staging_staus[i] & 0x1;
+				ac_board.handle_status[i+PT_SUB_COUNT] = ac_board.relay_staging_staus[i+PT_SUB_COUNT] & 0x1;
+			}else
+			{
+				if(ac_board.md_data.rw_data.rw_d.chn_ctrl[i] == 0 || ac_board.md_data.rw_data.rw_d.chn_ctrl[i] == 1)
+				{
+					ac_board.handle_status[i] = ac_board.relay_staging_staus[i] & 0x1;
+				}else 
+				{
+					ac_board.handle_status[i] = ac_board.relay_staging_staus[i] = 0;
+				}
+				
+				if(ac_board.md_data.rw_data.rw_d.chn_ctrl[i+PT_SUB_COUNT] == 0 || ac_board.md_data.rw_data.rw_d.chn_ctrl[i+PT_SUB_COUNT] == 1)
+				{
+					ac_board.handle_status[i+PT_SUB_COUNT] = ac_board.relay_staging_staus[i+PT_SUB_COUNT] & 0x1;
+				}else 
+				{
+					ac_board.handle_status[i+PT_SUB_COUNT] = ac_board.relay_staging_staus[i+PT_SUB_COUNT] = 0;
+				}
+			}
 		}
-		
-	}
-	if(ac_board.md_data.r_data.r_d.detection & 0x2)
+	}else
 	{
-		for(uint8_t i = PT_SUB_COUNT; i < RelaySlaveChaNum;i++)
+		for(int i = 0 ; i < PT_SUB_COUNT;i++)
 		{
-			ac_board.handle_status[i] = ac_board.relay_staging_staus[i];
-		}		
+			if(ac_board.md_data.rw_data.rw_d.chn_ctrl[i] == 0 && ac_board.md_data.rw_data.rw_d.chn_ctrl[i+PT_SUB_COUNT] == 0)
+			{
+				
+				ac_board.handle_status[i+PT_SUB_COUNT] = ac_board.relay_staging_staus[i+PT_SUB_COUNT] & 0x1;		
+				ac_board.relay_staging_staus[i]	= 0;
+				ac_board.relay_staging_staus[i+PT_SUB_COUNT] = 0;
+			}else
+			{
+				if(ac_board.md_data.r_data.r_d.detection & 0x1)
+				{
+					if(ac_board.md_data.rw_data.rw_d.chn_ctrl[i] == 0 || ac_board.md_data.rw_data.rw_d.chn_ctrl[i] == 1)
+					{
+						ac_board.handle_status[i] = ac_board.relay_staging_staus[i] & 0x1;
+					}else
+					{
+						ac_board.handle_status[i] = ac_board.relay_staging_staus[i] = 0;
+					}
+				}
+				
+				if(ac_board.md_data.r_data.r_d.detection & 0x2)
+				{
+					if(ac_board.md_data.rw_data.rw_d.chn_ctrl[i+PT_SUB_COUNT] == 0 || ac_board.md_data.rw_data.rw_d.chn_ctrl[i+PT_SUB_COUNT] == 1)
+					{
+						ac_board.handle_status[i+PT_SUB_COUNT] = ac_board.relay_staging_staus[i+PT_SUB_COUNT] & 0x1;
+					}else
+					{
+						ac_board.handle_status[i+PT_SUB_COUNT] = ac_board.relay_staging_staus[i+PT_SUB_COUNT] = 0;
+					}
+				}				
+			}
+		}
 	}
+
 #else
 	
 	if(ac_board.md_data.r_data.r_d.detection & 0x1)
@@ -91,6 +141,12 @@ int main(){
 		{
 			ac_board.handle_status[i] = ac_board.relay_staging_staus[i];
 		}
+#if (ZERO_CONTRL  == ZERO_LINE_CTRL_YES)
+		for(uint8_t i = 0; i < ZERO_CTRL_NUM;i++)
+		{
+			ac_board.handle_status_N[i] = ac_board.relay_zero_staging_status[i];
+		}
+#endif
 	}	
 	
 #endif
@@ -113,14 +169,14 @@ int main(){
 	return 0;
 }
 
-
+static uint16_t _count = 0;
 
 static void task_query(void)
 {
 	w_eeprom_data_t data = {0};
 	if(ac_board.q_cache.de_queue(&data))
 	{
-		ac_board.write_eeprom(data.start_addr,&data.data,data.lenth);
+		ac_board.write_eeprom_page(data.start_addr,&data.data,data.lenth);
 	}
 }
 
@@ -129,12 +185,15 @@ static void task_1s(void)
 	static uint8_t channel = 0;
 	if(ac_board.flag_1s)
 	{
-			ac_board.md_data.r_data.r_d.keep_running_time++;
+			ac_board.md_data.r_data.r_d.b_info.keep_running_time++;
 			ac_board.flag_1s = 0;
 			ac_board.led_flash();
 			ac_board.detection();
 			ac_board.read_ele(channel);
 			ac_board.check_wanning(ELE_OUTPUT,channel);
+			ac_board.opt_overfunc(channel);
+
+		
 			channel++;
 			if(channel == RelaySlaveChaNum)
 			{
@@ -147,7 +206,7 @@ static void task_1s(void)
 			uint32_t data_current = 0;
 			uint32_t data_power = 0;
 			uint32_t data_consumer = 0;
-			for(int j =i;j < RelaySlaveChaNum;i+=3)
+			for(int j =i;j < RelaySlaveChaNum;j+=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;
@@ -158,10 +217,52 @@ static void task_1s(void)
 			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.md_data.r_data.r_d.ele_3_in.info[i].resever = ac_board.md_data.r_data.r_d.ele_out[i].resever;
 			ac_board.check_wanning(ELE_INPUT,i);
+			uint32_t sort_buff[3] = {0};
+			
+			uint32_t Vmax = 0;
+			uint32_t Vmin = 0;
+			
+			sort_buff[0] = ac_board.md_data.r_data.r_d.ele_3_in.info[0].voltage;
+			sort_buff[1] = ac_board.md_data.r_data.r_d.ele_3_in.info[1].voltage;
+			sort_buff[2] = ac_board.md_data.r_data.r_d.ele_3_in.info[2].voltage;
+			
+			Vmax = (sort_buff[0] >= sort_buff[1]) ? sort_buff[0] :sort_buff[1];
+			Vmax = (Vmax >= sort_buff[2]) ? Vmax : sort_buff[2];
+			
+			Vmin = (sort_buff[0] <= sort_buff[1]) ? sort_buff[0] :sort_buff[1];
+			Vmin = (Vmin <= sort_buff[2]) ? Vmin : sort_buff[2];	
+				
+			if((Vmin < AC3PPDU_Lack_Voltage) && (Vmax != 0) && (Vmax > (AC3PPDU_Lack_Voltage*2)))
+			{
+				uint32_t v_mid = AC3PPDU_Lack_Voltage *2; 
+				_count ++;
+				if(_count++)
+				{
+					if(ac_board.md_data.r_data.r_d.ele_3_in.info[0].voltage < v_mid)
+					{
+						ac_board.md_data.r_data.r_d.wanning_lock_L1 = 1;
+					}
+					if(ac_board.md_data.r_data.r_d.ele_3_in.info[1].voltage < v_mid)
+					{
+						ac_board.md_data.r_data.r_d.wanning_lock_L2 = 1;
+					}
+					if(ac_board.md_data.r_data.r_d.ele_3_in.info[2].voltage < v_mid)
+					{
+						ac_board.md_data.r_data.r_d.wanning_lock_L3 = 1;
+					}	
+					_count = 0;
+				}
+			}else
+			{
+				ac_board.md_data.r_data.r_d.wanning_lock_L1 = 0;
+				ac_board.md_data.r_data.r_d.wanning_lock_L2 = 0;
+				ac_board.md_data.r_data.r_d.wanning_lock_L3 = 0;
+				_count = 0;
+			}
 		}
-
+		
 #else
 		uint32_t data_voltage = 0;
 	  uint32_t data_current = 0;
@@ -201,7 +302,7 @@ static void task_1s(void)
 
 	#else
 
-			for(int i = 0 ; i < avi;i++)
+			for(int i = 0 ; 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;
@@ -345,17 +446,17 @@ static void relay_ctrl(void)
 				}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]);
+					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{
 					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_COUNTER_END_FLAG(ac_board.relay_zero_staging_status[i]);
+					CLEAR_RL_COUNTER_BEGIN_FLAG(ac_board.relay_zero_staging_status[i]);
+					CLEAR_RL_ON_FLAG(ac_board.relay_zero_staging_status[i]);				
+				  CLEAR_RL_OFF_FLAG(ac_board.relay_zero_staging_status[i]);
 			}
-			CLEAR_RL_ORDER_FLAG(ac_board.relay_staging_staus[i]);
+			CLEAR_RL_ORDER_FLAG(ac_board.relay_zero_staging_status[i]);
 		}		
 	}
 	for(int i = 0; i < RelaySlaveChaNum;i++)
@@ -363,50 +464,57 @@ static void relay_ctrl(void)
 		if(IS_RL_COUNTER_END_FLAG_EN(ac_board.relay_staging_staus[i]))
 		{
 			CLEAR_RL_COUNTER_END_FLAG(ac_board.relay_staging_staus[i]);
-			uint16_t value = 0;
 			if(IS_RL_ON_FLAG_EN(ac_board.relay_staging_staus[i]))
 			{
 				CLEAR_RL_ON_FLAG(ac_board.relay_staging_staus[i]);
-				value = RELAY_OPEN;
 				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);
-				value = RELAY_CLOSE;
 			}
-			//todo insert data to iic flash chache and wait write to eepeom
-			w_eeprom_data_t data = {0};
-			data.lenth =2;
-			memcpy(&data.data,&value,2);
-			data.start_addr = (EEPROM_STATUS_ADDR+(i*2));
-			ac_board.q_cache.en_queue(&data);
 		}
+#if (POWER_TYPE == POWER_AC_3_3)
+		if(((i+1) % 3) == 0)
+		{
+			if(ac_board.md_data.rw_data.rw_d.relay_status[i] == RELAY_OPEN &&
+				ac_board.md_data.rw_data.rw_d.relay_status[i-1] == RELAY_OPEN &&
+				ac_board.md_data.rw_data.rw_d.relay_status[i-2] == RELAY_OPEN)
+			{
+				ac_board.md_data.rw_data.rw_d.combin_relay_status[i/3] = RELAY_OPEN;
+			}else
+			{
+				ac_board.md_data.rw_data.rw_d.combin_relay_status[i/3] = RELAY_CLOSE;
+			}
+		}
+#elif (POWER_TYPE == POWER_AC_3_2)
+		if(i >= PT_SUB_COUNT)
+		{
+			if(ac_board.md_data.rw_data.rw_d.relay_status[i] == RELAY_OPEN 
+				&& ac_board.md_data.rw_data.rw_d.relay_status[i - PT_SUB_COUNT] == RELAY_OPEN)
+			{
+				ac_board.md_data.rw_data.rw_d.combin_relay_status[i-PT_SUB_COUNT] = RELAY_OPEN;
+			}else
+			{
+				ac_board.md_data.rw_data.rw_d.combin_relay_status[i-PT_SUB_COUNT] = RELAY_CLOSE;
+			}
+		}
+#endif
 	}
 	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]);
-			uint16_t value = 0;
 			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);
-				value = RELAY_OPEN;
 			}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);
-				value = RELAY_CLOSE;
 			}
-			//todo insert data to iic flash chache and wait write to eepeom
-			
-			w_eeprom_data_t data = {0};
-			data.lenth =2;
-			memcpy(&data.data,&value,2);
-			data.start_addr = (EEPROM_STATUS_ADDR+((13+i)*2));
-			ac_board.q_cache.en_queue(&data);
 		}
 	}
 }