262 lines
6.5 KiB
C
262 lines
6.5 KiB
C
|
#include "type.h"
|
|||
|
#include "UWater_adc_driver.h"
|
|||
|
#include "UWater_power_app.h"
|
|||
|
#include "UWater_eeprom_driver.h"
|
|||
|
#include "UWater_frame_app.h"
|
|||
|
#include "UWater_timer1us_driver.h"
|
|||
|
#include "UWater_rtcc_app.h"
|
|||
|
#include "UWater_ir_app.h"
|
|||
|
#include "UWater_self_test.h"
|
|||
|
#include "UWater_pt_app.h"
|
|||
|
#include "UWater_lptimer_driver.h"
|
|||
|
|
|||
|
static MCU_MAC temp_mcu_mac;
|
|||
|
static u8 g_testself_ee_msg_temp = 0;
|
|||
|
static u8 g_testself_ee_buf[7];
|
|||
|
static u32 g_testself_tickstart = 0;
|
|||
|
static u32 g_testself_adc_result=0;
|
|||
|
//static u8 g_testself_adc_done=0;
|
|||
|
static u8 g_test_self_buf[32];
|
|||
|
|
|||
|
u16 g_testself_result=0;
|
|||
|
|
|||
|
u8 step_TestSelf=TEST_SELF_MAC_GET;
|
|||
|
|
|||
|
|
|||
|
static void McuUidCodeToMac(MCU_MAC *pmac)
|
|||
|
{
|
|||
|
u8 temp_uid=0;
|
|||
|
//u8 temp_buf_uid[12];
|
|||
|
u8 i=0,j=0;
|
|||
|
for (i = 0; i < 10; i++)
|
|||
|
{
|
|||
|
temp_uid = *((u8*)(0x00100E74 + i));
|
|||
|
if(temp_uid != 0)
|
|||
|
{
|
|||
|
if(j<7)
|
|||
|
{
|
|||
|
pmac->buf[j] = temp_uid;
|
|||
|
j++;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void SelfTest_Proc(void)
|
|||
|
{
|
|||
|
switch(step_TestSelf)
|
|||
|
{
|
|||
|
case TEST_SELF_IDLE:
|
|||
|
{
|
|||
|
break;
|
|||
|
}
|
|||
|
case TEST_SELF_MAC_GET://<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7>д<EFBFBD><D0B4>EEROM
|
|||
|
{
|
|||
|
g_testself_result =0;//<2F><><EFBFBD>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD><EFBFBD>0
|
|||
|
McuUidCodeToMac(&temp_mcu_mac);
|
|||
|
//if(PowerIfSleepSys() == 1)
|
|||
|
{
|
|||
|
RtccSetTimer(RTCC_TIMER_BAT_NUM, 3); //3s<33><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD>ѹ
|
|||
|
}
|
|||
|
step_TestSelf = TEST_SELF_EE_WR;
|
|||
|
break;
|
|||
|
}
|
|||
|
case TEST_SELF_EE_WR://дEE<45><45><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
|
|||
|
{
|
|||
|
if (TASK_IDLE == EepIfIdle())
|
|||
|
{
|
|||
|
g_testself_ee_msg_temp = 0;
|
|||
|
EepWrite(temp_mcu_mac.buf, EEP_FRAME_MAC_ADDR, 7, &g_testself_ee_msg_temp);
|
|||
|
step_TestSelf =TEST_SELF_EE_WR_WT;
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
case TEST_SELF_EE_WR_WT://<2F>ȴ<EFBFBD>д<EFBFBD><D0B4><EFBFBD>ɣ<EFBFBD>EE<45><45><EFBFBD><EFBFBD>
|
|||
|
{
|
|||
|
if (TASK_IDLE == EepIfIdle())
|
|||
|
{
|
|||
|
g_testself_tickstart = Timer1usGetTick();//<2F><>ʱ200ms
|
|||
|
step_TestSelf =TEST_SELF_EE_OFF_WT;
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
case TEST_SELF_EE_OFF_WT://<2F>ȴ<EFBFBD>EE<45><45><EFBFBD><EFBFBD>200ms,<2C><>EE<45><45><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
|
|||
|
{
|
|||
|
if((Timer1usGetTick() - g_testself_tickstart)>200000)//100ms
|
|||
|
{
|
|||
|
EepRead(EEP_FRAME_MAC_ADDR, &g_testself_ee_buf[0], 7, &g_testself_ee_msg_temp);
|
|||
|
step_TestSelf =TEST_SELF_EE_RD_CK;
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
case TEST_SELF_EE_RD_CK://<2F><><EFBFBD><EFBFBD>EE<45><45>ȡ<EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>ȷ
|
|||
|
{
|
|||
|
if (TASK_IDLE == EepIfIdle())
|
|||
|
{
|
|||
|
int temp_i;
|
|||
|
for(temp_i=0; temp_i<7; temp_i++)
|
|||
|
{
|
|||
|
g_test_self_buf[temp_i] = temp_mcu_mac.buf[temp_i];
|
|||
|
if(g_testself_ee_buf[temp_i] != temp_mcu_mac.buf[temp_i])
|
|||
|
{
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
if(temp_i == 7)
|
|||
|
{
|
|||
|
g_testself_result |= 0x0001;
|
|||
|
}
|
|||
|
g_testself_tickstart = Timer1usGetTick();
|
|||
|
step_TestSelf =TEST_SELF_HALL_CK;
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
case TEST_SELF_HALL_CK://<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
{
|
|||
|
//if((KEY_GPIO->IDR & KEY_PIN) == (u32)0)
|
|||
|
{
|
|||
|
g_testself_result |= 0x0002;
|
|||
|
}
|
|||
|
if((Timer1usGetTick() - g_testself_tickstart)>100000)//100ms
|
|||
|
{
|
|||
|
RtccSetTimer(TIMER_RTCC_TEST_SELF, 2);
|
|||
|
g_testself_tickstart = Timer1usGetTick();
|
|||
|
step_TestSelf =TEST_SELF_RTCC_CK;
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
case TEST_SELF_RTCC_CK://<2F><><EFBFBD><EFBFBD>RTCC
|
|||
|
{
|
|||
|
if((0 == RtccCheckTimer(TIMER_RTCC_TEST_SELF))&&((Timer1usGetTick() - g_testself_tickstart)>1000000))
|
|||
|
{
|
|||
|
if((0 == RtccIsError()))//RTC<54><43><EFBFBD>쳣
|
|||
|
{
|
|||
|
g_testself_result |= 0x0004;
|
|||
|
}
|
|||
|
else//<2F><><EFBFBD><EFBFBD>RTC<54>쳣,<2C><><EFBFBD>ٴγ<D9B4>ʼ<EFBFBD><CABC>,<2C><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD>֡<EFBFBD>״<EFBFBD><D7B4>ϵ<EFBFBD>GP30û<30><C3BB>ʼ<EFBFBD><CABC>
|
|||
|
{
|
|||
|
u8 rtcc_clk_source = RtccInit(); //<2F>ٴγ<D9B4>ʼ<EFBFBD><CABC>
|
|||
|
LPTimer1Init(rtcc_clk_source);
|
|||
|
if((0 == RtccIsError()))//RTC<54><43><EFBFBD>쳣
|
|||
|
{
|
|||
|
g_testself_result |= 0x0004;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
if((Timer1usGetTick() - g_testself_tickstart)>3000000)//3s
|
|||
|
{
|
|||
|
step_TestSelf = TEST_SELF_IR_CK1;
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
case TEST_SELF_IR_CK1://<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
{
|
|||
|
#if (MODULE_BLE_USED)
|
|||
|
if(BleIfIdle()==TASK_IDLE)
|
|||
|
{
|
|||
|
if(BleGetPowerState()!=BlePowerWrong)
|
|||
|
{
|
|||
|
g_testself_result |= 0x0010;
|
|||
|
}
|
|||
|
step_TestSelf = TEST_SELF_SEND_RESULT;
|
|||
|
}
|
|||
|
#else
|
|||
|
step_TestSelf = TEST_SELF_SEND_RESULT;
|
|||
|
#endif
|
|||
|
break;
|
|||
|
}
|
|||
|
case TEST_SELF_IR_CK2:
|
|||
|
{
|
|||
|
// if (TRUE == g_testself_adc_done)
|
|||
|
// {
|
|||
|
// if (ADC_OK == AdcGetStatus())
|
|||
|
// {
|
|||
|
// IrKey_AdcInitForUart();//ADC<44><43>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>
|
|||
|
// IrInitApp();//<2F><EFBFBD><F2BFAAB4><EFBFBD>
|
|||
|
// if((g_testself_adc_result < 3000)&&((g_testself_adc_result > 2000)))
|
|||
|
// {
|
|||
|
// g_testself_result |= 0x0008;
|
|||
|
// }
|
|||
|
// step_TestSelf = TEST_SELF_SEND_RESULT;
|
|||
|
// }
|
|||
|
// }
|
|||
|
break;
|
|||
|
}
|
|||
|
case TEST_SELF_SEND_RESULT://??GP22??
|
|||
|
{
|
|||
|
UNION_FLOAT_STORAGE temp;
|
|||
|
g_test_self_buf[7]= g_testself_result&0xFF; //??????
|
|||
|
g_test_self_buf[8]= (g_testself_result>>8)&0xFF;//??????
|
|||
|
g_test_self_buf[9]= PowerCheckValueSys()&0xFF; //??????
|
|||
|
g_test_self_buf[10]= ( PowerCheckValueSys()>>8)&0xFF;//??????
|
|||
|
g_test_self_buf[11]= g_testself_adc_result&0xFF; //??????
|
|||
|
g_test_self_buf[12]= ( g_testself_adc_result>>8)&0xFF;//??????
|
|||
|
temp.float_datas = TempCheckValueApp();
|
|||
|
g_test_self_buf[13]=temp.float_storage_format.data_buf[0];
|
|||
|
g_test_self_buf[14]=temp.float_storage_format.data_buf[1];
|
|||
|
g_test_self_buf[15]=temp.float_storage_format.data_buf[2];
|
|||
|
g_test_self_buf[16]=temp.float_storage_format.data_buf[3];
|
|||
|
|
|||
|
g_testself_tickstart = Timer1usGetTick();
|
|||
|
|
|||
|
step_TestSelf = TEST_SELF_SEND_WAIT;
|
|||
|
break;
|
|||
|
}
|
|||
|
case TEST_SELF_SEND_WAIT:
|
|||
|
{
|
|||
|
if((Timer1usGetTick() - g_testself_tickstart)>2000000)//2s
|
|||
|
{
|
|||
|
step_TestSelf =TEST_SELF_IDLE;
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void SelfTest_Start(void)
|
|||
|
{
|
|||
|
if(step_TestSelf == TEST_SELF_IDLE)
|
|||
|
{
|
|||
|
step_TestSelf = TEST_SELF_MAC_GET;
|
|||
|
}
|
|||
|
}
|
|||
|
void SelfTest_End(void)
|
|||
|
{
|
|||
|
step_TestSelf = TEST_SELF_IDLE;
|
|||
|
}
|
|||
|
|
|||
|
u8 SelfTest_GetResult(u8 *pBuf)
|
|||
|
{
|
|||
|
if(step_TestSelf == TEST_SELF_SEND_WAIT)
|
|||
|
{
|
|||
|
u8 i=0;
|
|||
|
for(i=0;i<17;i++)
|
|||
|
{
|
|||
|
*pBuf++ = g_test_self_buf[i];
|
|||
|
}
|
|||
|
step_TestSelf = TEST_SELF_IDLE;
|
|||
|
return 17;
|
|||
|
}
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|