-
Notifications
You must be signed in to change notification settings - Fork 7.6k
MSPM0: RTC Support #90844
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
base: main
Are you sure you want to change the base?
MSPM0: RTC Support #90844
Conversation
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.
Please add an overlay to and test out the driver with https://docs.zephyrproject.org/latest/hardware/peripherals/rtc.html#rtc-device-driver-test-suite :)
dts/bindings/rtc/ti,mspm0-rtc.yaml
Outdated
compatible: "ti,mspm0-rtc" | ||
|
||
include: | ||
- name: rtc.yaml |
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.
only rtc-device.yaml should be included, rtc.yaml
is an old relic :)
drivers/rtc/rtc_ti_mspm0.c
Outdated
|
||
#define DT_DRV_COMPAT ti_mspm0_rtc | ||
|
||
#include <errno.h> |
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 needed since its part of zephyr/kernel.h :)
drivers/rtc/rtc_ti_mspm0.c
Outdated
__disable_irq(); | ||
ret = alarm->is_pending ? 1 : 0; | ||
alarm->is_pending = false; | ||
__enable_irq(); |
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.
disable IRQ is not needed here as that is what a spinlock does, so you are already in a critical section here because of line 349 :)
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.
also, this is not tracking (they key part), so it seems it could break the kernel by not restoring interrupt mask to correct state :) I have not seen __disable_irq() before
drivers/rtc/rtc_ti_mspm0.c
Outdated
{ | ||
#if defined(CONFIG_RTC_ALARM) | ||
uint8_t id; | ||
uint32_t key = irq_lock(); |
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.
Use spinlock if needed :)
drivers/rtc/rtc_ti_mspm0.c
Outdated
alarm->is_pending = true; | ||
if (alarm->callback) { | ||
alarm->callback(dev, id, alarm->user_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.
Its safer to store the callback and user data in a local variable, reenable irqs as critical section is no longer needed, then call the callback. This way the callback is not called with irqs disabled (or more appropriately spinlock held) :)
drivers/rtc/rtc_ti_mspm0.c
Outdated
.base = (RTC_Regs *)DT_INST_REG_ADDR(n), \ | ||
.rtc_x = DT_INST_PROP(n, ti_rtc_x), \ | ||
.irq_config_func = ti_mspm0_config_irq_##n, \ |
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.
alingment here should be
static type sym = {
.member = foo,
};
dts/arm/ti/mspm0/mspm0.dtsi
Outdated
reg = <0x40094000 0x2000>; | ||
interrupts = <30 0>; | ||
prescaler = <1>; | ||
clock-frequency = <32768>; |
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.
missing alarms-count = <2>; property inhereted from rtc-device.yaml
:)
4e49499
to
bb57eaa
Compare
@bjarki-andreasen Updated the changes. Please have a look |
dts/bindings/rtc/ti,mspm0-rtc.yaml
Outdated
ti,rtc-x: | ||
type: boolean | ||
description: | | ||
Indicate as Real-Time-Clock_x(RTC_x) instances. |
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.
add a space between 'x('
drivers/rtc/rtc_ti_mspm0.c
Outdated
#if defined(CONFIG_RTC_ALARM) | ||
struct rtc_ti_mspm0_alarm { | ||
uint16_t mask; | ||
bool is_pending; |
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.
move these 2 attributes at the end of the structure for better alignment
drivers/rtc/rtc_ti_mspm0.c
Outdated
|
||
struct rtc_ti_mspm0_config { | ||
RTC_Regs *base; | ||
bool rtc_x; |
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.
move this attribute at the end of the structure for better alignment
const struct rtc_ti_mspm0_config *cfg = dev->config; | ||
|
||
DL_RTC_Common_disableInterrupt(cfg->base, DL_RTC_COMMON_INTERRUPT_CALENDAR_ALARM1); | ||
if (mask & RTC_ALARM_TIME_MASK_MINUTE) { |
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.
add an empty line before the if ()
const struct rtc_ti_mspm0_config *cfg = dev->config; | ||
|
||
DL_RTC_Common_disableInterrupt(cfg->base, DL_RTC_COMMON_INTERRUPT_CALENDAR_ALARM2); | ||
if (mask & RTC_ALARM_TIME_MASK_MINUTE) { |
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.
same
drivers/rtc/rtc_ti_mspm0.c
Outdated
#define RTC_TI_MAX_ALARM DT_INST_PROP(0, alarms_count) | ||
|
||
struct rtc_ti_mspm0_config { | ||
RTC_Regs *base; |
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.
s/base/regs would be better semantically, like it has been done for the uart driver.
|
||
K_SPINLOCK(&data->lock) { | ||
rtc_ti_mspm0_clear_alarm(dev, id); | ||
if (id == RTC_TI_ALARM_1) { |
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.
same
The RTC_Common APIs is the superset file in the SDK for all flavors of RTC that exist on MSPM0 devices. The base rtc apis (in rtc.h/c) should be used instead. |
RTC common(dl_rtc_common.h) is compatible with rtc and rtc_x variant in RTC IP block from MSPM0. We don't need a separate driver each, instead we can adapt the existing driver to support both. |
bb57eaa
to
6dcab95
Compare
@bjarki-andreasen Ping for review. Thanks |
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 would encourage you to add a .conf overlay to the rtc api test suite to enable CONFIG_RTC_ALARM to test them as well, looks good otherwise :)
add Real-Time Clock binding for Texas Instruments MSPM0 Family Signed-off-by: Karthikeyan Krishnasamy <[email protected]>
added Real-Time Clock driver support for Texas Instruments MSPM0 Family, currently this driver supports rtc time keeping and calendar alarms functionality Signed-off-by: Karthikeyan Krishnasamy <[email protected]>
Add a rtc support for mspm0 Signed-off-by: Karthikeyan Krishnasamy <[email protected]>
Add rtc_api test coverage support for lp_mspm0g3507 Signed-off-by: Karthikeyan Krishnasamy <[email protected]>
6dcab95
to
5bce82b
Compare
|
@bjarki-andreasen Ping for a review. Thanks |
This PR add real time clock support for Texas Instruments MSPM0 Family Series