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.
433 lines
7.9 KiB
433 lines
7.9 KiB
#include "app_config.h"
|
|
//#include "../tpc/tpc_uart.h"
|
|
///#include "../bsp/bsp_cs1232.h"
|
|
#include "msp_eeprom.h"
|
|
///#include "../msp/msp_id.h"
|
|
#include "debug_drv.h"
|
|
#include "msp_uartN.h"
|
|
|
|
TS_GlobalRegisterSave_ S;
|
|
////TS_GlobalParam_ G;
|
|
|
|
GlobalRegister R;
|
|
|
|
void L3_reg_reset(void)
|
|
{
|
|
//称重数据初始化
|
|
R.weight.sensor_adc[0] = 0;
|
|
R.weight.sensor_adc[1] = 0;
|
|
R.weight.sensor_adc[2] = 0;
|
|
R.weight.sensor_adc[3] = 0;
|
|
R.weight.kgx10_out = 0;
|
|
R.weight.adc16 = 0;
|
|
|
|
//网络状态 00 联网 01 断网
|
|
R.net_status = NET_STATUS_NOTCONNECT;
|
|
|
|
//充电状态
|
|
R.charge_status = KLJ_CHARGE_STATUS_NORMAL;
|
|
|
|
//电量百分比
|
|
R.dl = 0;
|
|
|
|
//功耗模式:正常模式
|
|
R.power_mode = POWER_NORMAL;
|
|
|
|
//单位
|
|
R.danwei = KG;
|
|
|
|
//蜂鸣器
|
|
R.beep = 0;
|
|
|
|
//校时标志位
|
|
R.setime_flag = 0;
|
|
|
|
//实时时钟数据初始化
|
|
R.ds1302.second = 0;
|
|
R.ds1302.miunte = 0;
|
|
R.ds1302.hour = 0;
|
|
R.ds1302.day = 0;
|
|
R.ds1302.month = 0;
|
|
R.ds1302.week = 0;
|
|
R.ds1302.year = 0;
|
|
}
|
|
|
|
void L3_reg_init(void)
|
|
{
|
|
L3_reg_reset();
|
|
// L3_iap_2_reg();
|
|
}
|
|
|
|
void L3_R_2_S(void)
|
|
{
|
|
TTSS_run_times(4)////tst_v.i
|
|
{ ////ts_adc_samples[tst_v.i].pSPara = &TS_adc_SPara[tst_v.i];
|
|
Lc_buf_from_const_uc(D_struct2U8(S.adc_SPara[tst_v.i]),D_struct2U8(TS_adc_SPara[tst_v.i]),D_TS_adc_SPara_LEN);
|
|
}
|
|
///tst_weight.pSPara = &ts_weight_SPara;
|
|
Lc_buf_from_const_uc(D_struct2U8(S.weight_SPara),D_struct2U8(ts_weight_SPara),D_TS_weight_SPara_len);
|
|
}
|
|
void L3_S_2_R(void)
|
|
{
|
|
TTSS_run_times(4)////tst_v.i
|
|
{
|
|
Lc_buf_from_const_uc(D_struct2U8(TS_adc_SPara[tst_v.i]),D_struct2U8(S.adc_SPara[tst_v.i]),D_TS_adc_SPara_LEN);
|
|
ts_adc_samples[tst_v.i].pSPara = &TS_adc_SPara[tst_v.i];
|
|
}
|
|
///
|
|
Lc_buf_from_const_uc(D_struct2U8(ts_weight_SPara),D_struct2U8(S.weight_SPara),D_TS_weight_SPara_len);
|
|
tst_weight.pSPara = &ts_weight_SPara;
|
|
}
|
|
|
|
#define D_0xaa55 0xaa55
|
|
|
|
////返回0 并打印 ("\r\nSpara ok ");
|
|
/// 返回非零 为错误次数 最后一次ok
|
|
/// 返回100 严重错误 一次没有成功
|
|
vtype L3_S_init(void)
|
|
{
|
|
vtype ovt = 0;
|
|
////
|
|
/*
|
|
|
|
存错的多个写法:
|
|
使用三个区域,增加一致性判定的写法
|
|
使用一个区域,容错一次的写法
|
|
|
|
|
|
step 1 上电读取eeprom参数,
|
|
step 2 如果标志位数据不对,把每个任务中的spara初始化放到S 中,然后写入eeprom,返回step 1
|
|
如果重试次数溢出 打印错误信息;严重警告 系统不可用
|
|
step 3 如果标志位数据ok 退出
|
|
TTSS_run_times(4)////tst_v.i
|
|
{ ////ts_adc_samples[tst_v.i].pSPara = &TS_adc_SPara[tst_v.i];
|
|
Lc_buf_from_const_uc(D_struct2U8(S.adc_SPara[tst_v.i]),D_struct2U8(&TS_adc_SPara[tst_v.i]),D_TS_adc_SPara_LEN);
|
|
}
|
|
|
|
///tst_weight.pSPara = &ts_weight_SPara;
|
|
Lc_buf_from_const_uc(D_struct2U8(S.weight_SPara),D_struct2U8(&ts_weight_SPara),D_TS_weight_SPara_len);
|
|
|
|
|
|
*/
|
|
do{
|
|
L0_Iap_Read_array(D_EEP_BASE,D_struct2U8(S),D_S_LEN);
|
|
printf1("\r\nread S: %d ",(int)ovt);
|
|
L1_uartD_Arrayhex(D_struct2U8(S),D_S_LEN);
|
|
|
|
if(0xaa55 == S.d0xaa55)
|
|
{////>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>和应用强相关
|
|
L3_S_2_R();
|
|
////<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<和应用强相关
|
|
printfs("\r\nSpara ok ");
|
|
return ovt;
|
|
}else
|
|
{
|
|
S.d0xaa55 = D_0xaa55;
|
|
printf1("\r\nProg %x",S.d0xaa55);
|
|
L3_R_2_S();
|
|
L0_Iap_Program_array(D_EEP_BASE,D_struct2U8(S),D_S_LEN);
|
|
}
|
|
}while(ovt ++< 2);
|
|
return 100;
|
|
}
|
|
|
|
/*
|
|
void L3_param_init(void)
|
|
{
|
|
int i;
|
|
for(i=0;i<D_ch_max_num;i++)
|
|
{
|
|
G.weight[i] = 0;
|
|
}
|
|
G.allweight = 0;
|
|
G._total_weight = 0;
|
|
G._total_zweight = 0;
|
|
|
|
//L3_eeprom_read_param();
|
|
}
|
|
|
|
*/
|
|
|
|
///出厂参数 向 保存参数
|
|
void L3_S(void)
|
|
{
|
|
|
|
|
|
/// Lc_buf_copy_uc((u8 *)&R.sd,(u8 *)&iapData,20);
|
|
//写入eeprom
|
|
/// if(L1_eeprom_write((U8*)&iapData,sizeof(TS_GlobalRegisterSave_)) == 0)
|
|
{
|
|
// L0_uart0_sendstr("e2p write success");
|
|
}
|
|
}
|
|
|
|
////把当前任务中的数据放入到保存参数(一般是eeprom
|
|
void L2_para_2_S(TS_para_ *t)
|
|
{////void L0_Iap_Program_array(vU16 addr,U8 *buf,U8 len)
|
|
/// L0_Iap_Program_array(t->add,);
|
|
|
|
}
|
|
|
|
|
|
|
|
//读取iap内容,写入reg
|
|
void L3_iap_2_reg(void)
|
|
{
|
|
|
|
/*
|
|
|
|
|
|
U8 len = 0,i = 0;
|
|
if(L1_eeprom_read((U8*)&iapData,&len) == 1)
|
|
{
|
|
L0_uart0_sendstr("e2p read failed\r\n");
|
|
return;
|
|
}
|
|
L0_uart0_sendstr("e2p read success\r\n");
|
|
|
|
Lc_buf_copy_uc((u8 *)&iapData,(u8 *)&R.sd,20);
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
/*********
|
|
|
|
|
|
int L3_mcu_id_ok(void)
|
|
{
|
|
U8 i = 0,crc[2];
|
|
U32 enc_key;
|
|
//1.获取MCU_ID
|
|
L0_id_get_rom(G.e.mcu_id);
|
|
for(i=0;i<MCU_ID_LEN;i++)
|
|
{
|
|
L0_uart0_uchex(G.e.mcu_id[i]);
|
|
}
|
|
|
|
//2.读取eeprom中的加密信息
|
|
L0_Iap_Read_array(EEP_ENC_ADDR, (U8*)&eep_enc, MCU_ID_KEY_LEN + MCU_ID_LEN + 2);
|
|
crc16(crc,(U8*)&eep_enc,MCU_ID_KEY_LEN + MCU_ID_LEN);
|
|
if(eep_enc.crc[0] != crc[0] || eep_enc.crc[1] != crc[1])
|
|
{
|
|
L0_uart0_uc('-');
|
|
return 0;
|
|
}
|
|
|
|
//3.根据mcu_id和enc_key计算enc_val
|
|
enc_key = ((U32)eep_enc.enc_key[0] << 24) | (eep_enc.enc_key[1] << 16) | (eep_enc.enc_key[2] << 8) |(eep_enc.enc_key[3] << 0);
|
|
Lc_encrypt_id((U8*)G.e.mcu_enc_id, (U8*)G.e.mcu_id, enc_key, MCU_ID_LEN);
|
|
|
|
//4.判断enc_val是否一致
|
|
for(i=0;i<MCU_ID_KEY_LEN;i++)
|
|
{
|
|
if(G.e.mcu_enc_id[i] != eep_enc.enc_val[i])
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
|
|
**********/
|
|
|
|
|
|
|
|
#if 0
|
|
TS_EEPROM_ENC_ eep_enc;
|
|
|
|
void L0_reg_reset()
|
|
{/******
|
|
//R.p.reset = 0;
|
|
R.p.adc_ch_status = ADC_status_ch1_Ready | ADC_status_ch2_Ready | ADC_status_ch3_Ready | ADC_status_ch4_Ready; //修改采集通道
|
|
R.p.slaver_id = D_UART0_485_SLAVER_ID;
|
|
R.zero = 0;
|
|
R.status_eep_save = 0;
|
|
// R.reset = 0;
|
|
R.p.weight_max = 150; //500kg
|
|
R.p.lmd = 15; //2mv/v
|
|
|
|
R.p.adc_blur_mid = 1;
|
|
R.p.adc_blur_avg = 6;
|
|
R.p.adc_blur_shift[0] = 0;
|
|
R.p.adc_blur_shift[1] = 2;
|
|
R.p.adc_blur_shift[2] = 4;
|
|
R.p.adc_blur_threshold[0] = 1600; //1.6kg
|
|
R.p.adc_blur_threshold[1] = 700; //0.7kg
|
|
*********/
|
|
|
|
///L3_reg_2_iap();
|
|
}
|
|
|
|
void L0_reg_init(void)
|
|
{
|
|
R.sd.rev0x55aa55aa = 0x55aa55aa;
|
|
//R.total_weight = R.total_zweight = 0;
|
|
///L0_reg_reset();
|
|
L4_iap_2_reg();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
S32 L3_count_std_weight(S32 weight)
|
|
{
|
|
U8 i = 0;
|
|
U16 ratio = 100;
|
|
weight = (weight - G._total_zweight)/10;
|
|
for(i=0;i<D_weight_std_num;i++)
|
|
{
|
|
if(R.p.weight_std[i].weight_range == 0 || (R.p.weight_std[i].weight_range * 100) >= weight)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
if(i<D_weight_std_num && R.p.weight_std[i].ratio != 0)
|
|
{
|
|
ratio = R.p.weight_std[i].ratio;
|
|
}
|
|
return (S32)(weight * 1.0 * ratio / 100) ;
|
|
}
|
|
#endif
|
|
|
|
|
|
|
|
void L0_main_lowp(void)
|
|
{//
|
|
|
|
|
|
BITN_1(P_SW2 ,BITN7);USBCON = 0;
|
|
|
|
D_stdIO_P0_ALL();
|
|
|
|
D_stdIO_P1_ALL();
|
|
D_stdIO_P2_ALL();
|
|
D_stdIO_P3_ALL();
|
|
D_stdIO_P4_ALL();
|
|
D_stdIO_P5_ALL();
|
|
|
|
|
|
|
|
|
|
|
|
WKTCL = 0xff; //设定掉电唤醒时钟约为 1 秒钟 WKTCH = 0x87;
|
|
|
|
WKTCH = 0x87;
|
|
///SetWakeUpTime(10000);
|
|
|
|
D_P24_REV();
|
|
Lc_delay_ms(500);
|
|
D_P24_REV();
|
|
Lc_delay_ms(500);
|
|
D_P24_REV();
|
|
Lc_delay_ms(500);
|
|
|
|
D_P24_ON();
|
|
P_SW2|=0x80;
|
|
|
|
P0PU = 0;
|
|
P1PU = 0;
|
|
P2PU = 0;
|
|
P3PU = 0;
|
|
P4PU = 0;
|
|
P5PU = 0;
|
|
|
|
P0SR =0xff;
|
|
P1SR =0xff;
|
|
P2SR =0xff;
|
|
P3SR =0xff;
|
|
P4SR =0xff;
|
|
P5SR =0xff;
|
|
|
|
P0DR =0xff;
|
|
P1DR =0xff;
|
|
P2DR =0xff;
|
|
P3DR =0xff;
|
|
P4DR =0xff;
|
|
P5DR =0xff;
|
|
|
|
|
|
P0IE =0;
|
|
P1IE =0;
|
|
P2IE =0;
|
|
P3IE =0;
|
|
P4IE =0;
|
|
P5IE =0;
|
|
|
|
USBCON = 0;
|
|
///USBCON = 0x80;
|
|
|
|
|
|
|
|
|
|
D_HighR_P0_ALL();
|
|
D_HighR_P1_ALL();
|
|
D_HighR_P2_ALL();
|
|
D_HighR_P3_ALL();
|
|
D_HighR_P4_ALL();
|
|
D_HighR_P5_ALL();
|
|
P_SW2 = 0x80;
|
|
// XOSCCR =0;
|
|
///HIRCCR = 0;
|
|
/*****
|
|
|
|
IRC32KCR = 0x80; //启动内部32K IRC
|
|
while (!(IRC32KCR & 1)); //等待时钟稳定
|
|
CLKDIV = 0x00; //时钟不分频
|
|
CLKSEL = 0x03; //选择内部32K
|
|
P_SW2 = 0x00;
|
|
|
|
|
|
D_stdIO_P0_ALL();
|
|
D_stdIO_P1_ALL();
|
|
D_stdIO_P2_ALL();
|
|
D_stdIO_P3_ALL();
|
|
D_stdIO_P4_ALL();
|
|
D_stdIO_P5_ALL();
|
|
|
|
P0 = 0xff;
|
|
P1 = 0xff;
|
|
P2 = 0xff;
|
|
P3 = 0xff;
|
|
P4 = 0xff;
|
|
P5 = 0xff;
|
|
|
|
|
|
|
|
*******/
|
|
RSTCFG=0;//没有变化43ua 41ua
|
|
|
|
while(9)
|
|
{
|
|
|
|
D_HighR_P2_ALL();
|
|
|
|
|
|
|
|
|
|
|
|
_nop_();
|
|
_nop_();
|
|
|
|
PCON = 0x02; ////2222 //MCU进入掉电模式
|
|
///D_LPCD_INT_CLOSE(); 对掉电唤醒后有一个中断进来没有效果
|
|
_nop_();
|
|
_nop_(); _nop_();
|
|
_nop_(); _nop_();
|
|
_nop_();
|
|
/// D_P24_REV();
|
|
|
|
D_stdIO_P2_ALL();
|
|
D_P24_REV();
|
|
|
|
Lc_delay_ms(300);
|
|
D_P24_REV();
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|