Skip to content

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

karthi012
Copy link
Contributor

This PR add real time clock support for Texas Instruments MSPM0 Family Series

Copy link
Collaborator

@bjarki-andreasen bjarki-andreasen left a comment

Choose a reason for hiding this comment

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

compatible: "ti,mspm0-rtc"

include:
- name: rtc.yaml
Copy link
Collaborator

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


#define DT_DRV_COMPAT ti_mspm0_rtc

#include <errno.h>
Copy link
Collaborator

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

Comment on lines 363 to 366
__disable_irq();
ret = alarm->is_pending ? 1 : 0;
alarm->is_pending = false;
__enable_irq();
Copy link
Collaborator

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

Copy link
Collaborator

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

{
#if defined(CONFIG_RTC_ALARM)
uint8_t id;
uint32_t key = irq_lock();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use spinlock if needed :)

Comment on lines 396 to 387
alarm->is_pending = true;
if (alarm->callback) {
alarm->callback(dev, id, alarm->user_data);
}
Copy link
Collaborator

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

Comment on lines 448 to 450
.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, \
Copy link
Collaborator

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,
};

reg = <0x40094000 0x2000>;
interrupts = <30 0>;
prescaler = <1>;
clock-frequency = <32768>;
Copy link
Collaborator

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

@parthitce parthitce linked an issue May 30, 2025 that may be closed by this pull request
@karthi012 karthi012 force-pushed the upstream/ti/mspm0-rtc branch from 4e49499 to bb57eaa Compare May 31, 2025 10:14
@karthi012
Copy link
Contributor Author

@bjarki-andreasen Updated the changes. Please have a look

ti,rtc-x:
type: boolean
description: |
Indicate as Real-Time-Clock_x(RTC_x) instances.
Copy link
Collaborator

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('

#if defined(CONFIG_RTC_ALARM)
struct rtc_ti_mspm0_alarm {
uint16_t mask;
bool is_pending;
Copy link
Collaborator

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


struct rtc_ti_mspm0_config {
RTC_Regs *base;
bool rtc_x;
Copy link
Collaborator

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

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

Choose a reason for hiding this comment

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

same

#define RTC_TI_MAX_ALARM DT_INST_PROP(0, alarms_count)

struct rtc_ti_mspm0_config {
RTC_Regs *base;
Copy link
Collaborator

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

Choose a reason for hiding this comment

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

same

@d-philpot
Copy link

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.

@karthi012
Copy link
Contributor Author

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.

@karthi012 karthi012 force-pushed the upstream/ti/mspm0-rtc branch from bb57eaa to 6dcab95 Compare June 21, 2025 11:56
@parthitce parthitce removed the platform: TI SimpleLink Texas Instruments SimpleLink MCU label Jun 26, 2025
@karthi012
Copy link
Contributor Author

@bjarki-andreasen Ping for review. Thanks

Copy link
Collaborator

@bjarki-andreasen bjarki-andreasen left a 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 :)

karthi012 added 4 commits July 3, 2025 16:22
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]>
@karthi012 karthi012 force-pushed the upstream/ti/mspm0-rtc branch from 6dcab95 to 5bce82b Compare July 3, 2025 11:11
@github-actions github-actions bot added the platform: TI SimpleLink Texas Instruments SimpleLink MCU label Jul 3, 2025
Copy link

sonarqubecloud bot commented Jul 3, 2025

@karthi012
Copy link
Contributor Author

karthi012 commented Jul 5, 2025

@bjarki-andreasen Ping for a review. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RTC
5 participants