#define UINT32_MAX (0xFFFFFFFF)
#define UINT32_MAX (0xFFFFFFFF)
uint32_t utils_time_is_expired(iotx_time_t *timer)
{
uint32_t cur_time;
if (!timer) {
return 1;
}
cur_time = HAL_UptimeMs();
/*
* WARNING: Do NOT change the following code until you know exactly what it do!
*
* check whether it reach destination time or not.
*/
if ((cur_time - timer->time) < (UINT32_MAX / 2)) {
return 1;
} else {
return 0;
}
}
根據源碼 UINT32_MAX / 2 得到 0x7FFFFFFF:
如果cur_time大於timer->time, 兩個相減就會得到一個較小的無符號數。
如果cur_time小於timer->time,兩個相間就會得到一個大的無符號數,最高位爲1.
所用用UINT32_MAX / 2)用來表示 unint32中 兩個數的大小。