|
|
@ -0,0 +1,33 @@ |
|
|
|
#include "zhal_core.hpp"
|
|
|
|
using namespace std; |
|
|
|
using namespace iflytop; |
|
|
|
namespace iflytop { |
|
|
|
ZHALCORE ZHALCORE_instance; |
|
|
|
} |
|
|
|
|
|
|
|
void ZHALCORE::regPeriodJob(function<void(Context& context)> job, uint32_t period_ms) { |
|
|
|
PeriodJob* periodJob = new PeriodJob(job, period_ms); |
|
|
|
ZASSERT(periodJob != NULL); |
|
|
|
m_periodJobs.push_back(periodJob); |
|
|
|
} |
|
|
|
|
|
|
|
void ZHALCORE::loop() { |
|
|
|
static uint32_t ticket = 0; |
|
|
|
Context context; |
|
|
|
if (haspassedms(ticket) < 1) { |
|
|
|
return; |
|
|
|
} |
|
|
|
ticket = chip_get_ticket(); |
|
|
|
for (auto iter = m_periodJobs.begin(); iter != m_periodJobs.end(); iter++) { |
|
|
|
auto periodJob = *iter; |
|
|
|
|
|
|
|
if (haspassedms2(periodJob->lastcall, ticket) < periodJob->period_ms) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
context.periodJob = periodJob; |
|
|
|
periodJob->lastcall = ticket; |
|
|
|
periodJob->job(context); |
|
|
|
periodJob->schedule_times++; |
|
|
|
} |
|
|
|
} |