Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
1f2daf43
Commit
1f2daf43
authored
9 years ago
by
danicampora
Browse files
Options
Downloads
Patches
Plain Diff
cc3200: Correct ticks_cpu and ticks_us functions in time module.
parent
1c7f9b16
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
cc3200/misc/mpsystick.c
+2
-20
2 additions, 20 deletions
cc3200/misc/mpsystick.c
cc3200/mods/modutime.c
+5
-13
5 additions, 13 deletions
cc3200/mods/modutime.c
tests/wipy/time.py
+2
-4
2 additions, 4 deletions
tests/wipy/time.py
with
9 additions
and
37 deletions
cc3200/misc/mpsystick.c
+
2
−
20
View file @
1f2daf43
...
@@ -58,32 +58,14 @@ void sys_tick_wait_at_least(uint32_t start_tick, uint32_t delay_ms) {
...
@@ -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
// The SysTick timer counts down at HAL_FCPU_HZ, so we can use that knowledge
// to grab a microsecond counter.
// to grab a microsecond counter.
//
// We assume that HAL_GetTick returns milliseconds.
// We assume that HAL_GetTick returns milliseconds.
uint32_t
sys_tick_get_microseconds
(
void
)
{
uint32_t
sys_tick_get_microseconds
(
void
)
{
mp_uint_t
irq_state
=
disable_irq
();
mp_uint_t
irq_state
=
disable_irq
();
uint32_t
counter
=
SysTickValueGet
();
uint32_t
counter
=
SysTickValueGet
();
uint32_t
milliseconds
=
HAL_GetTick
();
uint32_t
milliseconds
=
HAL_GetTick
();
uint32_t
status
=
(
HWREG
(
NVIC_ST_CTRL
));
enable_irq
(
irq_state
);
enable_irq
(
irq_state
);
// It's still possible for the countflag bit to get set if the counter was
uint32_t
load
=
SysTickPeriodGet
();
// 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
));
counter
=
load
-
counter
;
// Convert from decrementing to incrementing
counter
=
load
-
counter
;
// Convert from decrementing to incrementing
return
(
milliseconds
*
1000
)
+
((
counter
*
1000
)
/
load
);
// ((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
);
}
}
This diff is collapsed.
Click to expand it.
cc3200/mods/modutime.c
+
5
−
13
View file @
1f2daf43
...
@@ -150,33 +150,25 @@ STATIC mp_obj_t time_sleep_us (mp_obj_t usec_in) {
...
@@ -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_DEFINE_CONST_FUN_OBJ_1
(
time_sleep_us_obj
,
time_sleep_us
);
STATIC
mp_obj_t
time_ticks_ms
(
void
)
{
STATIC
mp_obj_t
time_ticks_ms
(
void
)
{
// We want to "cast" the 32 bit unsigned into a small-int. This means
// We want to "cast" the 32 bit unsigned into a 30-bit small-int
// 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
()
&
MP_SMALL_INT_POSITIVE_MASK
);
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_DEFINE_CONST_FUN_OBJ_0
(
time_ticks_ms_obj
,
time_ticks_ms
);
STATIC
mp_obj_t
time_ticks_us
(
void
)
{
STATIC
mp_obj_t
time_ticks_us
(
void
)
{
// We want to "cast" the 32 bit unsigned into a small-int. This means
// We want to "cast" the 32 bit unsigned into a 30-bit small-int
// 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
()
&
MP_SMALL_INT_POSITIVE_MASK
);
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_DEFINE_CONST_FUN_OBJ_0
(
time_ticks_us_obj
,
time_ticks_us
);
STATIC
mp_obj_t
time_ticks_cpu
(
void
)
{
STATIC
mp_obj_t
time_ticks_cpu
(
void
)
{
// We want to "cast" the 32 bit unsigned into a small-int. This means
// We want to "cast" the 32 bit unsigned into a 30-bit small-int
// copying the MSB down 1 bit (extending the sign down), which is
return
MP_OBJ_NEW_SMALL_INT
((
SysTickPeriodGet
()
-
SysTickValueGet
())
&
MP_SMALL_INT_POSITIVE_MASK
);
// equivalent to just using the MP_OBJ_NEW_SMALL_INT macro.
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
);
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
)
{
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
// We want to "cast" the 32 bit unsigned into a 30-bit small-int
// copying the MSB down 1 bit (extending the sign down), which is
// equivalent to just using the MP_OBJ_NEW_SMALL_INT macro.
uint32_t
start
=
mp_obj_get_int
(
t0
);
uint32_t
start
=
mp_obj_get_int
(
t0
);
uint32_t
end
=
mp_obj_get_int
(
t1
);
uint32_t
end
=
mp_obj_get_int
(
t1
);
return
MP_OBJ_NEW_SMALL_INT
((
end
-
start
)
&
MP_SMALL_INT_POSITIVE_MASK
);
return
MP_OBJ_NEW_SMALL_INT
((
end
-
start
)
&
MP_SMALL_INT_POSITIVE_MASK
);
...
...
This diff is collapsed.
Click to expand it.
tests/wipy/time.py
+
2
−
4
View file @
1f2daf43
...
@@ -70,8 +70,6 @@ print(abs(time.ticks_diff(t1, t2)- 50) <= 1)
...
@@ -70,8 +70,6 @@ print(abs(time.ticks_diff(t1, t2)- 50) <= 1)
t1
=
time
.
ticks_us
()
t1
=
time
.
ticks_us
()
time
.
sleep_us
(
1000
)
time
.
sleep_us
(
1000
)
t2
=
time
.
ticks_us
()
t2
=
time
.
ticks_us
()
print
(
time
.
ticks_diff
(
t1
,
t2
)
<
20
00
)
print
(
time
.
ticks_diff
(
t1
,
t2
)
<
15
00
)
t1
=
time
.
ticks_cpu
()
print
(
time
.
ticks_diff
(
time
.
ticks_cpu
(),
time
.
ticks_cpu
())
<
16384
)
t2
=
time
.
ticks_cpu
()
print
(
time
.
ticks_diff
(
t1
,
t2
)
>=
0
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment