Lines Matching +full:zephyr +full:- +full:base
5 * SPDX-License-Identifier: Apache-2.0
10 #include <zephyr/drivers/counter.h>
11 #include <zephyr/drivers/clock_control.h>
12 #include <zephyr/irq.h>
14 #include <zephyr/logging/log.h>
15 #include <zephyr/sys/barrier.h>
19 #define DEV_CFG(_dev) ((const struct mcux_gpt_config *)(_dev)->config)
20 #define DEV_DATA(_dev) ((struct mcux_gpt_data *)(_dev)->data)
48 GPT_Type *base = get_base(dev); in mcux_gpt_start() local
50 GPT_StartTimer(base); in mcux_gpt_start()
57 GPT_Type *base = get_base(dev); in mcux_gpt_stop() local
59 GPT_StopTimer(base); in mcux_gpt_stop()
66 GPT_Type *base = get_base(dev); in mcux_gpt_get_value() local
68 *ticks = GPT_GetCurrentTimerCount(base); in mcux_gpt_get_value()
75 GPT_Type *base = get_base(dev); in mcux_gpt_set_alarm() local
76 struct mcux_gpt_data *data = dev->data; in mcux_gpt_set_alarm()
78 uint32_t current = GPT_GetCurrentTimerCount(base); in mcux_gpt_set_alarm()
79 uint32_t ticks = alarm_cfg->ticks; in mcux_gpt_set_alarm()
83 return -EINVAL; in mcux_gpt_set_alarm()
86 if ((alarm_cfg->flags & COUNTER_ALARM_CFG_ABSOLUTE) == 0) { in mcux_gpt_set_alarm()
90 if (data->alarm_callback) { in mcux_gpt_set_alarm()
91 return -EBUSY; in mcux_gpt_set_alarm()
94 data->alarm_callback = alarm_cfg->callback; in mcux_gpt_set_alarm()
95 data->alarm_user_data = alarm_cfg->user_data; in mcux_gpt_set_alarm()
97 GPT_SetOutputCompareValue(base, kGPT_OutputCompare_Channel1, in mcux_gpt_set_alarm()
99 GPT_EnableInterrupts(base, kGPT_OutputCompare1InterruptEnable); in mcux_gpt_set_alarm()
106 GPT_Type *base = get_base(dev); in mcux_gpt_cancel_alarm() local
107 struct mcux_gpt_data *data = dev->data; in mcux_gpt_cancel_alarm()
111 return -EINVAL; in mcux_gpt_cancel_alarm()
114 GPT_DisableInterrupts(base, kGPT_OutputCompare1InterruptEnable); in mcux_gpt_cancel_alarm()
115 data->alarm_callback = NULL; in mcux_gpt_cancel_alarm()
122 GPT_Type *base = get_base(dev); in mcux_gpt_isr() local
123 struct mcux_gpt_data *data = dev->data; in mcux_gpt_isr()
124 uint32_t current = GPT_GetCurrentTimerCount(base); in mcux_gpt_isr()
127 status = GPT_GetStatusFlags(base, kGPT_OutputCompare1Flag | in mcux_gpt_isr()
129 GPT_ClearStatusFlags(base, status); in mcux_gpt_isr()
132 if ((status & kGPT_OutputCompare1Flag) && data->alarm_callback) { in mcux_gpt_isr()
133 GPT_DisableInterrupts(base, in mcux_gpt_isr()
135 counter_alarm_callback_t alarm_cb = data->alarm_callback; in mcux_gpt_isr()
136 data->alarm_callback = NULL; in mcux_gpt_isr()
137 alarm_cb(dev, 0, current, data->alarm_user_data); in mcux_gpt_isr()
140 if ((status & kGPT_RollOverFlag) && data->top_callback) { in mcux_gpt_isr()
141 data->top_callback(dev, data->top_user_data); in mcux_gpt_isr()
147 GPT_Type *base = get_base(dev); in mcux_gpt_get_pending_int() local
149 return GPT_GetStatusFlags(base, kGPT_OutputCompare1Flag); in mcux_gpt_get_pending_int()
155 const struct mcux_gpt_config *config = dev->config; in mcux_gpt_set_top_value()
156 GPT_Type *base = get_base(dev); in mcux_gpt_set_top_value() local
157 struct mcux_gpt_data *data = dev->data; in mcux_gpt_set_top_value()
159 if (cfg->ticks != config->info.max_top_value) { in mcux_gpt_set_top_value()
161 config->info.max_top_value); in mcux_gpt_set_top_value()
162 return -ENOTSUP; in mcux_gpt_set_top_value()
165 data->top_callback = cfg->callback; in mcux_gpt_set_top_value()
166 data->top_user_data = cfg->user_data; in mcux_gpt_set_top_value()
168 GPT_EnableInterrupts(base, kGPT_RollOverFlagInterruptEnable); in mcux_gpt_set_top_value()
175 const struct mcux_gpt_config *config = dev->config; in mcux_gpt_get_top_value()
177 return config->info.max_top_value; in mcux_gpt_get_top_value()
182 const struct mcux_gpt_config *config = dev->config; in mcux_gpt_init()
185 GPT_Type *base; in mcux_gpt_init() local
189 if (!device_is_ready(config->clock_dev)) { in mcux_gpt_init()
191 return -ENODEV; in mcux_gpt_init()
194 if (clock_control_get_rate(config->clock_dev, config->clock_subsys, in mcux_gpt_init()
196 return -EINVAL; in mcux_gpt_init()
200 if (clock_freq % config->info.freq) { in mcux_gpt_init()
201 LOG_ERR("Cannot Adjust GPT freq to %u\n", config->info.freq); in mcux_gpt_init()
203 return -EINVAL; in mcux_gpt_init()
209 gptConfig.divider = clock_freq / config->info.freq; in mcux_gpt_init()
210 base = get_base(dev); in mcux_gpt_init()
211 GPT_Init(base, &gptConfig); in mcux_gpt_init()