Kaynağa Gözat

新寄存器,增加耗电量存储,产生告警,延时开关等代码。

liyi 1 yıl önce
ebeveyn
işleme
e9a7f95f25

+ 107 - 9
truing_control/PDU-AC/common/common.c

@@ -1,7 +1,12 @@
 #include "common.h"
 #include "board_cfg.h"
 
+#if EEPROM_TEST		
 
+#define TEST_ADDR  (120 * 32)
+#define LENTH      (32)
+
+#endif
 
 
 void read_config_from_eeprom(void)
@@ -11,23 +16,56 @@ void read_config_from_eeprom(void)
 	{
 		uint16_t device = 0;
 		board->read_eeprom(EEPROM_DEVICES_ADDR,(uint8_t *)&device,EEPROM_DEVICES_LENTH);
+
+#if EEPROM_TEST		
+		uint8_t test_buff[32] ={0};
+		for(int i =0;i < 32;i++)
+			test_buff[i]=i;
+		board->write_eeprom_page(TEST_ADDR,test_buff,LENTH);
+		
+		for(int i =0;i < 32;i++)
+			test_buff[i]=0;
+		board->read_eeprom_page(TEST_ADDR,test_buff,LENTH);
+		
+#endif
+		
+		
 		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);
+			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);
 			//config phase information
 			uint8_t buff[EEPROM_CHANNEL_LENTH] = {0};
-			board->write_eeprom(EEPROM_CHANNEL_PHASE,buff,EEPROM_CHANNEL_LENTH);
-		}else
+			board->write_eeprom_page(EEPROM_CHANNEL_PHASE,buff,EEPROM_CHANNEL_LENTH);
+			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->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);
+			//channel open or close
+			board->read_eeprom_page(EEPROM_STATUS_ADDR,(uint8_t *)&board->relay_staging_staus[0],2*RelaySlaveChaNum);
+			{
+				for(int i =0 ;i < RelaySlaveChaNum;i++)
+				{
+					if(board->relay_staging_staus[i])
+					{
+						SET_RL_ON_DELAY_FLAG(board->relay_staging_staus[i]);
+						CLEAR_RL_OFF_DELAY_FLAG(board->relay_staging_staus[i]);
+						SET_RL_ORDER_FLAG(board->relay_staging_staus[i]);
+					}
+				}
+			}
+			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);
 						//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
+			board->read_eeprom_page(EEPROM_CHANNEL_PHASE,buff,EEPROM_CHANNEL_LENTH);
+#if (POWER_TYPE == POWER_AC_3_3)
 			for(int i = 0; i < 3; i++)
 			{
 				board->check_threshold(THRESHOLD_IN,i);
@@ -43,6 +81,66 @@ 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);
 			}
+			iic_data chache={0};
+			for(int i = 0 ; i < MAX_ROW;i++)
+			{
+				board->read_eeprom_page(EEPROM_CONSUMER_ADDR +(CONSUM_PAGE*i),&chache,sizeof(iic_data));
+				if(board->con_da.index > chache.iic_con.recode_index1)
+				{
+					
+				}else
+				{
+					board->con_da.index = chache.iic_con.recode_index1;
+					board->con_da.row = i;
+				}
+			}	
+			board->read_eeprom_page(EEPROM_CONSUMER_ADDR +(CONSUM_PAGE*(board->con_da.row)),&chache,sizeof(iic_data));
+			for(int i = 0 ; i < RelaySlaveChaNum;i++)
+				board->md_data.r_data.r_d.ele_out[i].consumer = chache.iic_con.iic_consumer[i];
+			board->con_da.row++;      //point next write row
+			if(board->con_da.row >= MAX_ROW)
+			{
+				board->con_da.row = 0;
+			}
+			board->con_da.index++;		//point next write consumer index
+			if(board->con_da.index > 0XFFFFFFFFFFFFFFFF)
+			{
+				iic_data chache1={0};
+				board->con_da.index = 0;
+				for(int i = 0 ; i < MAX_ROW;i++)
+					board->write_eeprom_page(EEPROM_CONSUMER_ADDR +(CONSUM_PAGE*i),&chache1,CONSUM_PAGE);
+			}
 		}
 	}
 }
+
+
+void set_relay_status_async(uint16_t *reg,uint8_t method,uint16_t status)
+{
+	board_t *board = get_board();
+	SET_RL_STATUS(*reg,status);
+	if(method == DELAY_CTRL)
+	{
+		if(status)
+		{
+			SET_RL_ON_DELAY_FLAG(*reg);
+			CLEAR_RL_OFF_DELAY_FLAG(*reg);
+		}else
+		{
+			CLEAR_RL_ON_DELAY_FLAG(*reg);
+			SET_RL_OFF_DELAY_FLAG(*reg);
+		}
+	}else 
+	{
+		 if(status)
+		 {
+			 CLEAR_RL_ON_DELAY_FLAG(*reg);
+			 CLEAR_RL_OFF_DELAY_FLAG(*reg);
+		 }else
+		 {
+			 CLEAR_RL_ON_DELAY_FLAG(*reg);
+			 CLEAR_RL_OFF_DELAY_FLAG(*reg);
+		 }
+	}
+	SET_RL_ORDER_FLAG(*reg);
+}

+ 44 - 7
truing_control/PDU-AC/common/common.h

@@ -25,6 +25,7 @@
 
 #define START_RW_REGISTER         				(START_R_REGISTER + START_R_LENTH)
 
+
 #define START_RW_LENTH            				(350)
 
 
@@ -196,6 +197,11 @@
 #define EEPROM_CHANNEL_LENTH                  (9)
 
 
+#define CONSUM_PAGE                           (64)
+#define MAX_ROW                               (40)
+
+#define EEPROM_CONSUMER_ADDR                  (3072)
+#define EEPROM_CONSUMER_ADDR_LEN              (CONSUM_PAGE*MAX_ROW)
 
 
 #define THRESHOLD_IN             							0
@@ -237,6 +243,8 @@
 #define IS_RL_OFF_DELAY_FLAG_EN(reg) 						 (reg & RL_OFF_DELAY_FLAG)
 
 
+#define SET_RL_STATUS(reg,value)                  ((reg) = ((value) ? ((reg) | 1) : ((reg) & (~1))))
+
 #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 )
@@ -256,6 +264,13 @@
 
 
 
+enum{
+	DELAY_CTRL = 0,
+	PROMPT_CTRL,
+};
+
+
+
 #pragma pack (2)
 typedef struct {
 	uint32_t uniq_3;
@@ -344,8 +359,29 @@ typedef struct {
 	mod_bus_rw rw_data;
 }mod_data_t;
 
+
+typedef struct {
+	uint32_t iic_consumer[MAX_CHANNEL];
+	uint64_t recode_index1;
+}iic_consumer_chache_t;
+
+typedef struct{
+	uint8_t  data[64];
+	iic_consumer_chache_t iic_con;
+}iic_data;
+
+
+
+
+
 #pragma pack ()
 
+typedef struct{
+	iic_data   iic_da;
+	uint64_t   index;
+	uint16_t   row;
+}consumer_data;
+
 
 typedef struct {
 	uint8_t flag;
@@ -363,7 +399,7 @@ typedef struct {
 
 
 typedef struct {
-#define QUEUE_MAX     10
+#define QUEUE_MAX     20
 	uint8_t  front;
 	uint8_t  rear;
 	w_eeprom_data_t data[QUEUE_MAX];
@@ -377,11 +413,9 @@ typedef struct {
 
 typedef struct {
 	mod_data_t md_data;
-	uint8_t 	flag_1s;													
-	uint8_t   eeprom_write_flag;
-	uint8_t   jlink_flag;																				/* jugement jlink insert and programe process       */
+	uint8_t 	flag_1s;
+	uint8_t	  flag_10s;
 	uint8_t   erase_consumer_flag; 															/* erase consumer and all successful this flag is 0 */
-	uint8_t   write_eeprom_index;
 	uint8_t   out_wanning_en[MAX_CHANNEL];
 	uint8_t   in_wanning_en[MAX_INPUT_CAHNNEL];
 	uint8_t   over_func[MAX_CHANNEL];
@@ -390,7 +424,7 @@ typedef struct {
 	uint16_t  relay_zero_staging_status[3];
 	uint16_t  relay_limit_counter[MAX_CHANNEL];
 	uint16_t  relay_zero_limit_counter[3];
-
+	consumer_data con_da;
 	uint8_t   haddr;
 	uint8_t   detection_1_value;
 	uint32_t  detection_1_count;
@@ -469,10 +503,13 @@ typedef struct {
 	void (*unlock)();
 	void (*check_threshold)(uint8_t in_out,uint8_t channel);
 	void (*relay_sync)();
+	void (*read_eeprom_page)(uint16_t addr,uint8_t *r_buff,uint16_t lenth);
+	void (*write_eeprom_page)(uint16_t addr,uint8_t *r_buff,uint16_t lenth);
 }board_t;
 
 
 board_t *get_board();
-
+void set_relay_status_async(uint16_t *reg,uint8_t method,uint16_t status);
+void read_config_from_eeprom(void);
 #endif
 

+ 38 - 38
truing_control/PDU-AC/hardware/detection/detection.c

@@ -200,20 +200,18 @@ static void detection_opt(void)
 				if(board->handle_input_pt[0] == 0)
 				{
 					board->handle_input_pt[0] = 1;
-					uint8_t val = (RelaySlaveChaNum % 2) ? (RelaySlaveChaNum / 2 + 1) : (RelaySlaveChaNum / 2);
-					for(uint8_t k = 0; k < val;k++)
+//					uint8_t val = (RelaySlaveChaNum % 2) ? (RelaySlaveChaNum / 2 + 1) : (RelaySlaveChaNum / 2);
+//					uint16_t value = 0;
+					for(uint8_t k = 0; k < PT_SUB_COUNT;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->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);
 					}
 					
 				}
@@ -221,14 +219,17 @@ static void detection_opt(void)
 			{
 				if(board->handle_input_pt[0] == 1)
 				{
-					uint8_t val = (RelaySlaveChaNum % 2) ? (RelaySlaveChaNum / 2 + 1) : (RelaySlaveChaNum/2);
-					for(uint8_t k = 0; k < val;k++)
+//					uint8_t val = (RelaySlaveChaNum % 2) ? (RelaySlaveChaNum / 2 + 1) : (RelaySlaveChaNum/2);
+//					uint16_t value = RELAY_CLOSE;
+					for(uint8_t k = 0; k < PT_SUB_COUNT;k++)
 					{
 						board->handle_status[k] = board->md_data.rw_data.rw_d.relay_status[k];
-						board->relay_staging_staus[k] = RELAY_CLOSE;
-						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]);
+						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_input_pt[0] = 0;
 				}
@@ -238,34 +239,33 @@ static void detection_opt(void)
 				if(board->handle_input_pt[1] == 0)
 				{
 					board->handle_input_pt[1] = 1;
-					uint8_t val = (RelaySlaveChaNum % 2) ? (RelaySlaveChaNum / 2 + 1) : (RelaySlaveChaNum/2);
-					for(uint8_t k = val; k < RelaySlaveChaNum;k++)
+//					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->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]);
+						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);
 					}
 				}
 			}else
 			{
 				if(board->handle_input_pt[1] == 1)
 				{
-					uint8_t val = (RelaySlaveChaNum % 2) ? (RelaySlaveChaNum / 2 + 1) : (RelaySlaveChaNum/2);
-					for(uint8_t k = val; k < RelaySlaveChaNum;k++)
+//					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_status[k] = board->md_data.rw_data.rw_d.relay_status[k];
-						board->relay_staging_staus[k] = RELAY_CLOSE;
-						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]);					
+						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_input_pt[1] = 0;
 				}

+ 129 - 16
truing_control/PDU-AC/hardware/eeprom/eeprom.c

@@ -7,12 +7,13 @@
 #define ACK       1   
 #define NACK      0   
 
-#define IIC_WP_PIN          GPIO_PIN_13
+#define IIC_WP_PIN          GPIO_PIN_15
 
 #define IIC_DATA_IO         GPIOF
 #define IIC_SDA_PIN         GPIO_PIN_0
 #define IIC_SCL_PIN         GPIO_PIN_1
-
+#define PAGE_SZIE_32        (32)
+#define PAGE_SIZE_16        (16)
 
 
 #define IIC_READ_SDA()      gpio_input_bit_get(IIC_DATA_IO, IIC_SDA_PIN) 
@@ -34,6 +35,7 @@
 #define AT24C256   32767
 
 #define USER_DEFINE_EEPROM_TYPE    AT24C64 
+#define PAGE_SIZE                  PAGE_SZIE_32
 
 
 
@@ -55,7 +57,10 @@ static void         eeprom_write(uint16_t w_addr,uint8_t *data,uint16_t lenth);
 static void         eeprom_read(uint16_t r_addr,uint8_t *data,uint16_t lenth);
 static void 				check_threshold(uint8_t in_out,uint8_t channel);
 
-
+static void 				eeprom_page_read(uint16_t addr,uint8_t *data,uint16_t lenth);
+static void         eeprom_write_page(uint16_t addr,uint8_t *data,uint16_t chuank);
+static void 				eeprom_auto_page_write(uint16_t addr,uint8_t *data,uint16_t lenth);
+static void 				eeprom_auto_page_read(uint16_t addr,uint8_t *data,uint16_t lenth);
 static inline void iic_set_sda_input()
 {
 	gpio_mode_set(IIC_DATA_IO, GPIO_MODE_INPUT, GPIO_PUPD_NONE, IIC_SDA_PIN);
@@ -76,15 +81,17 @@ void eeprom_init(void)
 	board->read_eeprom = eeprom_read;
 	board->write_eeprom = eeprom_write;
 	board->check_threshold = check_threshold;
+	board->read_eeprom_page = eeprom_auto_page_read;
+	board->write_eeprom_page = eeprom_auto_page_write;
 }
 
 
 static void iic_init(void)
 {
 	rcu_periph_clock_enable(RCU_GPIOC);
-	gpio_mode_set(GPIOC, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO_PIN_13);
-	gpio_output_options_set(GPIOC, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_13);		  				/* WP */
-	gpio_bit_reset(GPIOC, GPIO_PIN_13);
+	gpio_mode_set(GPIOC, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO_PIN_15);
+	gpio_output_options_set(GPIOC, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_15);		  				/* WP */
+	gpio_bit_reset(GPIOC, GPIO_PIN_15);
 	
 	rcu_periph_clock_enable(RCU_GPIOF);
 	gpio_mode_set(IIC_DATA_IO, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO_PIN_0);
@@ -146,9 +153,9 @@ static void iic_send_byte(uint8_t data)
 {
 	iic_set_sda_output();
 	IIC_SCL_CLR;
-	uint8_t t = 8;
-	do{
-		if(data & 0x80)
+	uint8_t t;
+	for(t = 0; t < 8; t++){
+		if((data & 0x80) >> 7)
 		{
 			IIC_SDA_SET;
 		}else
@@ -161,7 +168,7 @@ static void iic_send_byte(uint8_t data)
 		DelayNus(2);
 		IIC_SCL_CLR;
 		DelayNus(2);
-	}while(--t);
+	}
 }
 /*****************************************************************************************
 *          						read 1 byte
@@ -174,20 +181,21 @@ static void iic_send_byte(uint8_t data)
 ******************************************************************************************/
 static uint8_t iic_read_byte(uint8_t ack)
 {
-	uint8_t t = 8;
+	uint8_t i;
 	uint8_t receive = 0;
 	iic_set_sda_input();
-	do{
+	for(i = 0; i < 8; i++ ){
 		IIC_SCL_CLR;
 		DelayNus(2);
 		IIC_SCL_SET;
+		receive <<= 1;
+		
 		if(IIC_READ_SDA())
 		{
-			receive |= 1;
+			receive ++;
 		}
-		receive <<= 1;
 		DelayNus(1);
-	}while(--t);
+	}
 	if(NACK == ack)
 	{
 		iic_send_nack();
@@ -208,6 +216,8 @@ static uint8_t iic_wait_ack(void)
 {
 	uint8_t err_time = 0;
 	iic_set_sda_input();
+	IIC_SCL_SET;
+	DelayNus(1);
 	while(IIC_READ_SDA())
 	{
 		err_time++;
@@ -376,7 +386,7 @@ static void check_threshold(uint8_t in_out,uint8_t channel)
 			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]);
+				SET_VOLTAGE_MAX_EN(board->out_wanning_en[channel]);
 			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 
@@ -399,3 +409,106 @@ static void check_threshold(uint8_t in_out,uint8_t channel)
 		}
 	}
 }
+static void eeprom_page_read(uint16_t addr,uint8_t *data,uint16_t lenth)
+{
+   if(lenth == 0 || lenth > PAGE_SIZE || ((addr % PAGE_SIZE) + lenth > PAGE_SIZE))
+   {
+      return;
+   }
+	iic_start_signal();
+	if(USER_DEFINE_EEPROM_TYPE > AT24C16)
+	{
+		iic_send_byte(0XA0);
+		iic_wait_ack();
+		iic_send_byte(addr >> 8);
+	}else
+	{
+		iic_send_byte(0XA0 + ((addr / 256) << 1));
+	}
+	iic_wait_ack();
+	iic_send_byte(addr % 256);
+	iic_wait_ack();
+	iic_start_signal();
+	iic_send_byte(0XA1);
+	iic_wait_ack();
+	
+	for(int i = 0; i < lenth;i++)
+	{
+		if(i == lenth -1)
+		{
+			data[i] = iic_read_byte(0);
+		}else
+		{
+			data[i] = iic_read_byte(1);
+		}
+	}
+	
+	iic_stop_signal();
+}
+
+static void eeprom_write_page(uint16_t addr,uint8_t *data,uint16_t chuank)
+{
+	  if(chuank == 0 || chuank > PAGE_SIZE || ((addr % PAGE_SIZE) + chuank > PAGE_SIZE))
+    {
+        return;
+    }
+
+	iic_start_signal();
+	if(USER_DEFINE_EEPROM_TYPE > AT24C16)
+	{
+		iic_send_byte(0XA0);
+		iic_wait_ack();
+		iic_send_byte(addr >> 8);
+	}else
+	{
+		iic_send_byte(0XA0 + ((addr / 256) << 1));
+	}
+	iic_wait_ack();
+	iic_send_byte(addr % 256);
+	iic_wait_ack();	
+	for(uint16_t i = 0; i < chuank;i++)
+	{
+		iic_send_byte(data[i]);
+		iic_wait_ack();
+	}
+	iic_stop_signal();
+	DelayNms(7);
+}
+
+
+
+
+static void eeprom_auto_page_write(uint16_t addr,uint8_t *data,uint16_t lenth)
+{
+    uint16_t remaining = lenth;
+    uint8_t *p = data;
+    
+    while(remaining > 0)
+    {
+        uint8_t chunk = PAGE_SIZE - (addr % PAGE_SIZE);
+        if(chunk > remaining) chunk = remaining;
+        eeprom_write_page(addr, p,chunk);
+        addr += chunk;
+        p += chunk;
+        remaining -= chunk;
+    }	
+}
+
+
+static void eeprom_auto_page_read(uint16_t addr,uint8_t *data,uint16_t lenth)
+{
+    uint16_t remaining = lenth;
+    uint8_t *p = data;
+    
+    while(remaining > 0)
+    {
+        uint8_t chunk = PAGE_SIZE - (addr % PAGE_SIZE);
+        if(chunk > remaining) chunk = remaining;
+        
+        eeprom_page_read(addr, p, chunk);
+         
+        addr += chunk;
+        p += chunk;
+        remaining -= chunk;
+    }
+}

+ 17 - 3
truing_control/PDU-AC/hardware/electricity/electricity.c

@@ -47,6 +47,20 @@ static void read_ele(uint8_t channel)
 		board->md_data.r_data.r_d.ele_out[channel].freq = F_AC_LINE_Freq * 100;
 		board->md_data.r_data.r_d.ele_out[channel].factor = F_AC_PF * 100;
 		board->md_data.r_data.r_d.ele_out[channel].consumer += F_AC_E * 1000;
+
+		if(board->md_data.r_data.r_d.ele_out[channel].voltage < 100)
+		{
+			board->md_data.r_data.r_d.ele_out[channel].voltage = 0;
+			board->md_data.r_data.r_d.ele_out[channel].current = 0;
+			board->md_data.r_data.r_d.ele_out[channel].power = 0;
+			board->md_data.r_data.r_d.ele_out[channel].factor = 0;
+			board->md_data.r_data.r_d.ele_out[channel].freq = 0;
+		}else if(board->md_data.r_data.r_d.ele_out[channel].factor < 1)
+		{
+			board->md_data.r_data.r_d.ele_out[channel].current = 0;
+			board->md_data.r_data.r_d.ele_out[channel].power = 0;
+			board->md_data.r_data.r_d.ele_out[channel].factor = 0;
+		}
 	}
 }
 
@@ -71,7 +85,7 @@ static void check_wanning(uint8_t in_out,uint8_t channel)
 				UNSET_WANNING_VOLTAGE_MIN(board->md_data.r_data.r_d.ele_3_in.info[channel].wanning);
 			}
 			if(IS_CURRENT_MAX_EN(board->in_wanning_en[channel]) && 
-							board->md_data.r_data.r_d.ele_3_in.info[channel].current < board->md_data.rw_data.rw_d.th_in[channel].th_current_max)
+							board->md_data.r_data.r_d.ele_3_in.info[channel].current > board->md_data.rw_data.rw_d.th_in[channel].th_current_max)
 			{
 				SET_WANNING_CURRENT_MAX(board->md_data.r_data.r_d.ele_3_in.info[channel].wanning);
 			}else
@@ -79,7 +93,7 @@ static void check_wanning(uint8_t in_out,uint8_t channel)
 				UNSET_WANNING_CURRENT_MAX(board->md_data.r_data.r_d.ele_3_in.info[channel].wanning);
 			}			
 			if(IS_POWER_MAX_EN(board->in_wanning_en[channel]) && 
-							board->md_data.r_data.r_d.ele_3_in.info[channel].power < board->md_data.rw_data.rw_d.th_in[channel].th_power_max)
+							board->md_data.r_data.r_d.ele_3_in.info[channel].power > board->md_data.rw_data.rw_d.th_in[channel].th_power_max)
 			{
 				SET_WANNING_POWER_MAX(board->md_data.r_data.r_d.ele_3_in.info[channel].wanning);
 			}else
@@ -88,7 +102,7 @@ static void check_wanning(uint8_t in_out,uint8_t channel)
 			}			
 			
 			if(IS_CONSUMER_MAX_EN(board->in_wanning_en[channel]) && 
-							board->md_data.r_data.r_d.ele_3_in.info[channel].consumer < board->md_data.rw_data.rw_d.th_in[channel].th_consumer_max)
+							board->md_data.r_data.r_d.ele_3_in.info[channel].consumer > board->md_data.rw_data.rw_d.th_in[channel].th_consumer_max)
 			{
 				SET_WANNING_CONSUMER_MAX(board->md_data.r_data.r_d.ele_3_in.info[channel].wanning);
 			}else

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

@@ -18,10 +18,10 @@ static timer14_config(uint16_t arr,uint16_t psc);
 static void relay_remember(void);
 
 static  uint16_t count_1s = 0;
-static  uint16_t count_3s = 0;
+static  uint16_t count_10s = 0;
 
-static uint16_t rl_delay_cnt[RelaySlaveChaNum] = {0};
-static uint16_t rl_delay_zero_cnt[ZERO_CTRL_NUM] = {0};
+uint16_t rl_delay_cnt[RelaySlaveChaNum] = {0};
+uint16_t rl_delay_zero_cnt[ZERO_CTRL_NUM] = {0};
 
 
 void time_init(void)
@@ -107,11 +107,11 @@ void TIMER14_IRQHandler(void)
 		{
 			board->flag_1s = 1;
 			count_1s = 0;
-			count_3s ++;
-			if(count_3s == 3)
+			count_10s ++;
+			if(count_10s == 10)
 			{
-				board->eeprom_write_flag = 1;
-				count_3s = 0;
+				board->flag_10s = 1;
+				count_10s = 0;
 			}
 		}
 	}

+ 205 - 36
truing_control/PDU-AC/modbus/BARE/port/port.c

@@ -117,18 +117,75 @@ unsigned int WiRegIndex;
 
 
 
-//uint32_t Modbus_Wr_buff[Mb_Wcmd_Width][Mb_Wcmd_len] = {0};
-uint8_t cmd_cnt = 0;
 
-//extern uint8_t md_status;
+#define RW_RELAY_CHN_STU            			(START_RW_REGISTER)
+#define RW_RELAY_CHN_STU_LEN              (9)
+
+#define RW_Com_RELAY_CHN_STU              (RW_RELAY_CHN_STU+RW_RELAY_CHN_STU_LEN)
+#define RW_Com_RELAY_CHN_STU_LEN          (4)
+
+
+#define RW_Zero_RELAY_CHN_STU             (RW_Com_RELAY_CHN_STU + RW_Com_RELAY_CHN_STU_LEN)
+#define RW_Zero_RELAY_CHN_STU_LEN         (3)
+
+
+#define RW_DELAY_CHN                     (RW_Zero_RELAY_CHN_STU + RW_Zero_RELAY_CHN_STU_LEN)
+#define RW_DELAY_CHN_LEN                 (9*2)
+
+#define RW_Comb_DELAY_CHN                (RW_DELAY_CHN + RW_DELAY_CHN_LEN)
+#define RW_Comb_DELAY_CHN_LEN            (4*2)
+
+#define RW_Zero_DELAY_CHN                (RW_Comb_DELAY_CHN + RW_Comb_DELAY_CHN_LEN)
+#define RW_Zero_DELAY_CHN_LEN            (3*2)
+
+#define RW_IN_THRESHOLD_CHN              (RW_Zero_DELAY_CHN + RW_Zero_DELAY_CHN_LEN)
+#define RW_IN_THRESHOLD_CHN_LEN          (7*3*2)
+
+#define RW_OUT_THRESHOLD_CHN						 (RW_IN_THRESHOLD_CHN+RW_IN_THRESHOLD_CHN_LEN)
+#define RW_OUT_THRESHOLD_CHN_LEN         (7*9*2)
+
+#define RW_OUT_Com_THRESHOLD_CHN         (RW_OUT_THRESHOLD_CHN + RW_OUT_THRESHOLD_CHN_LEN)
+#define RW_OUT_Com_THRESHOLD_CHN_LEN     (7*4*2)
+
+
+#define RW_IN_OVERFUNC_CHN               (RW_OUT_Com_THRESHOLD_CHN + RW_OUT_Com_THRESHOLD_CHN_LEN)
+#define RW_IN_OVERFUNC_CHN_LEN           (3)
+
+#define RW_OUT_OVERFUNC_CHN              (RW_IN_OVERFUNC_CHN + RW_IN_OVERFUNC_CHN_LEN)
+#define RW_OUT_OVERFUNC_CHN_LEN          (9)
+
+#define RW_OUT_Com_OVERFUNC_CHN          (RW_OUT_OVERFUNC_CHN + RW_OUT_OVERFUNC_CHN_LEN)
+#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 W_ALL_ON                         (START_W_REGISTER)
+#define W_ALL_ON_LEN                     (1)
+
+#define W_ALL_OFF                        (W_ALL_ON + W_ALL_ON_LEN)
+#define W_ALL_OFF_LEN                    (1)
+
+#define W_CHN_CONSUMER_CLAEAR            (W_ALL_OFF + W_ALL_OFF_LEN)
+#define W_CHN_CONSUMER_CLAEAR_LEN        (1)
+
+#define W_CLEAR_CONFIG               		 (W_CHN_CONSUMER_CLAEAR + W_CHN_CONSUMER_CLAEAR_LEN)
+#define W_CLEAR_CONFIG_LEN               (1)
+
+#define W_SOFT_RESET                     (W_CLEAR_CONFIG + W_CLEAR_CONFIG_LEN)
+#define W_SOFT_RESET_LEN                 (1)
+
+#define W_BREAK_UPGRAGE                  (W_SOFT_RESET + W_SOFT_RESET_LEN)
+#define W_BREAK_UPGRAGE_LEN              (1)
+
+#define W_SET_PH_INFO                    (W_BREAK_UPGRAGE + W_BREAK_UPGRAGE_LEN)
+#define W_SET_PH_INFO_LEN                (1)
+
 
-//extern uint8_t AC3PPDU_SlaveAddress;
-//extern uint32_t AC3PPDU_Modbus_Reg[AC3PPDU_Modbus_Reg_len];
-//extern information_t infomation;
 
 
-#define  AC_1_STATUS 0
-#define  AC_9_STATUS 8
 
 eMBErrorCode
 eMBRegHoldingCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs, eMBRegisterMode eMode )
@@ -153,7 +210,7 @@ eMBRegHoldingCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs, eMBRegi
 							 {
 								 usNRegs = (START_W_REGISTER - T_cnt);
 							 }
-							 memcpy(&usRegHoldBuf[iRegIndex],(void *)(&(board->md_data) + T_cnt),usNRegs * 2);
+							 memcpy(&usRegHoldBuf[iRegIndex],(void *)(((uint16_t*)&(board->md_data)) + T_cnt),usNRegs * 2);
 						 }else
 						 {
 							 eStatus = MB_ENOREG;
@@ -179,47 +236,159 @@ eMBRegHoldingCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs, eMBRegi
 							usNRegs--;
 						}
 						{
-							if(usAddress >= START_RW_REGISTER && usAddress < START_W_REGISTER)
+							
+							if(usAddress >= RW_RELAY_CHN_STU && usAddress < RW_Com_RELAY_CHN_STU)   										//
 							{
-								T_cnt = usAddress - START_RW_REGISTER;
-
-								switch(T_cnt)
+								T_cnt = usAddress - RW_RELAY_CHN_STU;
+#if (SURPPORT_2_PT )			
+		#if (!SUPPORT_TWIN_FIRE)
+								for(uint8_t j = 0; j < WusNRegs;j++)
 								{
-									case AC_1_STATUS ... AC_9_STATUS:			//
+									if(T_cnt >= PT_SUB_COUNT)
 									{
-										WusNRegs =	(WusNRegs > (9 - T_cnt)) ? (9 - T_cnt) : WusNRegs;
-										memcpy((uint8_t *)(&board->relay_staging_staus[0]+T_cnt),usRegHoldBuf[iRegIndex],WusNRegs * 2);
-										board->relay_sync();
-										w_eeprom_data_t data = {0};
-										data.lenth = WusNRegs * 2;
-										data.start_addr = (EEPROM_DELAY_ADDR+(T_cnt*2));
-										memcpy(&data.data,usRegHoldBuf[iRegIndex],WusNRegs * 2);
-										board->q_cache.en_queue(&data);
-									}
-										break;
-
-									case 9 ... 14:				//3 ph
+										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
 									{
+										if(board->md_data.r_data.r_d.detection & 0x1)
+										{
+											set_relay_status_async(&board->relay_staging_staus[j+T_cnt],PROMPT_CTRL,usRegHoldBuf[WiRegIndex+j]);
+										}
 									}
-									break;
-									default:
+								}
+		#else
+								for(uint8_t j = 0; j < WusNRegs;j += PT_SUB_COUNT)
+								{
+									if(board->md_data.r_data.r_d.detection & 0x3)
 									{
-										memcpy((uint8_t *)(&board->md_data.rw_data.rw_d.delay_chn[0]+T_cnt),usRegHoldBuf[iRegIndex],WusNRegs * 2);
+										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]);
 									}
-										break;
-
+								}
+								
+		#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;
+							}else if(usAddress >= RW_Zero_RELAY_CHN_STU && usAddress < RW_DELAY_CHN)
+							{
+								// todo
+								T_cnt = usAddress - RW_Zero_RELAY_CHN_STU;
+							}else if(usAddress >= RW_DELAY_CHN && usAddress < RW_RESERVE)
+							{
+								T_cnt = usAddress - RW_DELAY_CHN;
+								memcpy((void *)((uint16_t*)(&board->md_data.rw_data.rw_d.delay_chn[0])+T_cnt),&usRegHoldBuf[WiRegIndex],WusNRegs * 2);
+								w_eeprom_data_t data = {0};
+								data.lenth =WusNRegs*2;
+								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)
+								{
+									board->check_threshold(THRESHOLD_IN,0);
+									board->check_threshold(THRESHOLD_IN,1);
+									board->check_threshold(THRESHOLD_IN,2);
+								}else if(usAddress >= RW_OUT_THRESHOLD_CHN && usAddress < RW_OUT_Com_THRESHOLD_CHN)
+								{
+									for(uint8_t j = 0; j < RelaySlaveChaNum;j++)
+										board->check_threshold(THRESHOLD_OUT,j);
+								}else if(usAddress >= RW_OUT_Com_THRESHOLD_CHN && usAddress < RW_IN_OVERFUNC_CHN)
+								{
+									//conbin  to do
+								}else
+								{
+									;;
+								}
+								
+							}else if(usAddress == W_ALL_ON)		//write
+							{
+								if(usRegHoldBuf[WiRegIndex] == 1)
+								{
+#if (SURPPORT_2_PT)	
+			#if (!SUPPORT_TWIN_FIRE)
+									for(uint8_t j = 0; j < RelaySlaveChaNum;j++)
+									{
+										if(j >= PT_SUB_COUNT)
+										{
+											if(board->md_data.r_data.r_d.detection & 0x2)
+											{
+												set_relay_status_async(&board->relay_staging_staus[j],DELAY_CTRL,1);
+											}
+										}else
+										{
+											if(board->md_data.r_data.r_d.detection & 0x1)
+											{
+												set_relay_status_async(&board->relay_staging_staus[j],DELAY_CTRL,1);
+											}
+										}
+									}
+			#else
+									for(uint8_t j = 0; j < RelaySlaveChaNum;j += PT_SUB_COUNT)
+									{
+										if(board->md_data.r_data.r_d.detection & 0x3)
+										{
+											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]);
+										}
+									}										
+			#endif
+#else
+									for(uint8_t j = 0; j < RelaySlaveChaNum;j++)
+									{
+										if(board->md_data.r_data.r_d.detection)
+										{
+											set_relay_status_async(&board->relay_staging_staus[j],DELAY_CTRL,1);
+										}
+									}
+#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);
+									}
 								}
-								cmd_cnt ++;
-								if(cmd_cnt == 16)
+							}else if(usAddress == W_CHN_CONSUMER_CLAEAR)
+							{
+								for(uint8_t j = 0; j < RelaySlaveChaNum;j++)
 								{
-									cmd_cnt = 0;
+									if(j == usRegHoldBuf[WiRegIndex]){
+										board->md_data.r_data.r_d.ele_out[j].consumer = 0;
+										break;
+									}
 								}
-							}else
+							}else if(usAddress == W_CLEAR_CONFIG)
+							{
+								
+							}else if(usAddress == W_SOFT_RESET)
+							{
+								
+							}else if(usAddress == W_BREAK_UPGRAGE)
+							{
+								
+							}else if(usAddress == W_SET_PH_INFO)
+							{
+								
+							}
+							else
 							{
 								eStatus = MB_ENOREG;
 							}
-
 						}
 						break;
 					}

Dosya farkı çok büyük olduğundan ihmal edildi
+ 3723 - 3271
truing_control/PDU-AC/prj/JLinkLog.txt


Dosya farkı çok büyük olduğundan ihmal edildi
+ 161 - 161
truing_control/PDU-AC/prj/ctrl_board.uvguix.Gowon


+ 9 - 0
truing_control/PDU-AC/prj/ctrl_board.uvoptx

@@ -117,6 +117,10 @@
         <pMon>Segger\JL2CM3.dll</pMon>
       </DebugOpt>
       <TargetDriverDllRegistry>
+        <SetRegEntry>
+          <Number>0</Number>
+          <Key>DLGUARM</Key>
+        </SetRegEntry>
         <SetRegEntry>
           <Number>0</Number>
           <Key>DLGTARM</Key>
@@ -150,6 +154,11 @@
           <WinNumber>1</WinNumber>
           <ItemText>ac_board</ItemText>
         </Ww>
+        <Ww>
+          <count>2</count>
+          <WinNumber>1</WinNumber>
+          <ItemText>usRegHoldBuf</ItemText>
+        </Ww>
       </WatchWindow1>
       <Tracepoint>
         <THDelay>0</THDelay>

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

@@ -46,6 +46,9 @@
 																																													 |(zero_count       << 7)\
 																																													 |(ctrl_output_flag << 6)\
 																																													 |relay_count)
+																																													 																																						 
+#define PT_SUB_COUNT_3             3
+#define PT_SUB_COUNT_4             4
 
 
 #define  	PRJ_4_BASE                0
@@ -110,6 +113,7 @@
 	#define 	RELAY_REMENBER						1
 	#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

+ 110 - 29
truing_control/PDU-AC/user/main.c

@@ -24,13 +24,14 @@ board_t *get_board()
 	return &ac_board;
 }
 
+extern uint16_t rl_delay_cnt[RelaySlaveChaNum];
+extern uint16_t rl_delay_zero_cnt[ZERO_CTRL_NUM];
+
 
 
 static void task_query(void);
 static void task_1s(void);
-
-
-
+static void task_10s(void);
 static void relay_ctrl(void);
 
 
@@ -63,13 +64,45 @@ int main(){
 	strcpy(&(ac_board.md_data.r_data.r_d.b_info.version),VERSION);
 	
 	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)
+	{
+		for(uint8_t i = 0; i < PT_SUB_COUNT;i++)
+		{
+			ac_board.handle_status[i] = ac_board.relay_staging_staus[i];
+		}
+		
+	}
+	if(ac_board.md_data.r_data.r_d.detection & 0x2)
+	{
+		for(uint8_t i = PT_SUB_COUNT; i < RelaySlaveChaNum;i++)
+		{
+			ac_board.handle_status[i] = ac_board.relay_staging_staus[i];
+		}		
+	}
+#else
+	
+	if(ac_board.md_data.r_data.r_d.detection & 0x1)
+	{
+		for(uint8_t i = 0; i < RelaySlaveChaNum;i++)
+		{
+			ac_board.handle_status[i] = ac_board.relay_staging_staus[i];
+		}
+	}	
+	
+#endif
+	
+	
 	while(1)
 	{
-		relay_ctrl();
 		task_query();
 		task_1s();
+		task_10s();
 		eMBPoll();
 		ac_board.opt_detection();
+		relay_ctrl();
 	}
 	return 0;
 }
@@ -123,46 +156,28 @@ static void task_1s(void)
 		}
 
 #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++)
+	#if(SURPPORT_2_PT)
+			for(int i = 0 ; i < PT_SUB_COUNT;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
+					//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++)
+			for(int i = PT_SUB_COUNT ; 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;
@@ -173,16 +188,61 @@ static void task_1s(void)
 			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
+			ac_board.md_data.r_data.r_d.ele_3_in.info[1].resever = ac_board.md_data.r_data.r_d.ele_out[PT_SUB_COUNT].resever;				//phase infomation
 			//check input wanning
 			ac_board.check_wanning(ELE_INPUT,1);
-		}
+
+	#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);
+	#endif
 #endif
 				channel = 0;
 			}
 	}
 }
 
+static void task_10s(void)
+{
+	if(ac_board.flag_10s)
+	{
+		ac_board.flag_10s = 0;
+		for(int i = 0; i < RelaySlaveChaNum;i++)
+		{
+			ac_board.con_da.iic_da.iic_con.iic_consumer[i] = ac_board.md_data.r_data.r_d.ele_out[i].consumer;
+		}
+		if(ac_board.con_da.row >= MAX_ROW)
+		{
+			ac_board.con_da.row = 0;
+		}
+		if(ac_board.con_da.index > 0xFFFFFFFFFFFFFFFF)
+		{
+			iic_data chache1={0};
+			ac_board.con_da.index = 0;
+			for(int i = 0 ; i < MAX_ROW;i++)
+				ac_board.write_eeprom_page(EEPROM_CONSUMER_ADDR +(CONSUM_PAGE*i),&chache1,CONSUM_PAGE);
+			ac_board.con_da.row = 0;
+		}
+		ac_board.con_da.iic_da.iic_con.recode_index1 = ac_board.con_da.index;
+		ac_board.write_eeprom_page(EEPROM_CONSUMER_ADDR+(CONSUM_PAGE*ac_board.con_da.row),&ac_board.con_da.iic_da.iic_con,CONSUM_PAGE);
+		ac_board.con_da.index++;
+		ac_board.con_da.row++;
+
+	}
+}
 
 static void relay_ctrl(void)
 {
@@ -201,6 +261,7 @@ static void relay_ctrl(void)
 					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]);
+					rl_delay_cnt[i] = 0;
 				}else
 				{
 					ac_board.relay_limit_counter[i] = 0;
@@ -217,6 +278,7 @@ static void relay_ctrl(void)
 					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]);
+					rl_delay_cnt[i] = 0;
 				}else
 				{
 					ac_board.relay_limit_counter[i] = 0;
@@ -248,6 +310,7 @@ static void relay_ctrl(void)
 					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]);
+					rl_delay_zero_cnt[i] = 0;
 				}else
 				{
 					ac_board.relay_zero_limit_counter[i] = 0;
@@ -264,6 +327,7 @@ static void relay_ctrl(void)
 					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]);
+					rl_delay_zero_cnt[i] = 0;
 				}else
 				{
 					ac_board.relay_zero_limit_counter[i] = 0;
@@ -285,16 +349,24 @@ 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);
 		}
 	}
 	for(int i = 0; i < ZERO_CTRL_NUM;i++)
@@ -302,16 +374,25 @@ static void relay_ctrl(void)
 		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);
 		}
 	}
 }