Skip to content

Commit 2e33b60

Browse files
committed
drivers: counter: counter_mspm0: misc fixes
instead of hardcoding the values of the cpu speed, just parse the sysclock. Also try to follow the spec and return the correct error codes Signed-off-by: Dimitris Karnikis <[email protected]>
1 parent 34f1778 commit 2e33b60

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

drivers/counter/counter_mspm0.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct counter_mspm0_config {
3232
struct counter_mspm0_data {
3333
const struct counter_mspm0_config *config;
3434
struct counter_mspm0_channel_data *channel_data;
35-
uint32_t freq;
35+
uint32_t frequency;
3636
DL_Timer_TimerConfig time_cfg;
3737
struct k_spinlock spinlock;
3838
};
@@ -63,7 +63,7 @@ static int counter_mspm0_set_alarm(const struct device *dev, uint8_t chan,
6363
// NOTE: we only support only 1 channel
6464
if (chan != 0) {
6565
LOG_ERR("Unsupported channel: %d", chan);
66-
return -EINVAL;
66+
return -ENOTSUP;
6767
}
6868

6969
struct counter_mspm0_data *data = dev->data;
@@ -89,7 +89,7 @@ static int counter_mspm0_cancel_alarm(const struct device *dev, uint8_t chan)
8989
// NOTE: we only support only 1 channel
9090
if (chan != 0) {
9191
LOG_ERR("Unsupported channel: %d", chan);
92-
return -1;
92+
return -ENOTSUP;
9393
}
9494

9595
struct counter_mspm0_data *data = dev->data;
@@ -108,7 +108,7 @@ static uint32_t counter_mspm0_get_freq(const struct device *dev)
108108
const struct counter_mspm0_config *cfg = dev->config;
109109
const DL_Timer_ClockConfig clock_cfg = cfg->clock_cfg;
110110
// freq = (timer_clk_source / ((div_ratio + 1) * (prescale + 1))
111-
return data->freq / ((clock_cfg.divideRatio + 1) * (clock_cfg.prescale + 1));
111+
return data->frequency / ((clock_cfg.divideRatio + 1) * (clock_cfg.prescale + 1));
112112
}
113113

114114
static const struct counter_driver_api counter_mspm0_driver_api = {
@@ -139,6 +139,7 @@ static int counter_mspm0_init(const struct device *dev)
139139
DL_Timer_enableInterrupt(cfg->timer, DL_TIMER_INTERRUPT_ZERO_EVENT);
140140
cfg->interrupt_init_function(dev);
141141
DL_Timer_enableClock(cfg->timer);
142+
142143
return 0;
143144
}
144145

@@ -178,7 +179,7 @@ static int counter_mspm0_init(const struct device *dev)
178179
static struct counter_mspm0_data counter_mspm0_##inst##_data = { \
179180
.config = &counter_mspm0_##inst##_cfg, \
180181
.channel_data = counter##inst##_channel_data, \
181-
.freq = DT_PROP(DT_DRV_INST(inst), clock_frequency), \
182+
.frequency = DT_INST_PROP_BY_PHANDLE(inst, clocks, clock_frequency), \
182183
.time_cfg = \
183184
{ \
184185
.timerMode = DT_PROP(DT_DRV_INST(inst), mode), \

0 commit comments

Comments
 (0)