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

i.MX EPIT Timer Driver #11441

Merged
merged 4 commits into from
Jan 24, 2019
Merged

i.MX EPIT Timer Driver #11441

merged 4 commits into from
Jan 24, 2019

Conversation

stanislav-poboril
Copy link
Collaborator

This adds EPIT driver and enables it on M4 core of i.MX 6SoloX SoC and on UDOO Neo Full board.
The driver conforms to the new counter API (#8340, #8331) and should be merged into topic-counters branch.

@codecov-io
Copy link

codecov-io commented Nov 16, 2018

Codecov Report

Merging #11441 into topic-counters will decrease coverage by 1.13%.
The diff coverage is n/a.

Impacted file tree graph

@@                Coverage Diff                 @@
##           topic-counters   #11441      +/-   ##
==================================================
- Coverage           55.08%   53.94%   -1.14%     
==================================================
  Files                 255      242      -13     
  Lines               28923    27654    -1269     
  Branches             6975     6717     -258     
==================================================
- Hits                15931    14917    -1014     
+ Misses              10095     9932     -163     
+ Partials             2897     2805      -92
Impacted Files Coverage Δ
lib/os/work_q.c
lib/os/mempool.c
lib/os/json.c
lib/os/fdtable.c
lib/os/crc16_sw.c
lib/os/rb.c
lib/os/crc7_sw.c
lib/os/crc8_sw.c
lib/os/base64.c
lib/os/printk.c
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6f5bf6a...d847144. Read the comment docs.


if TIMER_IMX_EPIT_1

config TIMER_IMX_EPIT_1_PRESCALER
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we put the prescaler in DTS?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've seen it set in Kconfig here in #8340, so I wanted to make it the same.
If the most of counter/timer drivers use dts, I can change it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should move the others to dts as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the prescaler setting into DTS for this pr.

Copy link
Collaborator

@galak galak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think EPIT2 is at wrong address in DTS:

devices/MCIMX6X/MCIMX6X_M4.h:#define EPIT1_BASE                               (0x420D0000u)
devices/MCIMX6X/MCIMX6X_M4.h:#define EPIT2_BASE                               (0x420D4000u)

EPIT_Type *base = get_epit_config(dev)->base;
struct imx_epit_data *driver_data = dev->driver_data;

if ((EPIT_CR_REG(base) & EPIT_CR_EN_MASK) == 0U) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it shoulld be possible to set wrap when counter is not started.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

/* (Re)enable EPIT Output Compare interrupt */
EPIT_SetIntCmd(base, true);
} else {
/* Reset reload value without affecting the actual count */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why callback=NULL resets wrap? There is no such statement in the API. Null callback mainly makes sense when channel alarms are implemented because it is establishing period.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this.

@MaureenHelm MaureenHelm added area: Counter area: API Changes to public APIs labels Nov 28, 2018
Copy link
Member

@MaureenHelm MaureenHelm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add counter to the list of supported features in the board yaml and doc, and update tests/drivers/counter/counter_basic_api to run on this board?

# SPDX-License-Identifier: Apache-2.0
#

config TIMER_IMX_EPIT
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename this to COUNTER_IMX_EPIT

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -0,0 +1,206 @@
/*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename the file to counter_imx_epit.c

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

default y

config TIMER_IMX_EPIT_2
default n
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can remove these two lines

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@stanislav-poboril
Copy link
Collaborator Author

Can you also add counter to the list of supported features in the board yaml and doc, and update tests/drivers/counter/counter_basic_api to run on this board?

@MaureenHelm @nordic-krch I've added two commits for the tests, one fixes the compilation errors existing on the topic-counter branch at the moment and the other adds support for the UDOO Neo board.
Note that the EPIT timer has just one compare register. As this is used to fire the wrap callback, there are zero channels available. I had to modify the test to look at the number of available channels first and skip some tests if needed.

How about the functionality when only one compare register is available? We have some options:

  1. The EPIT implementation could stay as it is now - no channel alarms, wrap callback available.
  2. Return error if counter_set_wrap() is called with non-null callback. Support one channel alarm.
  3. After initialisation of the driver, counter_get_num_of_channels() would return 1. If counter_set_wrap()
    is called with non-null callback, counter_get_num_of_channels() would return 0 and it will not be allowed to set a channel alarm. If counter_set_wrap() is called with null callback, counter_get_num_of_channels() would still return 1 and allow to set one channel alarm. But I think the counter_get_num_of_channels() is meant to be consistent and always number the same number of channels, although it is not stated in the API documentation explicitly.

Copy link
Contributor

@dbkinder dbkinder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for doc changes

@nordic-krch
Copy link
Contributor

@stanislav-poboril could you rebase?

regarding the approach when only one channel is available. There are 2 scenarios that can be covered with that:

  • periodic alarm
  • single-shot alarm.

For periodic alarm you need set_wrap to indicate that counter must be reset on wrap. For single shot you can use set_alarm or alternatively use set_wrap and disable counter in the callback to ensure single-shot functionality. Imo, to keep it simple i would stick with set_wrap only. The cost is that user must call counter_disable to avoid getting periodic callback.

@stanislav-poboril
Copy link
Collaborator Author

rebased

@MaureenHelm
Copy link
Member

@nordic-krch Please revisit

@nordic-krch nordic-krch force-pushed the topic-counters branch 2 times, most recently from 2f603c6 to 72f7261 Compare January 21, 2019 08:19
Add shim driver for i.MX EPIT (Enhanced Periodic Interrupt Timer)
peripheral which can be used for i.MX6SoloX, i.MX7D and other i.MX socs.

Origin: Original

Signed-off-by: Stanislav Poboril <[email protected]>
Add EPIT (Enhanced Periodic Interrupt Timer) peripheral support
for i.MX6SoloX soc.

Origin: Original

Signed-off-by: Stanislav Poboril <[email protected]>
Enabled EPIT (Enhanced Periodic Interrupt Timer) in Cortex-M4 core
of Udoo Neo Full board so the counter API could be used there.

Origin: Original

Signed-off-by: Stanislav Poboril <[email protected]>
Tests i.MX EPIT timer peripheral driver. Since it supports zero number
of channel alarms, some tests had to be adjusted to look at the
number of channel alarms supported first.

Signed-off-by: Stanislav Poboril <[email protected]>
@stanislav-poboril
Copy link
Collaborator Author

Rebased and updated after the merge of #11572.

@nordic-krch nordic-krch merged commit 26b5136 into zephyrproject-rtos:topic-counters Jan 24, 2019
@stanislav-poboril stanislav-poboril deleted the imx6sx_epit branch January 24, 2019 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: API Changes to public APIs area: Counter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants