Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
micropython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
micropython
Commits
ae70e98e
Commit
ae70e98e
authored
Oct 19, 2015
by
danicampora
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cc3200: Fix time.ticks_* functions.
parent
8faf2dc7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
6 deletions
+6
-6
cc3200/mods/modutime.c
cc3200/mods/modutime.c
+5
-4
tests/wipy/time.py
tests/wipy/time.py
+1
-2
No files found.
cc3200/mods/modutime.c
View file @
ae70e98e
...
...
@@ -32,6 +32,7 @@
#include MICROPY_HAL_H
#include "py/nlr.h"
#include "py/obj.h"
#include "py/smallint.h"
#include "timeutils.h"
#include "inc/hw_types.h"
#include "inc/hw_ints.h"
...
...
@@ -152,7 +153,7 @@ STATIC mp_obj_t time_ticks_ms(void) {
// We want to "cast" the 32 bit unsigned into a small-int. This means
// copying the MSB down 1 bit (extending the sign down), which is
// equivalent to just using the MP_OBJ_NEW_SMALL_INT macro.
return
MP_OBJ_NEW_SMALL_INT
(
HAL_GetTick
());
return
MP_OBJ_NEW_SMALL_INT
(
HAL_GetTick
()
&
MP_SMALL_INT_POSITIVE_MASK
);
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_0
(
time_ticks_ms_obj
,
time_ticks_ms
);
...
...
@@ -160,7 +161,7 @@ STATIC mp_obj_t time_ticks_us(void) {
// We want to "cast" the 32 bit unsigned into a small-int. This means
// copying the MSB down 1 bit (extending the sign down), which is
// equivalent to just using the MP_OBJ_NEW_SMALL_INT macro.
return
MP_OBJ_NEW_SMALL_INT
(
sys_tick_get_microseconds
());
return
MP_OBJ_NEW_SMALL_INT
(
sys_tick_get_microseconds
()
&
MP_SMALL_INT_POSITIVE_MASK
);
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_0
(
time_ticks_us_obj
,
time_ticks_us
);
...
...
@@ -168,7 +169,7 @@ STATIC mp_obj_t time_ticks_cpu(void) {
// We want to "cast" the 32 bit unsigned into a small-int. This means
// copying the MSB down 1 bit (extending the sign down), which is
// equivalent to just using the MP_OBJ_NEW_SMALL_INT macro.
return
MP_OBJ_NEW_SMALL_INT
(
SysTickValueGet
());
return
MP_OBJ_NEW_SMALL_INT
(
SysTickValueGet
()
&
MP_SMALL_INT_POSITIVE_MASK
);
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_0
(
time_ticks_cpu_obj
,
time_ticks_cpu
);
...
...
@@ -178,7 +179,7 @@ STATIC mp_obj_t time_ticks_diff(mp_obj_t t0, mp_obj_t t1) {
// equivalent to just using the MP_OBJ_NEW_SMALL_INT macro.
uint32_t
start
=
mp_obj_get_int
(
t0
);
uint32_t
end
=
mp_obj_get_int
(
t1
);
return
MP_OBJ_NEW_SMALL_INT
((
end
>
start
)
?
(
end
-
start
)
:
(
start
-
end
)
);
return
MP_OBJ_NEW_SMALL_INT
((
end
-
start
)
&
MP_SMALL_INT_POSITIVE_MASK
);
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_2
(
time_ticks_diff_obj
,
time_ticks_diff
);
...
...
tests/wipy/time.py
View file @
ae70e98e
...
...
@@ -43,7 +43,6 @@ def spot_test(seconds, expected_time):
return
print
(
"time.localtime("
,
seconds
,
") returned"
,
actual_time
,
"(pass)"
)
test
()
spot_test
(
0
,
(
2000
,
1
,
1
,
0
,
0
,
0
,
5
,
1
))
spot_test
(
1
,
(
2000
,
1
,
1
,
0
,
0
,
1
,
5
,
1
))
...
...
@@ -75,4 +74,4 @@ print(time.ticks_diff(t1, t2) < 2000)
t1
=
time
.
ticks_cpu
()
t2
=
time
.
ticks_cpu
()
print
(
time
.
ticks_diff
(
t1
,
t2
)
<
16384
)
print
(
time
.
ticks_diff
(
t1
,
t2
)
>=
0
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment