micropython time 函数实现
2017-12-01 10:21
417 查看
STATIC mp_obj_t mod_time_time(void) { /* The absence of FP support is deliberate. The Zephyr port uses * single precision floats so the fraction component will start to * lose precision on devices with a long uptime. */ __asm int 3; return mp_obj_new_int(k_uptime_get() / 1000); } STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_time_time_obj, mod_time_time); STATIC const mp_rom_map_elem_t mp_module_time_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_utime) }, { MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&mp_utime_sleep_obj) }, { MP_ROM_QSTR(MP_QSTR_sleep_ms), MP_ROM_PTR(&mp_utime_sleep_ms_obj) }, { MP_ROM_QSTR(MP_QSTR_sleep_us), MP_ROM_PTR(&mp_utime_sleep_us_obj) }, { MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&mod_time_time_obj) }, { MP_ROM_QSTR(MP_QSTR_ticks_ms), MP_ROM_PTR(&mp_utime_ticks_ms_obj) }, { MP_ROM_QSTR(MP_QSTR_ticks_us), MP_ROM_PTR(&mp_utime_ticks_us_obj) }, { MP_ROM_QSTR(MP_QSTR_ticks_cpu), MP_ROM_PTR(&mp_utime_ticks_cpu_obj) }, { MP_ROM_QSTR(MP_QSTR_ticks_add), MP_ROM_PTR(&mp_utime_ticks_add_obj) }, { MP_ROM_QSTR(MP_QSTR_ticks_diff), MP_ROM_PTR(&mp_utime_ticks_diff_obj) }, }; STATIC MP_DEFINE_CONST_DICT(mp_module_time_globals, mp_module_time_globals_table); const mp_obj_module_t mp_module_time = { .base = { &mp_type_module }, .globals = (mp_obj_dict_t*)&mp_module_time_globals, };
STATIC mp_obj_t mod_time_time(void) { #if MICROPY_PY_BUILTINS_FLOAT struct timeval tv; gettimeofday(&tv, NULL); mp_float_t val = tv.tv_sec + (mp_float_t)tv.tv_usec / 1000000; return mp_obj_new_float(val); #else return mp_obj_new_int((mp_int_t)time(NULL)); #endif }
time_t time(time_t *t) { return mp_hal_ticks_ms() / 1000; }
mp_uint_t mp_hal_ticks_ms(void) { struct timeval tv; gettimeofday(&tv, NULL); return tv.tv_sec * 1000 + tv.tv_usec / 1000; }
EFI_STATUS EFIAPI WinNtGetTime ( OUT EFI_TIME *Time, OUT EFI_TIME_CAPABILITIES *Capabilities OPTIONAL ) /*++ Routine Description: Service routine for RealTimeClockInstance->GetTime Arguments: Time - A pointer to storage that will receive a snapshot of the current time. Capabilities - A pointer to storage that will receive the capabilities of the real time clock in the platform. This includes the real time clock's resolution and accuracy. All reported device capabilities are rounded up. This is an OPTIONAL argument. Returns: EFI_SUCEESS - The underlying GetSystemTime call occurred and returned Note that in the NT32 emulation, the GetSystemTime call has no return value thus you will always receive a EFI_SUCCESS on this. --*/ // TODO: EFI_INVALID_PARAMETER - add return value to function comment { SYSTEMTIME SystemTime; TIME_ZONE_INFORMATION TimeZone; // // Check parameter for null pointer // if (Time == NULL) { return EFI_INVALID_PARAMETER; } gWinNt->GetLocalTime (&SystemTime); gWinNt->GetTimeZoneInformation (&TimeZone); Time->Year = (UINT16) SystemTime.wYear; Time->Month = (UINT8) SystemTime.wMonth; Time->Day = (UINT8) SystemTime.wDay; Time->Hour = (UINT8) SystemTime.wHour; Time->Minute = (UINT8) SystemTime.wMinute; Time->Second = (UINT8) SystemTime.wSecond; Time->Nanosecond = (UINT32) (SystemTime.wMilliseconds * 1000000); Time->TimeZone = (INT16) TimeZone.Bias; if (Capabilities != NULL) { Capabilities->Resolution = 1; Capabilities->Accuracy = 50000000; Capabilities->SetsToZero = FALSE; } Time->Daylight = 0; if (TimeZone.StandardDate.wMonth) { Time->Daylight = (UINT8) TimeZone.StandardDate.wMonth; } return EFI_SUCCESS; }
相关文章推荐
- Python实现的时间函数
- 【python学习笔记】实现linux终端下的getch()函数
- 用Python实现斐波那契(Fibonacci)函数
- Python+numpy实现函数向量化
- Python 使用reduce()函数实现,列表内的数相乘
- Python实现互联网笔试题-百度-关于排序sorted()函数
- Python实现截屏的函数
- Python实现接受任意个数参数的函数方法
- python 实现 Peceptron Learning Algorithm ( 一) 几个函数的记录
- Python实现一元二次方程的定义是:ax2 + bx + c = 0 请编写一个函数,返回一元二次方程的解。
- python 实现 frontCon 函数,画 马克韦茨 有效前沿和求切线 思路
- 基础入门_Python-模块和包.为wsgiref实现的WSGI服务器编写处理函数?
- python里使用正则表达式的search()函数实现指定位置搜索
- python 限制函数执行时间,自己实现 timeout
- 实现系统函数time,获取当前时间与UTC的间隔
- python如何使用生成器函数实现可迭代对象
- [Micropython]TPYBoard v202 利用单片机快速实现家庭智能控制平台
- Python实现动态添加类的属性或成员函数的解决方法
- Python实现动态添加类的属性或成员函数的解决方法
- Python time库常用函数