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
1f2daf43
Commit
1f2daf43
authored
Oct 21, 2015
by
danicampora
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cc3200: Correct ticks_cpu and ticks_us functions in time module.
parent
1c7f9b16
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
37 deletions
+9
-37
cc3200/misc/mpsystick.c
cc3200/misc/mpsystick.c
+2
-20
cc3200/mods/modutime.c
cc3200/mods/modutime.c
+5
-13
tests/wipy/time.py
tests/wipy/time.py
+2
-4
No files found.
cc3200/misc/mpsystick.c
View file @
1f2daf43
...
...
@@ -58,32 +58,14 @@ void sys_tick_wait_at_least(uint32_t start_tick, uint32_t delay_ms) {
// The SysTick timer counts down at HAL_FCPU_HZ, so we can use that knowledge
// to grab a microsecond counter.
//
// We assume that HAL_GetTick returns milliseconds.
uint32_t
sys_tick_get_microseconds
(
void
)
{
mp_uint_t
irq_state
=
disable_irq
();
uint32_t
counter
=
SysTickValueGet
();
uint32_t
milliseconds
=
HAL_GetTick
();
uint32_t
status
=
(
HWREG
(
NVIC_ST_CTRL
));
enable_irq
(
irq_state
);
// It's still possible for the countflag bit to get set if the counter was
// reloaded between reading VAL and reading CTRL. With interrupts disabled
// it definitely takes less than 50 HCLK cycles between reading VAL and
// reading CTRL, so the test (counter > 50) is to cover the case where VAL
// is +ve and very close to zero, and the COUNTFLAG bit is also set.
if
((
status
&
NVIC_ST_CTRL_COUNT
)
&&
counter
>
50
)
{
// This means that the HW reloaded VAL between the time we read VAL and the
// time we read CTRL, which implies that there is an interrupt pending
// to increment the tick counter.
milliseconds
++
;
}
uint32_t
load
=
(
HWREG
(
NVIC_ST_RELOAD
));
uint32_t
load
=
SysTickPeriodGet
();
counter
=
load
-
counter
;
// Convert from decrementing to incrementing
// ((load + 1) / 1000) is the number of counts per microsecond.
//
// counter / ((load + 1) / 1000) scales from the systick clock to microseconds
// and is the same thing as (counter * 1000) / (load + 1)
return
milliseconds
*
1000
+
(
counter
*
1000
)
/
(
load
+
1
);
return
(
milliseconds
*
1000
)
+
((
counter
*
1000
)
/
load
);
}
cc3200/mods/modutime.c
View file @
1f2daf43
...
...
@@ -150,33 +150,25 @@ STATIC mp_obj_t time_sleep_us (mp_obj_t usec_in) {
STATIC
MP_DEFINE_CONST_FUN_OBJ_1
(
time_sleep_us_obj
,
time_sleep_us
);
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.
// We want to "cast" the 32 bit unsigned into a 30-bit small-int
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
);
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.
// We want to "cast" the 32 bit unsigned into a 30-bit small-int
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
);
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
()
&
MP_SMALL_INT_POSITIVE_MASK
);
// We want to "cast" the 32 bit unsigned into a 30-bit small-int
return
MP_OBJ_NEW_SMALL_INT
((
SysTickPeriodGet
()
-
SysTickValueGet
())
&
MP_SMALL_INT_POSITIVE_MASK
);
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_0
(
time_ticks_cpu_obj
,
time_ticks_cpu
);
STATIC
mp_obj_t
time_ticks_diff
(
mp_obj_t
t0
,
mp_obj_t
t1
)
{
// 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.
// We want to "cast" the 32 bit unsigned into a 30-bit small-int
uint32_t
start
=
mp_obj_get_int
(
t0
);
uint32_t
end
=
mp_obj_get_int
(
t1
);
return
MP_OBJ_NEW_SMALL_INT
((
end
-
start
)
&
MP_SMALL_INT_POSITIVE_MASK
);
...
...
tests/wipy/time.py
View file @
1f2daf43
...
...
@@ -70,8 +70,6 @@ print(abs(time.ticks_diff(t1, t2)- 50) <= 1)
t1
=
time
.
ticks_us
()
time
.
sleep_us
(
1000
)
t2
=
time
.
ticks_us
()
print
(
time
.
ticks_diff
(
t1
,
t2
)
<
20
00
)
print
(
time
.
ticks_diff
(
t1
,
t2
)
<
15
00
)
t1
=
time
.
ticks_cpu
()
t2
=
time
.
ticks_cpu
()
print
(
time
.
ticks_diff
(
t1
,
t2
)
>=
0
)
print
(
time
.
ticks_diff
(
time
.
ticks_cpu
(),
time
.
ticks_cpu
())
<
16384
)
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