Skip to content
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

Merged
merged 7 commits into from Nov 10, 2023

Conversation

decsny
Copy link
Member

@decsny decsny commented Nov 3, 2023

Add support for NXP Multirate Timer Peripheral

Enabled on LPC55XXX, RT 3 digit

Depends on #64787

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;
Copy link
Collaborator

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

Copy link
Member Author

@decsny decsny Nov 3, 2023

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?)

Copy link
Collaborator

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) {
Copy link
Collaborator

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?

Copy link
Member Author

@decsny decsny Nov 3, 2023

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

Copy link
Member Author

@decsny decsny Nov 6, 2023

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>
@decsny
Copy link
Member Author

decsny commented Nov 6, 2023

updated with rebase and clarifying comment

@@ -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)
Copy link
Collaborator

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

Copy link
Member Author

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

POST_KERNEL, \
CONFIG_COUNTER_INIT_PRIORITY, NULL);

#define DT_DRV_COMPAT nxp_mrt
Copy link
Collaborator

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?)

Copy link
Member Author

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

} \
\
static struct nxp_mrt_channel_data \
nxp_mrt_##n##_channel_datas[DT_INST_PROP(n, num_channels)]; \
Copy link
Collaborator

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?

Copy link
Member Author

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

Copy link
Collaborator

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

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;
Copy link
Collaborator

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.

Copy link
Member Author

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
Copy link
Collaborator

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.

Copy link
Member Author

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

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>
@carlescufi carlescufi merged commit fef0018 into zephyrproject-rtos:main Nov 10, 2023
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants