Lines Matching refs:obj

106 cy_rslt_t _cyhal_timer_init_hw(cyhal_timer_t *obj, const cy_stc_tcpwm_counter_config_t *config, con…  in _cyhal_timer_init_hw()  argument
110 cyhal_resource_inst_t *timer = &obj->tcpwm.resource; in _cyhal_timer_init_hw()
111 obj->tcpwm.base = _CYHAL_TCPWM_DATA[_CYHAL_TCPWM_ADJUST_BLOCK_INDEX(timer->block_num)].base; in _cyhal_timer_init_hw()
117 obj->tcpwm.clock = *clk; in _cyhal_timer_init_hw()
118 obj->tcpwm.clock_hz = cyhal_clock_get_frequency(&obj->tcpwm.clock); in _cyhal_timer_init_hw()
119 if (CY_SYSCLK_SUCCESS != _cyhal_utils_peri_pclk_assign_divider(pclk, &(obj->tcpwm.clock))) in _cyhal_timer_init_hw()
124 …else if (CY_RSLT_SUCCESS == (result = _cyhal_utils_allocate_clock(&(obj->tcpwm.clock), timer, CYHA… in _cyhal_timer_init_hw()
126 obj->tcpwm.dedicated_clock = true; in _cyhal_timer_init_hw()
129 result = cyhal_timer_set_frequency(obj, CYHAL_TIMER_DEFAULT_FREQ * 3); in _cyhal_timer_init_hw()
131 result = cyhal_timer_set_frequency(obj, CYHAL_TIMER_DEFAULT_FREQ); in _cyhal_timer_init_hw()
135 … if (CY_SYSCLK_SUCCESS != _cyhal_utils_peri_pclk_assign_divider(pclk, &(obj->tcpwm.clock))) in _cyhal_timer_init_hw()
144 …result = Cy_TCPWM_Counter_Init(obj->tcpwm.base, _CYHAL_TCPWM_CNT_NUMBER(obj->tcpwm.resource), conf… in _cyhal_timer_init_hw()
149 _cyhal_tcpwm_init_data(&obj->tcpwm); in _cyhal_timer_init_hw()
150 Cy_TCPWM_Counter_Enable(obj->tcpwm.base, _CYHAL_TCPWM_CNT_NUMBER(obj->tcpwm.resource)); in _cyhal_timer_init_hw()
156 cy_rslt_t cyhal_timer_init(cyhal_timer_t *obj, cyhal_gpio_t pin, const cyhal_clock_t *clk) in cyhal_timer_init() argument
158 CY_ASSERT(NULL != obj); in cyhal_timer_init()
164 memset(obj, 0, sizeof(cyhal_timer_t)); in cyhal_timer_init()
171 result = cyhal_hwmgr_allocate(CYHAL_RSC_T2TIMER, &obj->t2timer.resource); in cyhal_timer_init()
174 obj->t2timer.which_timer = obj->t2timer.resource.block_num; in cyhal_timer_init()
175 result = _cyhal_t2timer_init(&obj->t2timer, NULL); in cyhal_timer_init()
178 obj->is_t2timer = true; in cyhal_timer_init()
186 obj->tcpwm.resource.type = CYHAL_RSC_INVALID; in cyhal_timer_init()
187 result = cyhal_hwmgr_allocate(CYHAL_RSC_TCPWM, &obj->tcpwm.resource); in cyhal_timer_init()
190 result = _cyhal_timer_init_hw(obj, &_cyhal_timer_default_config, clk); in cyhal_timer_init()
192 obj->is_t2timer = false; in cyhal_timer_init()
196 result = cyhal_hwmgr_allocate(CYHAL_RSC_T2TIMER, &obj->t2timer.resource); in cyhal_timer_init()
199 obj->t2timer.which_timer = obj->t2timer.resource.block_num; in cyhal_timer_init()
200 result = _cyhal_t2timer_init(&obj->t2timer, NULL); in cyhal_timer_init()
203 obj->is_t2timer = true; in cyhal_timer_init()
212 cyhal_timer_free(obj); in cyhal_timer_init()
218 cy_rslt_t cyhal_timer_init_cfg(cyhal_timer_t *obj, const cyhal_timer_configurator_t *cfg) in cyhal_timer_init_cfg() argument
220 memset(obj, 0, sizeof(cyhal_timer_t)); in cyhal_timer_init_cfg()
221 obj->tcpwm.resource = *cfg->resource; in cyhal_timer_init_cfg()
222 obj->tcpwm.owned_by_configurator = true; in cyhal_timer_init_cfg()
223 cy_rslt_t result = _cyhal_timer_init_hw(obj, cfg->config, cfg->clock); in cyhal_timer_init_cfg()
226 obj->is_t2timer = false; in cyhal_timer_init_cfg()
231 cyhal_timer_free(obj); in cyhal_timer_init_cfg()
236 cy_rslt_t cyhal_timer_configure(cyhal_timer_t *obj, const cyhal_timer_cfg_t *cfg) in cyhal_timer_configure() argument
240 if(obj->is_t2timer) in cyhal_timer_configure()
256 rslt = _cyhal_t2timer_configure(&obj->t2timer, &t2t_cfg); in cyhal_timer_configure()
261 obj->default_value = cfg->value; in cyhal_timer_configure()
269 …uint32_t old_mask = Cy_TCPWM_GetInterruptMask(obj->tcpwm.base, _CYHAL_TCPWM_CNT_NUMBER(obj->tcpwm.… in cyhal_timer_configure()
270 … Cy_TCPWM_Counter_DeInit(obj->tcpwm.base, _CYHAL_TCPWM_CNT_NUMBER(obj->tcpwm.resource), &config); in cyhal_timer_configure()
271 …rslt = (cy_rslt_t)Cy_TCPWM_Counter_Init(obj->tcpwm.base, _CYHAL_TCPWM_CNT_NUMBER(obj->tcpwm.resour… in cyhal_timer_configure()
272 Cy_TCPWM_Counter_Enable(obj->tcpwm.base, _CYHAL_TCPWM_CNT_NUMBER(obj->tcpwm.resource)); in cyhal_timer_configure()
273 …Cy_TCPWM_SetInterruptMask(obj->tcpwm.base, _CYHAL_TCPWM_CNT_NUMBER(obj->tcpwm.resource), old_mask); in cyhal_timer_configure()
276 cyhal_timer_reset(obj); in cyhal_timer_configure()
282 cy_rslt_t cyhal_timer_set_frequency(cyhal_timer_t *obj, uint32_t hz) in cyhal_timer_set_frequency() argument
287 if(obj->is_t2timer) in cyhal_timer_set_frequency()
289 result = _cyhal_t2timer_set_frequency(&obj->t2timer, hz); in cyhal_timer_set_frequency()
294 if(!obj->tcpwm.dedicated_clock) in cyhal_timer_set_frequency()
307 … uint32_t current_freq = _cyhal_utils_get_peripheral_clock_frequency(&(obj->tcpwm.resource)); in cyhal_timer_set_frequency()
310 …t)(_CYHAL_TCPWM_DATA[_CYHAL_TCPWM_ADJUST_BLOCK_INDEX(obj->tcpwm.resource.block_num)].clock_dst + o… in cyhal_timer_set_frequency()
311 …if(CY_RSLT_SUCCESS == _cyhal_utils_peri_pclk_set_divider(clk_dst, &obj->tcpwm.clock, (divider - 1)… in cyhal_timer_set_frequency()
313 if((CY_RSLT_SUCCESS == cyhal_clock_set_enabled(&obj->tcpwm.clock, false, false)) && in cyhal_timer_set_frequency()
314 (CY_RSLT_SUCCESS == cyhal_clock_set_frequency(&obj->tcpwm.clock, hz, &tolerance)) && in cyhal_timer_set_frequency()
315 (CY_RSLT_SUCCESS == cyhal_clock_set_enabled(&obj->tcpwm.clock, true, false))) in cyhal_timer_set_frequency()
318 obj->tcpwm.clock_hz = cyhal_clock_get_frequency(&obj->tcpwm.clock); in cyhal_timer_set_frequency()
330 cy_rslt_t cyhal_timer_start(cyhal_timer_t *obj) in cyhal_timer_start() argument
332 CY_ASSERT(NULL != obj); in cyhal_timer_start()
336 if (_cyhal_tcpwm_pm_transition_pending() || (obj->is_t2timer && obj->running)) in cyhal_timer_start()
346 if(obj->is_t2timer) in cyhal_timer_start()
348 result = _cyhal_t2timer_start(&obj->t2timer); in cyhal_timer_start()
351 obj->running = true; in cyhal_timer_start()
357 Cy_TCPWM_Counter_Enable(obj->tcpwm.base, _CYHAL_TCPWM_CNT_NUMBER(obj->tcpwm.resource)); in cyhal_timer_start()
359 Cy_TCPWM_TriggerStart_Single(obj->tcpwm.base, _CYHAL_TCPWM_CNT_NUMBER(obj->tcpwm.resource)); in cyhal_timer_start()
361 Cy_TCPWM_TriggerStart(obj->tcpwm.base, (1 << _CYHAL_TCPWM_CNT_NUMBER(obj->tcpwm.resource))); in cyhal_timer_start()
367 cy_rslt_t cyhal_timer_stop(cyhal_timer_t *obj) in cyhal_timer_stop() argument
369 CY_ASSERT(NULL != obj); in cyhal_timer_stop()
373 if(obj->is_t2timer) in cyhal_timer_stop()
375 result = _cyhal_t2timer_stop(&obj->t2timer); in cyhal_timer_stop()
378 obj->running = false; in cyhal_timer_stop()
384 Cy_TCPWM_Counter_Disable(obj->tcpwm.base, _CYHAL_TCPWM_CNT_NUMBER(obj->tcpwm.resource)); in cyhal_timer_stop()
390 cy_rslt_t cyhal_timer_reset(cyhal_timer_t *obj) in cyhal_timer_reset() argument
392 CY_ASSERT(NULL != obj); in cyhal_timer_reset()
396 if(obj->is_t2timer) in cyhal_timer_reset()
398 result = _cyhal_t2timer_reset(&obj->t2timer); in cyhal_timer_reset()
401 obj->running = true; in cyhal_timer_reset()
407 …Cy_TCPWM_Counter_SetCounter(obj->tcpwm.base, _CYHAL_TCPWM_CNT_NUMBER(obj->tcpwm.resource), obj->de… in cyhal_timer_reset()
413 uint32_t cyhal_timer_read(const cyhal_timer_t *obj) in cyhal_timer_read() argument
415 CY_ASSERT(NULL != obj); in cyhal_timer_read()
418 if(obj->is_t2timer) in cyhal_timer_read()
420 read_value = _cyhal_t2timer_read(&obj->t2timer); in cyhal_timer_read()
425 …read_value = Cy_TCPWM_Counter_GetCounter(obj->tcpwm.base, _CYHAL_TCPWM_CNT_NUMBER(obj->tcpwm.resou… in cyhal_timer_read()
468 cy_rslt_t cyhal_timer_connect_digital2(cyhal_timer_t *obj, cyhal_source_t source, cyhal_timer_input… in cyhal_timer_connect_digital2() argument
471 if(obj->is_t2timer) in cyhal_timer_connect_digital2()
477 return _cyhal_tcpwm_connect_digital(&(obj->tcpwm), source, tcpwm_signal, edge_type); in cyhal_timer_connect_digital2()
480 cy_rslt_t cyhal_timer_connect_digital(cyhal_timer_t *obj, cyhal_source_t source, cyhal_timer_input_… in cyhal_timer_connect_digital() argument
483 if(obj->is_t2timer) in cyhal_timer_connect_digital()
493 return cyhal_timer_connect_digital2(obj, source, signal, edge_type); in cyhal_timer_connect_digital()
495 CY_UNUSED_PARAMETER(obj); in cyhal_timer_connect_digital()
502 cy_rslt_t cyhal_timer_enable_output(cyhal_timer_t *obj, cyhal_timer_output_t signal, cyhal_source_t… in cyhal_timer_enable_output() argument
505 if(obj->is_t2timer) in cyhal_timer_enable_output()
511 return _cyhal_tcpwm_enable_output(&(obj->tcpwm), tcpwm_signal, source); in cyhal_timer_enable_output()
514 cy_rslt_t cyhal_timer_disconnect_digital(cyhal_timer_t *obj, cyhal_source_t source, cyhal_timer_inp… in cyhal_timer_disconnect_digital() argument
517 if(obj->is_t2timer) in cyhal_timer_disconnect_digital()
522 …return _cyhal_tcpwm_disconnect_digital(&(obj->tcpwm), source, _cyhal_timer_translate_input_signal(… in cyhal_timer_disconnect_digital()
525 cy_rslt_t cyhal_timer_disable_output(cyhal_timer_t *obj, cyhal_timer_output_t signal) in cyhal_timer_disable_output() argument
528 if(obj->is_t2timer) in cyhal_timer_disable_output()
533 return _cyhal_tcpwm_disable_output(&(obj->tcpwm), _cyhal_timer_translate_output_signal(signal)); in cyhal_timer_disable_output()