|
4 | 4 | from copy import copy as _copy
|
5 | 5 | from functools import wraps as _wraps
|
6 | 6 |
|
| 7 | +from artiq.language import units as _units |
| 8 | + |
7 | 9 |
|
8 | 10 | class int64(int):
|
9 | 11 | """64-bit integers for static compilation.
|
@@ -232,8 +234,6 @@ def _not_implemented(self, *args, **kwargs):
|
232 | 234 | take_time = _not_implemented
|
233 | 235 | get_time = _not_implemented
|
234 | 236 | set_time = _not_implemented
|
235 |
| - time_to_cycles = _not_implemented |
236 |
| - cycles_to_time = _not_implemented |
237 | 237 |
|
238 | 238 | _time_manager = _DummyTimeManager()
|
239 | 239 |
|
@@ -323,18 +323,30 @@ def at(time):
|
323 | 323 | _time_manager.set_time(time)
|
324 | 324 |
|
325 | 325 |
|
326 |
| -def time_to_cycles(time): |
| 326 | +def time_to_cycles(time, core=None): |
327 | 327 | """Converts time to the corresponding number of RTIO cycles.
|
328 | 328 |
|
| 329 | + :param time: Time (in seconds) to convert. |
| 330 | + :param core: Core device for which to perform the conversion. Specify only |
| 331 | + when running in the interpreter (not in kernel). |
| 332 | +
|
329 | 333 | """
|
330 |
| - return _time_manager.time_to_cycles(time) |
| 334 | + if core is None: |
| 335 | + raise ValueError("Core device must be specified for time conversion") |
| 336 | + return int64(time.amount//core.runtime_env.ref_period) |
331 | 337 |
|
332 | 338 |
|
333 |
| -def cycles_to_time(cycles): |
| 339 | +def cycles_to_time(cycles, core=None): |
334 | 340 | """Converts RTIO cycles to the corresponding time.
|
335 | 341 |
|
| 342 | + :param time: Cycle count to convert. |
| 343 | + :param core: Core device for which to perform the conversion. Specify only |
| 344 | + when running in the interpreter (not in kernel). |
| 345 | +
|
336 | 346 | """
|
337 |
| - return _time_manager.cycles_to_time(cycles) |
| 347 | + if core is None: |
| 348 | + raise ValueError("Core device must be specified for time conversion") |
| 349 | + return cycles*core.runtime_env.ref_period*_units.s |
338 | 350 |
|
339 | 351 |
|
340 | 352 | def syscall(*args):
|
|
0 commit comments