|
|
@@ -14,14 +14,13 @@
|
|
|
#include "flash.h"
|
|
|
#include "electricity.h"
|
|
|
#include "gd32e23x.h"
|
|
|
+#include "string.h"
|
|
|
+#include "query.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-board_t ac_board = {0};
|
|
|
-META_DATA_S meta_data = {0};
|
|
|
-
|
|
|
-float TotalWh[RelaySlaveChaNum] ={0.0};
|
|
|
+static board_t ac_board = {0};
|
|
|
|
|
|
board_t *get_board()
|
|
|
{
|
|
|
@@ -29,20 +28,22 @@ board_t *get_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 task_100ms(void);
|
|
|
static void relay_ctrl(void);
|
|
|
-static void app_init(META_DATA_S *meta);
|
|
|
+
|
|
|
|
|
|
|
|
|
int main(){
|
|
|
|
|
|
InitSysTick();
|
|
|
+ fwdgt_Init();
|
|
|
led_init();
|
|
|
lock_init();
|
|
|
detection_init();
|
|
|
@@ -54,16 +55,17 @@ int main(){
|
|
|
query_init();
|
|
|
eMBInit(MB_RTU, ac_board.haddr, 0, 115200, MB_PAR_NONE);
|
|
|
eMBEnable();
|
|
|
+ ac_board.feed_dog();
|
|
|
//device
|
|
|
- ac_board.md_data.r_data.dev_chn = ACSingCurrid << 8 | RelaySlaveChaNum; // DEIVECE(POWER_TYPE,INPUT_PT_NUM,ZERO_CONTRL,ZERO_CTRL_NUM,OUTPUT_CONTRL,RelaySlaveChaNum);
|
|
|
+ ac_board.md_data.r_data.dev_chn = ACSingCurrid << 8 | RelaySlaveChaNum;
|
|
|
//
|
|
|
ac_board.md_data.r_data.info.channels = RelaySlaveChaNum;
|
|
|
read_config_from_eeprom();
|
|
|
-
|
|
|
- strcpy(&(ac_board.md_data.r_data.info.date),__DATE__);
|
|
|
- strcat(&(ac_board.md_data.r_data.info.date)," ");
|
|
|
- strcat(&(ac_board.md_data.r_data.info.date),__TIME__);
|
|
|
- strcpy(&(ac_board.md_data.r_data.info.ver),VERSION);
|
|
|
+ ac_board.feed_dog();
|
|
|
+ strcpy((char*)&(ac_board.md_data.r_data.info.date),__DATE__);
|
|
|
+ strcat((char*)&(ac_board.md_data.r_data.info.date)," ");
|
|
|
+ strcat((char*)&(ac_board.md_data.r_data.info.date),__TIME__);
|
|
|
+ strcpy((char*)&(ac_board.md_data.r_data.info.ver),VERSION);
|
|
|
|
|
|
flash_get_infomation(&ac_board.md_data.r_data.info);
|
|
|
|
|
|
@@ -71,44 +73,33 @@ int main(){
|
|
|
ac_board.detection();
|
|
|
|
|
|
|
|
|
- #if SURPPORT_2_PT
|
|
|
- if(ac_board.md_data.r_data.detection & 0x1)
|
|
|
+
|
|
|
+ if((ac_board.md_data.r_data.detection & 0x1) == 0)
|
|
|
+ {
|
|
|
+ for(uint8_t i = 0; i < PT_SUB_COUNT;i++)
|
|
|
{
|
|
|
- for(uint8_t i = 0; i < PT_SUB_COUNT;i++)
|
|
|
- {
|
|
|
- ac_board.handle_status[i] = ac_board.relay_staging_staus[i];
|
|
|
- }
|
|
|
+ ac_board.handle_status[i] = ac_board.relay_staging_staus[i];
|
|
|
+ ac_board.relay_staging_staus[i] = 0;
|
|
|
}
|
|
|
-
|
|
|
- if(ac_board.md_data.r_data.detection & 0x2)
|
|
|
+ }
|
|
|
+#if SURPPORT_2_PT
|
|
|
+ if((ac_board.md_data.r_data.detection & 0x2) == 0)
|
|
|
{
|
|
|
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.detection & 0x1) == 0)
|
|
|
- {
|
|
|
- ac_board.handle_input_pt[0] = 0;
|
|
|
- for(uint8_t i = 0; i < RelaySlaveChaNum;i++)
|
|
|
{
|
|
|
ac_board.handle_status[i] = ac_board.relay_staging_staus[i];
|
|
|
ac_board.relay_staging_staus[i] = 0;
|
|
|
-// CLEAR_RL_ON_DELAY_FLAG(ac_board.relay_staging_staus[i]);
|
|
|
-// CLEAR_RL_OFF_DELAY_FLAG(ac_board.relay_staging_staus[i]);
|
|
|
-// CLEAR_RL_ORDER_FLAG(ac_board.relay_staging_staus[i]);
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
while(1)
|
|
|
{
|
|
|
-
|
|
|
+ ac_board.feed_dog();
|
|
|
task_query();
|
|
|
+ task_100ms();
|
|
|
task_1s();
|
|
|
task_10s();
|
|
|
eMBPoll();
|
|
|
@@ -120,32 +111,36 @@ int main(){
|
|
|
reset_config_for_eeprom();
|
|
|
}
|
|
|
}
|
|
|
- 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_page(data.start_addr,&data.data,data.lenth);
|
|
|
+ ac_board.write_eeprom_page(data.start_addr,(uint8_t*)&data.data,data.lenth);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
static void task_1s(void)
|
|
|
{
|
|
|
- static uint8_t channel = 0;
|
|
|
if(ac_board.flag_1s)
|
|
|
{
|
|
|
- ac_board.md_data.r_data.info.runing_time++;
|
|
|
-
|
|
|
ac_board.flag_1s = 0;
|
|
|
+ ac_board.md_data.r_data.info.runing_time++;
|
|
|
ac_board.led_flash();
|
|
|
ac_board.detection();
|
|
|
-
|
|
|
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+static void task_100ms(void)
|
|
|
+{
|
|
|
+ static uint8_t channel = 0;
|
|
|
+ if(ac_board.flag_100ms)
|
|
|
+ {
|
|
|
+ ac_board.flag_100ms = 0;
|
|
|
ac_board.read_ele(channel);
|
|
|
ac_board.check_wanning(ELE_OUTPUT,channel);
|
|
|
ac_board.opt_overfunc(channel);
|
|
|
@@ -155,10 +150,11 @@ static void task_1s(void)
|
|
|
//check input wanning
|
|
|
//calculate input
|
|
|
channel = 0;
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
static void task_10s(void)
|
|
|
{
|
|
|
if(ac_board.flag_10s)
|
|
|
@@ -172,32 +168,26 @@ static void task_10s(void)
|
|
|
{
|
|
|
ac_board.con_da.row = 0;
|
|
|
}
|
|
|
- if(ac_board.con_da.index > 0xFFFFFFFFFFFFFFFF)
|
|
|
+ if(ac_board.con_da.index >= UINT64_MAX)
|
|
|
{
|
|
|
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);
|
|
|
+ for(uint8_t i = 0 ; i < MAX_ROW;i++)
|
|
|
+ ac_board.write_eeprom_page(EEPROM_CONSUMER_ADDR +(CONSUM_PAGE*i),(uint8_t*)&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.write_eeprom_page(EEPROM_CONSUMER_ADDR+(CONSUM_PAGE*ac_board.con_da.row),(uint8_t*)&ac_board.con_da.iic_da.iic_con,CONSUM_PAGE);
|
|
|
ac_board.con_da.index++;
|
|
|
ac_board.con_da.row++;
|
|
|
|
|
|
}
|
|
|
}
|
|
|
-static void app_init(META_DATA_S *meta)
|
|
|
-{
|
|
|
- flash_get_meta_data(meta);
|
|
|
- nvic_vector_table_set(NVIC_VECTTAB_FLASH,meta->rom_addr - NVIC_VECTTAB_FLASH);
|
|
|
- __enable_irq();
|
|
|
-}
|
|
|
|
|
|
|
|
|
static void relay_ctrl(void)
|
|
|
{
|
|
|
- for(int i = 0; i < RelaySlaveChaNum;i++)
|
|
|
+ for(uint8_t i = 0; i < RelaySlaveChaNum;i++)
|
|
|
{
|
|
|
if(IS_RL_ORDER_FLAG_EN(ac_board.relay_staging_staus[i]))
|
|
|
{
|
|
|
@@ -246,7 +236,7 @@ static void relay_ctrl(void)
|
|
|
CLEAR_RL_ORDER_FLAG(ac_board.relay_staging_staus[i]);
|
|
|
}
|
|
|
}
|
|
|
- for(int i = 0; i < RelaySlaveChaNum;i++)
|
|
|
+ for(uint8_t i = 0; i < RelaySlaveChaNum;i++)
|
|
|
{
|
|
|
if(IS_RL_COUNTER_END_FLAG_EN(ac_board.relay_staging_staus[i]))
|
|
|
{
|