This commit is contained in:
zogodo
2019-11-09 11:21:48 +08:00
parent 381f4412fd
commit b3103624c1
2 changed files with 24 additions and 17 deletions

File diff suppressed because one or more lines are too long

View File

@@ -12,10 +12,12 @@ mico_timer_t power_timer;
PowerRecord power_record = { 1, { 0 } }; PowerRecord power_record = { 1, { 0 } };
/*
static uint32_t clock_count_last = 0; static uint32_t clock_count_last = 0;
static uint32_t clock_count = 0; static uint32_t clock_count = 0; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
static uint32_t timer_count = 0; static uint32_t timer_count = 0; //һ<>붨ʱ<EBB6A8><CAB1>
static uint32_t timer_irq_count = 0; static uint32_t timer_irq_count = 0; //<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD>
*/
uint32_t p_count = 0; uint32_t p_count = 0;
char power_record_str[1101] = { 0 }; char power_record_str[1101] = { 0 };
@@ -41,6 +43,7 @@ char* GetPowerRecord(int idx)
return power_record_str; return power_record_str;
} }
/*
static void PowerTimerHandler(void* arg) static void PowerTimerHandler(void* arg)
{ {
uint32_t timer = 0; uint32_t timer = 0;
@@ -72,19 +75,20 @@ static void PowerTimerHandler(void* arg)
timer_count++; timer_count++;
} }
} }
*/
float n_1s = 0; float n_1s = 0; //<2F><><EFBFBD><EFBFBD><EFBFBD>жϴ<D0B6><CFB4><EFBFBD>
mico_time_t t_x = 0; mico_time_t t_x = 0; //<2F><>ǰ<EFBFBD><C7B0>*1000
mico_time_t past_ms = 0; mico_time_t past_ms = 0; //ϵͳ<CFB5><CDB3><EFBFBD>еĺ<D0B5><C4BA><EFBFBD><EFBFBD><EFBFBD>
mico_time_t rest_ms = 1000; mico_time_t rest_x_ms = 0; //<2F><><EFBFBD>뵱ǰ<EBB5B1><C7B0><EFBFBD>߹<EFBFBD><DFB9>ĺ<EFBFBD><C4BA><EFBFBD><EFBFBD><EFBFBD>
mico_time_t rest_x_ms = 0; mico_time_t rest_y_ms = 0; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
mico_time_t rest_y_ms = 0;
static void PowerIrqHandler(void* arg) static void PowerIrqHandler(void* arg)
{ {
clock_count = mico_nanosecond_clock_value(); //clock_count = mico_nanosecond_clock_value();
if (timer_irq_count == 0) clock_count_last = clock_count; //if (timer_irq_count == 0) clock_count_last = clock_count;
timer_irq_count++; //timer_irq_count++;
p_count++; p_count++;
mico_time_get_time(&past_ms); mico_time_get_time(&past_ms);
@@ -93,7 +97,7 @@ static void PowerIrqHandler(void* arg)
t_x = past_ms - 1; t_x = past_ms - 1;
} }
rest_x_ms = past_ms - t_x; rest_x_ms = past_ms - t_x;
if (rest_x_ms < 1000) if (rest_x_ms <= 1000)
{ {
n_1s += 1; n_1s += 1;
rest_y_ms = t_x + 1000 - past_ms; rest_y_ms = t_x + 1000 - past_ms;
@@ -101,7 +105,7 @@ static void PowerIrqHandler(void* arg)
else if (rest_x_ms > 1000 && rest_x_ms < 2000) else if (rest_x_ms > 1000 && rest_x_ms < 2000)
{ {
n_1s += (float)rest_y_ms / (rest_x_ms - 1000 + rest_y_ms); n_1s += (float)rest_y_ms / (rest_x_ms - 1000 + rest_y_ms);
rest_y_ms = 2000 - t_x; rest_y_ms = 2000 - rest_x_ms;
t_x = past_ms / 1000 * 1000; t_x = past_ms / 1000 * 1000;
float power2 = 17.1 * n_1s; float power2 = 17.1 * n_1s;
@@ -110,9 +114,12 @@ static void PowerIrqHandler(void* arg)
} }
else else
{ {
//һ<><EFBFBD><E3B2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD>Բ<EFBFBD><D4B2><EFBFBD><EFBFBD><EFBFBD>...<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>~
SetPowerRecord(&power_record, 123456); SetPowerRecord(&power_record, 123456);
SetPowerRecord(&power_record, past_ms);
SetPowerRecord(&power_record, t_x);
SetPowerRecord(&power_record, rest_x_ms);
} }
} }
void PowerInit(void) void PowerInit(void)
@@ -120,7 +127,7 @@ void PowerInit(void)
os_log("user_power_init"); os_log("user_power_init");
MicoGpioInitialize(POWER, INPUT_PULL_UP); MicoGpioInitialize(POWER, INPUT_PULL_UP);
mico_rtos_init_timer(&power_timer, 1000, PowerTimerHandler, NULL); //mico_rtos_init_timer(&power_timer, 1000, PowerTimerHandler, NULL);
mico_rtos_start_timer(&power_timer); mico_rtos_start_timer(&power_timer);
MicoGpioEnableIRQ(POWER, IRQ_TRIGGER_FALLING_EDGE, PowerIrqHandler, NULL); MicoGpioEnableIRQ(POWER, IRQ_TRIGGER_FALLING_EDGE, PowerIrqHandler, NULL);