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
29c92a40
Commit
29c92a40
authored
10 years ago
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
stmhal: Use MP_OBJ_NEW_SMALL_INT directly in pyb.micros/millis.
Also some whitespace cleanup.
parent
2bf04444
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
stmhal/modpyb.c
+8
-10
8 additions, 10 deletions
stmhal/modpyb.c
stmhal/systick.c
+20
-20
20 additions, 20 deletions
stmhal/systick.c
teensy/teensy_hal.h
+4
-9
4 additions, 9 deletions
teensy/teensy_hal.h
with
32 additions
and
39 deletions
stmhal/modpyb.c
+
8
−
10
View file @
29c92a40
...
...
@@ -198,11 +198,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_sync_obj, pyb_sync);
/// always get the right answer and not have to worry about whether pyb.millis()
/// wraps around.
STATIC
mp_obj_t
pyb_millis
(
void
)
{
// We want to "cast" the 32 bit unsigned into a small-int. So we shift it
// left by 1 to throw away the top bit, and then shift it right by one
// to sign extend.
mp_int_t
val
=
HAL_GetTick
()
<<
1
;
return
mp_obj_new_int
(
val
>>
1
);
// 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
());
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_0
(
pyb_millis_obj
,
pyb_millis
);
...
...
@@ -219,11 +218,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_millis_obj, pyb_millis);
/// always get the right answer and not have to worry about whether pyb.micros()
/// wraps around.
STATIC
mp_obj_t
pyb_micros
(
void
)
{
// We want to "cast" the 32 bit unsigned into a small-int. So we shift it
// left by 1 to throw away the top bit, and then shift it right by one
// to sign extend.
mp_int_t
val
=
sys_tick_get_microseconds
()
<<
1
;
return
mp_obj_new_int
(
val
>>
1
);
// 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
());
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_0
(
pyb_micros_obj
,
pyb_micros
);
...
...
This diff is collapsed.
Click to expand it.
stmhal/systick.c
+
20
−
20
View file @
29c92a40
...
...
@@ -51,11 +51,11 @@ void sys_tick_wait_at_least(uint32_t start_tick, uint32_t delay_ms) {
//
// We assume that HAL_GetTickis returns milliseconds.
uint32_t
sys_tick_get_microseconds
(
void
)
{
mp_int_t
enabled
=
disable_irq
();
mp_
u
int_t
irq_state
=
disable_irq
();
uint32_t
counter
=
SysTick
->
VAL
;
uint32_t
milliseconds
=
HAL_GetTick
();
uint32_t
status
=
SysTick
->
CTRL
;
enable_irq
(
enabled
);
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
...
...
This diff is collapsed.
Click to expand it.
teensy/teensy_hal.h
+
4
−
9
View file @
29c92a40
...
...
@@ -113,25 +113,20 @@ typedef struct {
#define GPIO_AF6_I2C1 6
#define GPIO_AF7_FTM1 7
__attribute__
((
always_inline
))
static
inline
void
__WFI
(
void
)
{
__attribute__
((
always_inline
))
static
inline
void
__WFI
(
void
)
{
__asm
volatile
(
"wfi"
);
}
__attribute__
((
always_inline
))
static
inline
uint32_t
__get_PRIMASK
(
void
)
{
__attribute__
((
always_inline
))
static
inline
uint32_t
__get_PRIMASK
(
void
)
{
uint32_t
result
;
__asm
volatile
(
"MRS %0, primask"
:
"=r"
(
result
));
return
(
result
);
}
__attribute__
((
always_inline
))
static
inline
void
__set_PRIMASK
(
uint32_t
priMask
)
{
__attribute__
((
always_inline
))
static
inline
void
__set_PRIMASK
(
uint32_t
priMask
)
{
__asm
volatile
(
"MSR primask, %0"
:
:
"r"
(
priMask
)
:
"memory"
);
}
uint32_t
HAL_GetTick
(
void
);
void
HAL_Delay
(
uint32_t
Delay
);
...
...
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