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
cdd95ce7
Commit
cdd95ce7
authored
Jun 01, 2021
by
robert-hh
Committed by
Damien George
Jun 03, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mimxrt/machine_timer: Reuse any existing timer objects.
So there is a 1-1 mapping of hardware timer to Python object.
parent
5226d6e1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
8 deletions
+20
-8
ports/mimxrt/machine_timer.c
ports/mimxrt/machine_timer.c
+20
-8
No files found.
ports/mimxrt/machine_timer.c
View file @
cdd95ce7
...
...
@@ -31,7 +31,6 @@
#include "fsl_pit.h"
#include "modmachine.h"
#define ALARM_ID_INVALID (-1)
#define TIMER_MODE_ONE_SHOT (0)
#define TIMER_MODE_PERIODIC (1)
#define TIMER_MIN_PERIOD 1
...
...
@@ -96,8 +95,6 @@ STATIC mp_obj_t machine_timer_init_helper(machine_timer_obj_t *self, size_t n_ar
mp_arg_val_t
args
[
MP_ARRAY_SIZE
(
allowed_args
)];
mp_arg_parse_all
(
n_args
,
pos_args
,
kw_args
,
MP_ARRAY_SIZE
(
allowed_args
),
allowed_args
,
args
);
MP_STATE_PORT
(
timer_table
)[
self
->
id
]
=
self
;
// Insert into the table
self
->
mode
=
args
[
ARG_mode
].
u_int
;
if
(
args
[
ARG_freq
].
u_obj
!=
mp_const_none
)
{
// Frequency specified in Hz
...
...
@@ -133,9 +130,7 @@ STATIC mp_obj_t machine_timer_init_helper(machine_timer_obj_t *self, size_t n_ar
}
STATIC
mp_obj_t
machine_timer_make_new
(
const
mp_obj_type_t
*
type
,
size_t
n_args
,
size_t
n_kw
,
const
mp_obj_t
*
args
)
{
machine_timer_obj_t
*
self
=
m_new_obj_with_finaliser
(
machine_timer_obj_t
);
self
->
base
.
type
=
&
machine_timer_type
;
self
->
id
=
ALARM_ID_INVALID
;
machine_timer_obj_t
*
self
;
// Get timer id in the range of 0..2
mp_int_t
id
=
0
;
...
...
@@ -148,6 +143,16 @@ STATIC mp_obj_t machine_timer_make_new(const mp_obj_type_t *type, size_t n_args,
mp_raise_ValueError
(
MP_ERROR_TEXT
(
"Timer does not exist"
));
}
// check, if a timer exists at that channel and stop it first
if
(
MP_STATE_PORT
(
timer_table
)[
id
]
!=
NULL
)
{
PIT_StopTimer
(
PIT
,
channel_no
[
id
]);
self
=
MP_STATE_PORT
(
timer_table
)[
id
];
}
else
{
self
=
m_new_obj_with_finaliser
(
machine_timer_obj_t
);
self
->
base
.
type
=
&
machine_timer_type
;
MP_STATE_PORT
(
timer_table
)[
id
]
=
self
;
}
// Set initial values
self
->
id
=
id
;
self
->
channel
=
channel_no
[
id
];
...
...
@@ -162,6 +167,14 @@ STATIC mp_obj_t machine_timer_make_new(const mp_obj_type_t *type, size_t n_args,
return
MP_OBJ_FROM_PTR
(
self
);
}
STATIC
mp_obj_t
machine_timer___del__
(
mp_obj_t
self_in
)
{
machine_timer_obj_t
*
self
=
MP_OBJ_TO_PTR
(
self_in
);
PIT_StopTimer
(
PIT
,
self
->
channel
);
MP_STATE_PORT
(
timer_table
)[
self
->
id
]
=
NULL
;
return
mp_const_none
;
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_1
(
machine_timer___del___obj
,
machine_timer___del__
);
STATIC
mp_obj_t
machine_timer_init
(
size_t
n_args
,
const
mp_obj_t
*
args
,
mp_map_t
*
kw_args
)
{
machine_timer_obj_t
*
self
=
MP_OBJ_TO_PTR
(
args
[
0
]);
PIT_StopTimer
(
PIT
,
self
->
channel
);
...
...
@@ -172,7 +185,6 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_timer_init_obj, 1, machine_timer_init)
STATIC
mp_obj_t
machine_timer_deinit
(
mp_obj_t
self_in
)
{
machine_timer_obj_t
*
self
=
MP_OBJ_TO_PTR
(
self_in
);
PIT_StopTimer
(
PIT
,
self
->
channel
);
MP_STATE_PORT
(
timer_table
)[
self
->
id
]
=
NULL
;
return
mp_const_none
;
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_1
(
machine_timer_deinit_obj
,
machine_timer_deinit
);
...
...
@@ -192,7 +204,7 @@ void machine_timer_init_PIT(void) {
}
STATIC
const
mp_rom_map_elem_t
machine_timer_locals_dict_table
[]
=
{
{
MP_ROM_QSTR
(
MP_QSTR___del__
),
MP_ROM_PTR
(
&
machine_timer_
deinit
_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR___del__
),
MP_ROM_PTR
(
&
machine_timer_
__del__
_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_init
),
MP_ROM_PTR
(
&
machine_timer_init_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_deinit
),
MP_ROM_PTR
(
&
machine_timer_deinit_obj
)
},
...
...
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