New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
drivers: counter: Add support for NXP Multirate Timer Peripheral #64801
drivers: counter: Add support for NXP Multirate Timer Peripheral #64801
Conversation
fe02aea
to
cdaedb0
Compare
drivers/counter/counter_nxp_mrt.c
Outdated
const struct device *clock_dev; | ||
clock_control_subsys_t clock_subsys; | ||
void (*irq_config_func)(const struct device *dev); | ||
struct nxp_mrt_channel_data *data; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please clarify why the nxp_mrt_channel_data
is stored inside the config structure and not provided to dev
structure by passing it to DEVICE_DT_INST_DEFINE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you mean. It's not stored inside the config structure, it's stored in RAM, and it is provided to the dev structure (line 247 in the DEVICE_DT_DEFINE?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am referring to void *data;
in struct device
|
||
|
||
/* If not currently running, nothing else to do but wait for counter_start */ | ||
if (!active) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't follow this. Why cannot we change the top value if counter is not active?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setting the value will start the timer, see line 99 and 107 comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I improved this comment on line 107 in the latest push
Add binding for nxp,mrt and nxp,mrt-channel. MRT is NXP multirate timer, a simple timer with multiple independent channels. Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
Add code to handle MRT subsys clock to LPC syscon driver Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
cdaedb0
to
9c3848c
Compare
updated with rebase and clarifying comment |
drivers/counter/CMakeLists.txt
Outdated
@@ -48,3 +48,4 @@ zephyr_library_sources_ifdef(CONFIG_COUNTER_TIMER_GD32 counter_gd32_timer.c) | |||
zephyr_library_sources_ifdef(CONFIG_COUNTER_SNPS_DW counter_dw_timer.c) | |||
zephyr_library_sources_ifdef(CONFIG_COUNTER_SHELL counter_timer_shell.c) | |||
zephyr_library_sources_ifdef(CONFIG_COUNTER_TIMER_RPI_PICO counter_rpi_pico_timer.c) | |||
zephyr_library_sources_ifdef(CONFIG_COUNTER_NXP_MRT counter_nxp_mrt.c) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit- can you align indentation here? It seems that a few lines, like the rpi_pico_timer
are deviating from convention, but I don't see why we should add to the trend
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it looks aligned to me, I think the issue is tabs vs spaces, I'll change it to spaces
drivers/counter/counter_nxp_mrt.c
Outdated
POST_KERNEL, \ | ||
CONFIG_COUNTER_INIT_PRIORITY, NULL); | ||
|
||
#define DT_DRV_COMPAT nxp_mrt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit- by convention, we usually define this near the top of the file (unless there is a good reason not to?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the reason no longer applies to this revision so I will move it
drivers/counter/counter_nxp_mrt.c
Outdated
} \ | ||
\ | ||
static struct nxp_mrt_channel_data \ | ||
nxp_mrt_##n##_channel_datas[DT_INST_PROP(n, num_channels)]; \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we use DT_FOREACH_CHILD
with some macro to count the number of children MRT nodes here, instead of encoding it using a devicetree property?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is overcomplicated for no reason. It is perfectly valid to encode the number of channels in DT anyways because it varies based on IP version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not saying it is invalid to encode the number of channels in DT. I saw this as a change to reduce duplicated information, but it is just a suggestion
drivers/counter/counter_nxp_mrt.c
Outdated
const struct nxp_mrt_config *config = dev->config; | ||
struct nxp_mrt_channel_data *data = dev->data; | ||
MRT_Type *base = config->base; | ||
int channel_id = data - config->data; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent trick to get the channel id:) . Could we define some kind of macro here for this, and add a documentation comment on that macro? I think that will make this a bit easier to maintain in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay
# Copyright 2023 NXP | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
description: NXP Multirate Timer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we use child-binding for the MRT channels? I guess the issue with that might be that the Kconfig symbol depends on both DT_HAS_xxx_ENABLED
symbols.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried, it is not convenient
9c3848c
to
8cbc804
Compare
Add driver for NXP Multirate Timer Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
Update counter test to test NXP MRT devices Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
Enable NXP MRT on RT5xx soc and MIMXRT595_EVK board Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
Add NXP MRT to RT6xx DT definition and add peripheral reset to soc.c Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
Support NXP MRT on LPC55XXX SOC series, enable on lpcxpresso55s69_cpu0, add test overlay to counter basic api test Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
8cbc804
to
1a45995
Compare
Add support for NXP Multirate Timer Peripheral
Enabled on LPC55XXX, RT 3 digit
Depends on #64787