You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
212 lines
6.1 KiB
212 lines
6.1 KiB
//////////////////////////////////////////////////////////////////////////
|
|
/// COPYRIGHT NOTICE
|
|
/// Copyright (c) 2015, 传控科技
|
|
/// All rights reserved.
|
|
///
|
|
/// @file app_paraid.c
|
|
/// @brief parameter & id app
|
|
///
|
|
///(本文件实现的功能的详述)
|
|
///
|
|
/// @version 1.1 CCsens technology
|
|
/// @author CC
|
|
/// @date 20190107
|
|
///
|
|
///
|
|
/// 修订说明:最初版本
|
|
/// Modified by:
|
|
/// Modified date:
|
|
/// Version:
|
|
/// Descriptions:
|
|
///
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
//#include "app_algorithm.h"
|
|
#include "app_paraid.h"
|
|
#include "../clib/Clib.h"
|
|
#include "../clib/bit.h"
|
|
#include "../msp/msp_eeprom.h"
|
|
#include "../msp/uart0.h"
|
|
|
|
//-------------------------------------------
|
|
struct _s_flash_data s_flash_data;
|
|
|
|
void L3_flash_show_page0()
|
|
{
|
|
U8 i = 0;
|
|
U8 *ptr = (U8 *)&s_flash_data.f_page0;
|
|
L0_uart0_sendstr("Page0 Content: \r\n");
|
|
Lc_delay_ms(500);// 2000--7s
|
|
for(i=0;i<sizeof(struct _s_flash_page0);i++)
|
|
{
|
|
L0_uart0_uchex(*ptr++);
|
|
}
|
|
}
|
|
|
|
void L3_flash_read_page0()
|
|
{
|
|
struct _s_flash_page0 *p_page0 = &s_flash_data.f_page0;
|
|
L1_Iap_Read_array(D_flash_Addr_start(s_flash_data.page0),(U8*)p_page0,sizeof(struct _s_flash_page0));
|
|
L3_flash_show_page0();
|
|
}
|
|
|
|
void L3_flash_erase_page0()
|
|
{
|
|
L1_Iap_erase(D_flash_Addr_start(s_flash_data.page0)); //page0读完立即擦除
|
|
//L0_uart0_sendstr("Page0 Erased.");
|
|
}
|
|
|
|
void L3_flash_write_page0()
|
|
{
|
|
U8 i = 0;
|
|
struct _s_flash_page0 *p_page0 = &s_flash_data.f_page0;
|
|
|
|
L3_flash_erase_page0(); //page0擦除
|
|
|
|
p_page0->page = s_flash_data.page0;
|
|
p_page0->filter0 = FLASH_PARAM_PAGE_FILTER0;
|
|
p_page0->filter1 = FLASH_PARAM_PAGE_FILTER1;
|
|
#if 0
|
|
for(i=0;i<RELAY_NUM;i++)
|
|
{
|
|
#if (defined BOARD_MAIN04_GM35) || (defined BOARD_MAIN04_GM35_M42)
|
|
if(s_relay_oper[i].relay == RELAY_PC)
|
|
{
|
|
p_page0->relay_status[i] = RELAY_KAI; //pc必须是断开的(不断路)
|
|
}
|
|
else
|
|
{
|
|
p_page0->relay_status[i] = s_relay_oper[i].relay_status;
|
|
}
|
|
#elif defined BOARD_MAIN03_A9
|
|
p_page0->relay_status[i] = s_relay_oper[i].relay_status;
|
|
#endif
|
|
}
|
|
#endif
|
|
for(i=0;i<PAPER_BOX_NUM;i++)
|
|
{
|
|
p_page0->ts_paper_calib[i].num0 = G.paperCalibs[i].num0;
|
|
p_page0->ts_paper_calib[i].angle0 = G.paperCalibs[i].angle0;
|
|
p_page0->ts_paper_calib[i].num1 = G.paperCalibs[i].num1;
|
|
p_page0->ts_paper_calib[i].angle1 = G.paperCalibs[i].angle1;
|
|
}
|
|
crc16(p_page0->crc,(U8*)&p_page0->relay_status,sizeof(struct _s_flash_page0) - 3 - 2);
|
|
//L3_flash_show_page0();
|
|
L1_Iap_Write_array(D_flash_Addr_start(s_flash_data.page0),(U8*)p_page0,sizeof(struct _s_flash_page0));
|
|
|
|
//L0_uart0_sendstr("Page0 Writed.");
|
|
}
|
|
|
|
#if 0
|
|
void L3_flash_read_page1()
|
|
{
|
|
struct _s_flash_page1 *p_page1 = &s_flash_data.f_page1;
|
|
L1_Iap_Read_array(D_flash_Addr_start(s_flash_data.page1),(U8*)p_page1,sizeof(struct _s_flash_page1));
|
|
}
|
|
|
|
void L3_flash_erase_page1()
|
|
{
|
|
L1_Iap_erase(D_flash_Addr_start(s_flash_data.page1)); //page0读完立即擦除
|
|
L0_uart0_sendstr("Page1 Erased.");
|
|
}
|
|
|
|
void L3_flash_write_page1()
|
|
{
|
|
struct _s_flash_page1 *p_page1 = &s_flash_data.f_page1;
|
|
|
|
L3_flash_erase_page1(); //page1擦除
|
|
crc16(p_page1->crc,(U8*)&p_page1->relay_oper_max_time,sizeof(struct _s_flash_page1) - 3 - 2);
|
|
L3_flash_show_page1();
|
|
L1_Iap_Write_array(D_flash_Addr_start(s_flash_data.page1),(U8*)p_page1,sizeof(struct _s_flash_page1));
|
|
|
|
L0_uart0_sendstr("Page1 Writed.");
|
|
Lc_delay_ms(500);// 2000--7s
|
|
}
|
|
#endif
|
|
|
|
//=====================================================================================
|
|
|
|
void L3_flash_init()
|
|
{
|
|
s_flash_data.page0 = FLASH_PARAM_PAGE_0;
|
|
s_flash_data.page0_ok = 0;
|
|
s_flash_data.page1 = FLASH_PARAM_PAGE_1;
|
|
s_flash_data.page1_ok = 0;
|
|
}
|
|
|
|
void L3_flash_read_param()
|
|
{
|
|
struct _s_flash_page0 *p_page0 = &s_flash_data.f_page0;
|
|
struct _s_flash_page1 *p_page1 = &s_flash_data.f_page1;
|
|
U8 i,CRC[2];
|
|
|
|
//Read Page 0
|
|
L1_Iap_Read_array(D_flash_Addr_start(s_flash_data.page0),(U8*)p_page0,sizeof(struct _s_flash_page0));
|
|
if((p_page0->page == s_flash_data.page0)
|
|
&& (p_page0->filter0 == FLASH_PARAM_PAGE_FILTER0) && (p_page0->filter1 == FLASH_PARAM_PAGE_FILTER1))
|
|
{
|
|
crc16(CRC,(U8*)&p_page0->relay_status,sizeof(struct _s_flash_page0) - 3 - 2);
|
|
if((CRC[0] == p_page0->crc[0]) && (CRC[1] == p_page0->crc[1]))
|
|
{
|
|
s_flash_data.page0_ok = 1;
|
|
L0_uart0_sendstr("Flash Page0 CRC Success.");
|
|
//L1_Iap_erase(D_flash_Addr_start(s_flash_data.page0)); //page0读完立即擦除
|
|
#if 0
|
|
for(i=0;i<RELAY_NUM;i++)
|
|
{
|
|
G.relayStatus[i] = p_page0->relay_status[i];
|
|
}
|
|
#endif
|
|
|
|
for(i=0;i<PAPER_BOX_NUM;i++)
|
|
{
|
|
G.paperCalibs[i].num0 = p_page0->ts_paper_calib[i].num0;
|
|
G.paperCalibs[i].angle0 = p_page0->ts_paper_calib[i].angle0;
|
|
G.paperCalibs[i].num1 = p_page0->ts_paper_calib[i].num1;
|
|
G.paperCalibs[i].angle1 = p_page0->ts_paper_calib[i].angle1;
|
|
}
|
|
}
|
|
}
|
|
|
|
#if 0 //page1测试不成功
|
|
//Read Page 1
|
|
L1_Iap_Read_array(D_flash_Addr_start(s_flash_data.page1),(U8*)p_page1,sizeof(struct _s_flash_page1));
|
|
if((p_page1->page == s_flash_data.page1)
|
|
&& (p_page1->filter0 == FLASH_PARAM_PAGE_FILTER0) && (p_page1->filter1 == FLASH_PARAM_PAGE_FILTER1))
|
|
{
|
|
crc16(CRC,(U8*)&p_page1->relay_oper_max_time,sizeof(struct _s_flash_page1) - 3 - 2);
|
|
if((CRC[0] == p_page1->crc[0]) && (CRC[1] == p_page1->crc[1]))
|
|
{
|
|
s_flash_data.page1_ok = 1;
|
|
L0_uart0_sendstr("Flash Page1 CRC Success.");
|
|
}
|
|
}
|
|
if(s_flash_data.page1_ok == 0)
|
|
{
|
|
p_page1->page = s_flash_data.page1;
|
|
p_page1->filter0 = FLASH_PARAM_PAGE_FILTER0;
|
|
p_page1->filter1 = FLASH_PARAM_PAGE_FILTER1;
|
|
for(i=0;i<RELAY_NUM;i++)
|
|
{
|
|
p_page1->relay_oper_max_time[i] = g_flash_relay_max_time[i];
|
|
}
|
|
L3_flash_write_page1();
|
|
|
|
s_flash_data.page1_ok = 1;
|
|
}
|
|
if(s_flash_data.page1_ok == 0)
|
|
{
|
|
p_page1->page = s_flash_data.page1;
|
|
p_page1->filter0 = FLASH_PARAM_PAGE_FILTER0;
|
|
p_page1->filter1 = FLASH_PARAM_PAGE_FILTER1;
|
|
for(i=0;i<RELAY_NUM;i++)
|
|
{
|
|
p_page1->relay_oper_max_time[i] = g_flash_relay_max_time[i];
|
|
}
|
|
s_flash_data.page1_ok = 1;
|
|
}
|
|
#endif
|
|
}
|
|
|
|
|
|
|
|
|