Damien George | 04b9147 | 2014-05-03 23:27:38 +0100 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the Micro Python project, http://micropython.org/ |
| 3 | * |
| 4 | * The MIT License (MIT) |
| 5 | * |
| 6 | * Copyright (c) 2013, 2014 Damien P. George |
| 7 | * |
| 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 | * of this software and associated documentation files (the "Software"), to deal |
| 10 | * in the Software without restriction, including without limitation the rights |
| 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 12 | * copies of the Software, and to permit persons to whom the Software is |
| 13 | * furnished to do so, subject to the following conditions: |
| 14 | * |
| 15 | * The above copyright notice and this permission notice shall be included in |
| 16 | * all copies or substantial portions of the Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 24 | * THE SOFTWARE. |
| 25 | */ |
| 26 | |
Dave Hylands | 6678595 | 2014-08-19 18:38:38 -0700 | [diff] [blame] | 27 | #include <stdio.h> |
| 28 | #include <string.h> |
Damien George | d6cbbc5 | 2014-05-08 22:25:49 +0100 | [diff] [blame] | 29 | #include "stm32f4xx_hal.h" |
Damien George | d311655 | 2014-03-22 15:06:29 +0000 | [diff] [blame] | 30 | |
Paul Sokolovsky | 9b71b16 | 2014-05-02 18:03:04 +0300 | [diff] [blame] | 31 | #include "mpconfig.h" |
Damien George | d311655 | 2014-03-22 15:06:29 +0000 | [diff] [blame] | 32 | #include "nlr.h" |
| 33 | #include "misc.h" |
Damien George | d311655 | 2014-03-22 15:06:29 +0000 | [diff] [blame] | 34 | #include "qstr.h" |
| 35 | #include "obj.h" |
Damien George | 04b9147 | 2014-05-03 23:27:38 +0100 | [diff] [blame] | 36 | #include "portmodules.h" |
Damien George | d6cbbc5 | 2014-05-08 22:25:49 +0100 | [diff] [blame] | 37 | #include "rtc.h" |
| 38 | |
Damien George | ea439e5 | 2014-08-08 23:30:01 +0100 | [diff] [blame] | 39 | /// \module time - time related functions |
| 40 | /// |
| 41 | /// The `time` module provides functions for getting the current time and date, |
| 42 | /// and for sleeping. |
| 43 | |
Dave Hylands | 6678595 | 2014-08-19 18:38:38 -0700 | [diff] [blame] | 44 | STATIC const uint16_t days_since_jan1[]= { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }; |
Damien George | d6cbbc5 | 2014-05-08 22:25:49 +0100 | [diff] [blame] | 45 | |
Damien George | 02bc882 | 2014-07-19 16:39:13 +0100 | [diff] [blame] | 46 | STATIC bool is_leap_year(mp_uint_t year) { |
Damien George | d6cbbc5 | 2014-05-08 22:25:49 +0100 | [diff] [blame] | 47 | return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0; |
| 48 | } |
| 49 | |
Dave Hylands | 6678595 | 2014-08-19 18:38:38 -0700 | [diff] [blame] | 50 | // Month is one based |
Damien George | 8ba8324 | 2014-08-24 17:40:24 +0100 | [diff] [blame] | 51 | STATIC mp_uint_t mod_time_days_in_month(mp_uint_t year, mp_uint_t month) { |
Dave Hylands | 6678595 | 2014-08-19 18:38:38 -0700 | [diff] [blame] | 52 | mp_uint_t mdays = days_since_jan1[month] - days_since_jan1[month - 1]; |
| 53 | if (month == 2 && is_leap_year(year)) { |
| 54 | mdays++; |
| 55 | } |
| 56 | return mdays; |
| 57 | } |
| 58 | |
Damien George | d6cbbc5 | 2014-05-08 22:25:49 +0100 | [diff] [blame] | 59 | // compute the day of the year, between 1 and 366 |
| 60 | // month should be between 1 and 12, date should start at 1 |
Damien George | 8ba8324 | 2014-08-24 17:40:24 +0100 | [diff] [blame] | 61 | STATIC mp_uint_t mod_time_year_day(mp_uint_t year, mp_uint_t month, mp_uint_t date) { |
Damien George | 02bc882 | 2014-07-19 16:39:13 +0100 | [diff] [blame] | 62 | mp_uint_t yday = days_since_jan1[month - 1] + date; |
Damien George | d6cbbc5 | 2014-05-08 22:25:49 +0100 | [diff] [blame] | 63 | if (month >= 3 && is_leap_year(year)) { |
| 64 | yday += 1; |
| 65 | } |
| 66 | return yday; |
| 67 | } |
| 68 | |
Dave Hylands | 6678595 | 2014-08-19 18:38:38 -0700 | [diff] [blame] | 69 | // returns the number of seconds, as an integer, since 2000-01-01 |
Damien George | 02bc882 | 2014-07-19 16:39:13 +0100 | [diff] [blame] | 70 | mp_uint_t mod_time_seconds_since_2000(mp_uint_t year, mp_uint_t month, mp_uint_t date, mp_uint_t hour, mp_uint_t minute, mp_uint_t second) { |
| 71 | return |
| 72 | second |
| 73 | + minute * 60 |
| 74 | + hour * 3600 |
| 75 | + (mod_time_year_day(year, month, date) - 1 |
| 76 | + ((year - 2000 + 3) / 4) // add a day each 4 years starting with 2001 |
| 77 | - ((year - 2000 + 99) / 100) // subtract a day each 100 years starting with 2001 |
| 78 | + ((year - 2000 + 399) / 400) // add a day each 400 years starting with 2001 |
| 79 | ) * 86400 |
| 80 | + (year - 2000) * 31536000; |
| 81 | } |
| 82 | |
Dave Hylands | 6678595 | 2014-08-19 18:38:38 -0700 | [diff] [blame] | 83 | // LEAPOCH corresponds to 2000-03-01, which is a mod-400 year, immediately |
| 84 | // after Feb 29. We calculate seconds as a signed integer relative to that. |
| 85 | // |
| 86 | // Our timebase is is relative to 2000-01-01. |
| 87 | |
| 88 | #define LEAPOCH ((31 + 29) * 86400) |
| 89 | |
Damien George | 8ba8324 | 2014-08-24 17:40:24 +0100 | [diff] [blame] | 90 | #define DAYS_PER_400Y (365*400 + 97) |
| 91 | #define DAYS_PER_100Y (365*100 + 24) |
| 92 | #define DAYS_PER_4Y (365*4 + 1) |
Dave Hylands | 6678595 | 2014-08-19 18:38:38 -0700 | [diff] [blame] | 93 | |
Damien George | 8ba8324 | 2014-08-24 17:40:24 +0100 | [diff] [blame] | 94 | typedef struct { |
| 95 | uint16_t tm_year; // i.e. 2014 |
| 96 | uint8_t tm_mon; // 1..12 |
| 97 | uint8_t tm_mday; // 1..31 |
| 98 | uint8_t tm_hour; // 0..23 |
| 99 | uint8_t tm_min; // 0..59 |
| 100 | uint8_t tm_sec; // 0..59 |
| 101 | uint8_t tm_wday; // 0..6 0 = Monday |
| 102 | uint16_t tm_yday; // 1..366 |
| 103 | } mod_struct_time; |
| 104 | |
| 105 | STATIC void mod_time_seconds_since_2000_to_struct_time(mp_uint_t t, mod_struct_time *tm) { |
Dave Hylands | 6678595 | 2014-08-19 18:38:38 -0700 | [diff] [blame] | 106 | // The following algorithm was adapted from musl's __secs_to_tm and adapted |
Damien George | 8ba8324 | 2014-08-24 17:40:24 +0100 | [diff] [blame] | 107 | // for differences in Micro Python's timebase. |
Dave Hylands | 6678595 | 2014-08-19 18:38:38 -0700 | [diff] [blame] | 108 | |
| 109 | mp_int_t seconds = t - LEAPOCH; |
| 110 | |
| 111 | mp_int_t days = seconds / 86400; |
| 112 | seconds %= 86400; |
| 113 | tm->tm_hour = seconds / 3600; |
| 114 | tm->tm_min = seconds / 60 % 60; |
| 115 | tm->tm_sec = seconds % 60; |
| 116 | |
| 117 | mp_int_t wday = (days + 2) % 7; // Mar 1, 2000 was a Wednesday (2) |
| 118 | if (wday < 0) { |
| 119 | wday += 7; |
| 120 | } |
| 121 | tm->tm_wday = wday; |
| 122 | |
| 123 | mp_int_t qc_cycles = days / DAYS_PER_400Y; |
| 124 | days %= DAYS_PER_400Y; |
| 125 | if (days < 0) { |
| 126 | days += DAYS_PER_400Y; |
| 127 | qc_cycles--; |
| 128 | } |
| 129 | mp_int_t c_cycles = days / DAYS_PER_100Y; |
| 130 | if (c_cycles == 4) { |
| 131 | c_cycles--; |
| 132 | } |
| 133 | days -= (c_cycles * DAYS_PER_100Y); |
| 134 | |
| 135 | mp_int_t q_cycles = days / DAYS_PER_4Y; |
| 136 | if (q_cycles == 25) { |
| 137 | q_cycles--; |
| 138 | } |
| 139 | days -= q_cycles * DAYS_PER_4Y; |
| 140 | |
| 141 | mp_int_t years = days / 365; |
| 142 | if (years == 4) { |
| 143 | years--; |
| 144 | } |
| 145 | days -= (years * 365); |
| 146 | |
Damien George | 8ba8324 | 2014-08-24 17:40:24 +0100 | [diff] [blame] | 147 | /* We will compute tm_yday at the very end |
Dave Hylands | 6678595 | 2014-08-19 18:38:38 -0700 | [diff] [blame] | 148 | mp_int_t leap = !years && (q_cycles || !c_cycles); |
| 149 | |
| 150 | tm->tm_yday = days + 31 + 28 + leap; |
| 151 | if (tm->tm_yday >= 365 + leap) { |
| 152 | tm->tm_yday -= 365 + leap; |
| 153 | } |
| 154 | |
Damien George | 8ba8324 | 2014-08-24 17:40:24 +0100 | [diff] [blame] | 155 | tm->tm_yday++; // Make one based |
| 156 | */ |
| 157 | |
Dave Hylands | 6678595 | 2014-08-19 18:38:38 -0700 | [diff] [blame] | 158 | tm->tm_year = 2000 + years + 4 * q_cycles + 100 * c_cycles + 400 * qc_cycles; |
| 159 | |
| 160 | // Note: days_in_month[0] corresponds to March |
Damien George | 8ba8324 | 2014-08-24 17:40:24 +0100 | [diff] [blame] | 161 | STATIC const int8_t days_in_month[] = {31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29}; |
Dave Hylands | 6678595 | 2014-08-19 18:38:38 -0700 | [diff] [blame] | 162 | |
| 163 | mp_int_t month; |
| 164 | for (month = 0; days_in_month[month] <= days; month++) { |
| 165 | days -= days_in_month[month]; |
| 166 | } |
| 167 | |
| 168 | tm->tm_mon = month + 2; |
| 169 | if (tm->tm_mon >= 12) { |
| 170 | tm->tm_mon -= 12; |
| 171 | tm->tm_year++; |
| 172 | } |
| 173 | tm->tm_mday = days + 1; // Make one based |
| 174 | tm->tm_mon++; // Make one based |
Dave Hylands | 6678595 | 2014-08-19 18:38:38 -0700 | [diff] [blame] | 175 | |
Damien George | 8ba8324 | 2014-08-24 17:40:24 +0100 | [diff] [blame] | 176 | tm->tm_yday = mod_time_year_day(tm->tm_year, tm->tm_mon, tm->tm_mday); |
| 177 | } |
Dave Hylands | 6678595 | 2014-08-19 18:38:38 -0700 | [diff] [blame] | 178 | |
| 179 | /// \function localtime([secs]) |
| 180 | /// Convert a time expressed in seconds since Jan 1, 2000 into an 8-tuple which |
| 181 | /// contains: (year, month, mday, hour, minute, second, weekday, yearday) |
| 182 | /// If secs is not provided or None, then the current time from the RTC is used. |
| 183 | /// year includes the century (for example 2014) |
| 184 | /// month is 1-12 |
| 185 | /// mday is 1-31 |
| 186 | /// hour is 0-23 |
| 187 | /// minute is 0-59 |
| 188 | /// second is 0-59 |
| 189 | /// weekday is 0-6 for Mon-Sun. |
| 190 | /// yearday is 1-366 |
Damien George | ecc88e9 | 2014-08-30 00:35:11 +0100 | [diff] [blame] | 191 | STATIC mp_obj_t time_localtime(mp_uint_t n_args, const mp_obj_t *args) { |
Dave Hylands | 6678595 | 2014-08-19 18:38:38 -0700 | [diff] [blame] | 192 | if (n_args == 0 || args[0] == mp_const_none) { |
| 193 | // get current date and time |
| 194 | // note: need to call get time then get date to correctly access the registers |
| 195 | RTC_DateTypeDef date; |
| 196 | RTC_TimeTypeDef time; |
| 197 | HAL_RTC_GetTime(&RTCHandle, &time, FORMAT_BIN); |
| 198 | HAL_RTC_GetDate(&RTCHandle, &date, FORMAT_BIN); |
| 199 | mp_obj_t tuple[8] = { |
| 200 | mp_obj_new_int(2000 + date.Year), |
| 201 | mp_obj_new_int(date.Month), |
| 202 | mp_obj_new_int(date.Date), |
| 203 | mp_obj_new_int(time.Hours), |
| 204 | mp_obj_new_int(time.Minutes), |
| 205 | mp_obj_new_int(time.Seconds), |
| 206 | mp_obj_new_int(date.WeekDay - 1), |
| 207 | mp_obj_new_int(mod_time_year_day(2000 + date.Year, date.Month, date.Date)), |
| 208 | }; |
| 209 | return mp_obj_new_tuple(8, tuple); |
Damien George | 8ba8324 | 2014-08-24 17:40:24 +0100 | [diff] [blame] | 210 | } else { |
| 211 | mp_int_t seconds = mp_obj_get_int(args[0]); |
| 212 | mod_struct_time tm; |
| 213 | mod_time_seconds_since_2000_to_struct_time(seconds, &tm); |
| 214 | mp_obj_t tuple[8] = { |
| 215 | tuple[0] = mp_obj_new_int(tm.tm_year), |
| 216 | tuple[1] = mp_obj_new_int(tm.tm_mon), |
| 217 | tuple[2] = mp_obj_new_int(tm.tm_mday), |
| 218 | tuple[3] = mp_obj_new_int(tm.tm_hour), |
| 219 | tuple[4] = mp_obj_new_int(tm.tm_min), |
| 220 | tuple[5] = mp_obj_new_int(tm.tm_sec), |
| 221 | tuple[6] = mp_obj_new_int(tm.tm_wday), |
| 222 | tuple[7] = mp_obj_new_int(tm.tm_yday), |
| 223 | }; |
| 224 | return mp_obj_new_tuple(8, tuple); |
Dave Hylands | 6678595 | 2014-08-19 18:38:38 -0700 | [diff] [blame] | 225 | } |
Damien George | d6cbbc5 | 2014-05-08 22:25:49 +0100 | [diff] [blame] | 226 | } |
Dave Hylands | 6678595 | 2014-08-19 18:38:38 -0700 | [diff] [blame] | 227 | MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(time_localtime_obj, 0, 1, time_localtime); |
| 228 | |
| 229 | |
| 230 | /// \function mktime() |
| 231 | /// This is inverse function of localtime. It's argument is a full 8-tuple |
| 232 | /// which expresses a time as per localtime. It returns an integer which is |
| 233 | /// the number of seconds since Jan 1, 2000. |
| 234 | STATIC mp_obj_t time_mktime(mp_obj_t tuple) { |
| 235 | |
Damien George | d03c681 | 2014-10-05 21:51:54 +0100 | [diff] [blame] | 236 | mp_uint_t len; |
Dave Hylands | 6678595 | 2014-08-19 18:38:38 -0700 | [diff] [blame] | 237 | mp_obj_t *elem; |
| 238 | |
| 239 | mp_obj_get_array(tuple, &len, &elem); |
| 240 | |
| 241 | // localtime generates a tuple of len 8. CPython uses 9, so we accept both. |
| 242 | if (len < 8 || len > 9) { |
| 243 | nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "mktime needs a tuple of length 8 or 9 (%d given)", len)); |
| 244 | } |
| 245 | |
| 246 | mp_int_t year = mp_obj_get_int(elem[0]); |
| 247 | mp_int_t month = mp_obj_get_int(elem[1]); |
| 248 | mp_int_t mday = mp_obj_get_int(elem[2]); |
| 249 | mp_int_t hours = mp_obj_get_int(elem[3]); |
| 250 | mp_int_t minutes = mp_obj_get_int(elem[4]); |
| 251 | mp_int_t seconds = mp_obj_get_int(elem[5]); |
| 252 | |
Damien George | 8ba8324 | 2014-08-24 17:40:24 +0100 | [diff] [blame] | 253 | // Normalise the tuple. This allows things like: |
Dave Hylands | 6678595 | 2014-08-19 18:38:38 -0700 | [diff] [blame] | 254 | // |
| 255 | // tm_tomorrow = list(time.localtime()) |
| 256 | // tm_tomorrow[2] += 1 # Adds 1 to mday |
| 257 | // tomorrow = time.mktime(tm_tommorrow) |
Damien George | 8ba8324 | 2014-08-24 17:40:24 +0100 | [diff] [blame] | 258 | // |
Dave Hylands | 6678595 | 2014-08-19 18:38:38 -0700 | [diff] [blame] | 259 | // And not have to worry about all the weird overflows. |
| 260 | // |
| 261 | // You can subtract dates/times this way as well. |
| 262 | |
| 263 | minutes += seconds / 60; |
| 264 | if ((seconds = seconds % 60) < 0) { |
| 265 | seconds += 60; |
| 266 | minutes--; |
| 267 | } |
| 268 | |
| 269 | hours += minutes / 60; |
| 270 | if ((minutes = minutes % 60) < 0) { |
| 271 | minutes += 60; |
| 272 | hours--; |
| 273 | } |
| 274 | |
| 275 | mday += hours / 24; |
| 276 | if ((hours = hours % 24) < 0) { |
| 277 | hours += 24; |
| 278 | mday--; |
| 279 | } |
| 280 | |
| 281 | month--; // make month zero based |
| 282 | year += month / 12; |
| 283 | if ((month = month % 12) < 0) { |
| 284 | month += 12; |
| 285 | year--; |
| 286 | } |
| 287 | month++; // back to one based |
| 288 | |
| 289 | while (mday < 1) { |
| 290 | if (--month == 0) { |
| 291 | month = 12; |
| 292 | year--; |
| 293 | } |
Damien George | 8ba8324 | 2014-08-24 17:40:24 +0100 | [diff] [blame] | 294 | mday += mod_time_days_in_month(year, month); |
Dave Hylands | 6678595 | 2014-08-19 18:38:38 -0700 | [diff] [blame] | 295 | } |
Damien George | 8ba8324 | 2014-08-24 17:40:24 +0100 | [diff] [blame] | 296 | while (mday > mod_time_days_in_month(year, month)) { |
| 297 | mday -= mod_time_days_in_month(year, month); |
Dave Hylands | 6678595 | 2014-08-19 18:38:38 -0700 | [diff] [blame] | 298 | if (++month == 13) { |
| 299 | month = 1; |
| 300 | year++; |
| 301 | } |
| 302 | } |
| 303 | return mp_obj_new_int_from_uint(mod_time_seconds_since_2000(year, month, mday, hours, minutes, seconds)); |
| 304 | } |
| 305 | MP_DEFINE_CONST_FUN_OBJ_1(time_mktime_obj, time_mktime); |
| 306 | |
Damien George | d311655 | 2014-03-22 15:06:29 +0000 | [diff] [blame] | 307 | |
Damien George | ea439e5 | 2014-08-08 23:30:01 +0100 | [diff] [blame] | 308 | /// \function sleep(seconds) |
| 309 | /// Sleep for the given number of seconds. Seconds can be a floating-point number to |
| 310 | /// sleep for a fractional number of seconds. |
Damien George | d311655 | 2014-03-22 15:06:29 +0000 | [diff] [blame] | 311 | STATIC mp_obj_t time_sleep(mp_obj_t seconds_o) { |
Damien George | fb510b3 | 2014-06-01 13:32:54 +0100 | [diff] [blame] | 312 | #if MICROPY_PY_BUILTINS_FLOAT |
Damien George | d311655 | 2014-03-22 15:06:29 +0000 | [diff] [blame] | 313 | if (MP_OBJ_IS_INT(seconds_o)) { |
| 314 | #endif |
| 315 | HAL_Delay(1000 * mp_obj_get_int(seconds_o)); |
Damien George | fb510b3 | 2014-06-01 13:32:54 +0100 | [diff] [blame] | 316 | #if MICROPY_PY_BUILTINS_FLOAT |
Damien George | d311655 | 2014-03-22 15:06:29 +0000 | [diff] [blame] | 317 | } else { |
| 318 | HAL_Delay((uint32_t)(1000 * mp_obj_get_float(seconds_o))); |
| 319 | } |
| 320 | #endif |
| 321 | return mp_const_none; |
| 322 | } |
Damien George | d311655 | 2014-03-22 15:06:29 +0000 | [diff] [blame] | 323 | MP_DEFINE_CONST_FUN_OBJ_1(time_sleep_obj, time_sleep); |
| 324 | |
Damien George | ea439e5 | 2014-08-08 23:30:01 +0100 | [diff] [blame] | 325 | /// \function time() |
| 326 | /// Returns the number of seconds, as an integer, since 1/1/2000. |
Damien George | d6cbbc5 | 2014-05-08 22:25:49 +0100 | [diff] [blame] | 327 | STATIC mp_obj_t time_time(void) { |
| 328 | // get date and time |
| 329 | // note: need to call get time then get date to correctly access the registers |
| 330 | RTC_DateTypeDef date; |
| 331 | RTC_TimeTypeDef time; |
| 332 | HAL_RTC_GetTime(&RTCHandle, &time, FORMAT_BIN); |
| 333 | HAL_RTC_GetDate(&RTCHandle, &date, FORMAT_BIN); |
Damien George | 02bc882 | 2014-07-19 16:39:13 +0100 | [diff] [blame] | 334 | return mp_obj_new_int(mod_time_seconds_since_2000(2000 + date.Year, date.Month, date.Date, time.Hours, time.Minutes, time.Seconds)); |
Damien George | d6cbbc5 | 2014-05-08 22:25:49 +0100 | [diff] [blame] | 335 | } |
| 336 | MP_DEFINE_CONST_FUN_OBJ_0(time_time_obj, time_time); |
| 337 | |
Damien George | d311655 | 2014-03-22 15:06:29 +0000 | [diff] [blame] | 338 | STATIC const mp_map_elem_t time_module_globals_table[] = { |
Damien George | 0107e90 | 2014-10-12 20:23:47 +0100 | [diff] [blame] | 339 | { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_utime) }, |
Damien George | d311655 | 2014-03-22 15:06:29 +0000 | [diff] [blame] | 340 | |
Damien George | d6cbbc5 | 2014-05-08 22:25:49 +0100 | [diff] [blame] | 341 | { MP_OBJ_NEW_QSTR(MP_QSTR_localtime), (mp_obj_t)&time_localtime_obj }, |
Dave Hylands | 6678595 | 2014-08-19 18:38:38 -0700 | [diff] [blame] | 342 | { MP_OBJ_NEW_QSTR(MP_QSTR_mktime), (mp_obj_t)&time_mktime_obj }, |
Damien George | d311655 | 2014-03-22 15:06:29 +0000 | [diff] [blame] | 343 | { MP_OBJ_NEW_QSTR(MP_QSTR_sleep), (mp_obj_t)&time_sleep_obj }, |
Damien George | d6cbbc5 | 2014-05-08 22:25:49 +0100 | [diff] [blame] | 344 | { MP_OBJ_NEW_QSTR(MP_QSTR_time), (mp_obj_t)&time_time_obj }, |
Damien George | d311655 | 2014-03-22 15:06:29 +0000 | [diff] [blame] | 345 | }; |
| 346 | |
Damien George | 8b0535e | 2014-04-05 21:53:54 +0100 | [diff] [blame] | 347 | STATIC const mp_obj_dict_t time_module_globals = { |
| 348 | .base = {&mp_type_dict}, |
| 349 | .map = { |
| 350 | .all_keys_are_qstrs = 1, |
| 351 | .table_is_fixed_array = 1, |
Emmanuel Blot | f6932d6 | 2014-06-19 18:54:34 +0200 | [diff] [blame] | 352 | .used = MP_ARRAY_SIZE(time_module_globals_table), |
| 353 | .alloc = MP_ARRAY_SIZE(time_module_globals_table), |
Damien George | 8b0535e | 2014-04-05 21:53:54 +0100 | [diff] [blame] | 354 | .table = (mp_map_elem_t*)time_module_globals_table, |
| 355 | }, |
Damien George | d311655 | 2014-03-22 15:06:29 +0000 | [diff] [blame] | 356 | }; |
| 357 | |
Damien George | 0107e90 | 2014-10-12 20:23:47 +0100 | [diff] [blame] | 358 | const mp_obj_module_t mp_module_utime = { |
Damien George | d311655 | 2014-03-22 15:06:29 +0000 | [diff] [blame] | 359 | .base = { &mp_type_module }, |
Damien George | 0107e90 | 2014-10-12 20:23:47 +0100 | [diff] [blame] | 360 | .name = MP_QSTR_utime, |
Damien George | 8b0535e | 2014-04-05 21:53:54 +0100 | [diff] [blame] | 361 | .globals = (mp_obj_dict_t*)&time_module_globals, |
Damien George | d311655 | 2014-03-22 15:06:29 +0000 | [diff] [blame] | 362 | }; |