Lines Matching refs:rtc
150 static void nhw_rtc_TASKS_CLEAR(uint rtc);
151 static void nhw_rtc_signal_OVERFLOW(uint rtc);
152 static void nhw_rtc_signal_COMPARE(uint rtc, uint cc);
262 static uint64_t time_sub_us_to_counter(uint rtc, uint64_t delta_sub_us) { in time_sub_us_to_counter() argument
265 ticks = delta_sub_us / ((uint64_t)LF_CLOCK_PERIOD_subus * (nhw_rtc_st[rtc].PRESC + 1)); in time_sub_us_to_counter()
272 static uint64_t counter_to_time_sub_us(uint rtc, uint64_t counter) { in counter_to_time_sub_us() argument
275 Elapsed = counter * (uint64_t)LF_CLOCK_PERIOD_subus * (nhw_rtc_st[rtc].PRESC + 1); in counter_to_time_sub_us()
283 static uint64_t time_of_1_counter_wrap_sub_us(uint rtc) { in time_of_1_counter_wrap_sub_us() argument
284 return counter_to_time_sub_us(rtc, (uint64_t)RTC_COUNTER_MASK + 1); in time_of_1_counter_wrap_sub_us()
290 static bs_time_t get_counter_match_time(uint rtc, uint64_t counter_match, uint64_t* next_match_sub_… in get_counter_match_time() argument
292 struct rtc_status *this = &nhw_rtc_st[rtc]; in get_counter_match_time()
299 uint64_t counter_match_sub_us = counter_to_time_sub_us(rtc, counter_match); in get_counter_match_time()
312 *next_match_sub_us = time_of_1_counter_wrap_sub_us(rtc) in get_counter_match_time()
318 *next_match_sub_us += time_of_1_counter_wrap_sub_us(rtc); in get_counter_match_time()
329 for (int rtc = 0; rtc < NHW_RTC_TOTAL_INST ; rtc++) { in nhw_rtc_update_master_timer() local
330 struct rtc_status *this = &nhw_rtc_st[rtc]; in nhw_rtc_update_master_timer()
352 static void update_cc_timer(uint rtc, uint cc) { in update_cc_timer() argument
354 …nhw_rtc_st[rtc].cc_timers[cc] = get_counter_match_time(rtc, NRF_RTC_regs[rtc].CC[cc], &match_sub_u… in update_cc_timer()
361 static void update_all_cc_timers(uint rtc) { in update_all_cc_timers() argument
362 for (int cc = 0 ; cc < nhw_rtc_st[rtc].n_CCs; cc++) { in update_all_cc_timers()
363 update_cc_timer(rtc, cc); in update_all_cc_timers()
367 static void update_overflow_timer(uint rtc) { in update_overflow_timer() argument
368 struct rtc_status *this = &nhw_rtc_st[rtc]; in update_overflow_timer()
369 …this->overflow_timer = get_counter_match_time(rtc, RTC_COUNTER_MASK + 1, &this->overflow_timer_sub… in update_overflow_timer()
372 static void update_timers(int rtc) in update_timers() argument
374 update_all_cc_timers(rtc); in update_timers()
375 update_overflow_timer(rtc); in update_timers()
385 static void nhw_rtc_set_counter(uint rtc, uint64_t counter_val) in nhw_rtc_set_counter() argument
387 struct rtc_status *this = &nhw_rtc_st[rtc]; in nhw_rtc_set_counter()
390 uint64_t counter_val_sub_us = counter_to_time_sub_us(rtc, counter_val); in nhw_rtc_set_counter()
407 NRF_RTC_regs[rtc].COUNTER = counter_val; in nhw_rtc_set_counter()
409 update_timers(rtc); in nhw_rtc_set_counter()
412 static void handle_overflow_event(uint rtc) in handle_overflow_event() argument
414 struct rtc_status *this = &nhw_rtc_st[rtc]; in handle_overflow_event()
421 update_overflow_timer(rtc); //Next time it will overflow in handle_overflow_event()
423 bs_trace_raw_time(8, "RTC%i: Timer overflow\n", rtc); in handle_overflow_event()
428 nhw_rtc_signal_OVERFLOW(rtc); in handle_overflow_event()
432 for (int rtc = 0; rtc < NHW_RTC_TOTAL_INST ; rtc++) { in nhw_rtc_timer_triggered() local
433 struct rtc_status *rtc_el = &nhw_rtc_st[rtc]; in nhw_rtc_timer_triggered()
440 update_cc_timer(rtc, cc); //Next time it will match in nhw_rtc_timer_triggered()
441 nhw_rtc_signal_COMPARE(rtc, cc); in nhw_rtc_timer_triggered()
446 …handle_overflow_event(rtc); // this must always be the last event, as it might update counter_star… in nhw_rtc_timer_triggered()
472 void nhw_rtc_update_COUNTER(uint rtc) { in nhw_rtc_update_COUNTER() argument
473 struct rtc_status *this = &nhw_rtc_st[rtc]; in nhw_rtc_update_COUNTER()
474 NRF_RTC_Type *RTC_regs = &NRF_RTC_regs[rtc]; in nhw_rtc_update_COUNTER()
478 count = time_sub_us_to_counter(rtc, in nhw_rtc_update_COUNTER()
490 static void nhw_rtc_TASKS_START(uint rtc) { in nhw_rtc_TASKS_START() argument
491 struct rtc_status *this = &nhw_rtc_st[rtc]; in nhw_rtc_TASKS_START()
496 bs_trace_raw_time(5, "RTC%i: TASK_START\n", rtc); in nhw_rtc_TASKS_START()
500 this->PRESC = NRF_RTC_regs[rtc].PRESCALER; in nhw_rtc_TASKS_START()
503 nhw_rtc_set_counter(rtc, this->counter_at_stop); in nhw_rtc_TASKS_START()
509 static void nhw_rtc_TASKS_STOP(uint rtc) { in nhw_rtc_TASKS_STOP() argument
510 struct rtc_status *this = &nhw_rtc_st[rtc]; in nhw_rtc_TASKS_STOP()
515 bs_trace_raw_time(5, "RTC%i: TASK_STOP\n", rtc); in nhw_rtc_TASKS_STOP()
517 this->counter_at_stop = time_sub_us_to_counter(rtc, in nhw_rtc_TASKS_STOP()
521 NRF_RTC_regs[rtc].COUNTER = this->counter_at_stop; in nhw_rtc_TASKS_STOP()
532 static void nhw_rtc_TASKS_CLEAR(uint rtc) { in nhw_rtc_TASKS_CLEAR() argument
533 bs_trace_raw_time(5, "RTC%i: TASK_CLEAR\n", rtc); in nhw_rtc_TASKS_CLEAR()
536 nhw_rtc_st[rtc].PRESC = NRF_RTC_regs[rtc].PRESCALER; in nhw_rtc_TASKS_CLEAR()
537 nhw_rtc_st[rtc].counter_at_stop = 0; in nhw_rtc_TASKS_CLEAR()
538 nhw_rtc_set_counter(rtc, 0); in nhw_rtc_TASKS_CLEAR()
544 static void nhw_rtc_TASKS_TRIGOVRFLW(uint rtc) { in nhw_rtc_TASKS_TRIGOVRFLW() argument
546 bs_trace_raw_time(5, "RTC%i: TASK_TRIGGER_OVERFLOW\n", rtc); in nhw_rtc_TASKS_TRIGOVRFLW()
549 nhw_rtc_st[rtc].PRESC = NRF_RTC_regs[rtc].PRESCALER; in nhw_rtc_TASKS_TRIGOVRFLW()
550 nhw_rtc_st[rtc].counter_at_stop = RTC_TRIGGER_OVERFLOW_COUNTER_VALUE; in nhw_rtc_TASKS_TRIGOVRFLW()
551 nhw_rtc_set_counter(rtc, RTC_TRIGGER_OVERFLOW_COUNTER_VALUE); in nhw_rtc_TASKS_TRIGOVRFLW()
555 static void nhw_rtc_TASKS_CAPTURE(uint rtc, uint cc_n) { in nhw_rtc_TASKS_CAPTURE() argument
556 NRF_RTC_Type *RTC_regs = &NRF_RTC_regs[rtc]; in nhw_rtc_TASKS_CAPTURE()
558 nhw_rtc_update_COUNTER(rtc); in nhw_rtc_TASKS_CAPTURE()
561 nhw_rtc_regw_sideeffects_CC(rtc, cc_n); in nhw_rtc_TASKS_CAPTURE()
565 static void nhw_rtc_eval_interrupts(uint rtc) { in nhw_rtc_eval_interrupts() argument
570 struct rtc_status *this = &nhw_rtc_st[rtc]; in nhw_rtc_eval_interrupts()
575 if (NRF_RTC_regs[rtc].EVENTS_COMPARE[cc] && mask) { in nhw_rtc_eval_interrupts()
581 if (NRF_RTC_regs[rtc].EVENTS_TICK && (this->INTEN & RTC_INTENSET_TICK_Msk)) { in nhw_rtc_eval_interrupts()
584 if (NRF_RTC_regs[rtc].EVENTS_OVRFLW && (this->INTEN & RTC_INTENSET_OVRFLW_Msk)) { in nhw_rtc_eval_interrupts()
588 if (RTC_int_line[rtc] == false && new_int_line == true) { in nhw_rtc_eval_interrupts()
589 RTC_int_line[rtc] = true; in nhw_rtc_eval_interrupts()
590 hw_irq_ctrl_raise_level_irq_line(nhw_rtc_irq_map[rtc].cntl_inst, in nhw_rtc_eval_interrupts()
591 nhw_rtc_irq_map[rtc].int_nbr); in nhw_rtc_eval_interrupts()
592 } else if (RTC_int_line[rtc] == true && new_int_line == false) { in nhw_rtc_eval_interrupts()
593 RTC_int_line[rtc] = false; in nhw_rtc_eval_interrupts()
595 hw_irq_ctrl_lower_level_irq_line(nhw_rtc_irq_map[rtc].cntl_inst, in nhw_rtc_eval_interrupts()
596 nhw_rtc_irq_map[rtc].int_nbr); in nhw_rtc_eval_interrupts()
600 static void nhw_rtc_signal_COMPARE(uint rtc, uint cc) in nhw_rtc_signal_COMPARE() argument
602 struct rtc_status *this = &nhw_rtc_st[rtc]; in nhw_rtc_signal_COMPARE()
603 NRF_RTC_Type *RTC_regs = &NRF_RTC_regs[rtc]; in nhw_rtc_signal_COMPARE()
607 nhw_rtc_TASKS_CLEAR(rtc); in nhw_rtc_signal_COMPARE()
625 switch (rtc){ in nhw_rtc_signal_COMPARE()
644 nhw_rtc_eval_interrupts(rtc); in nhw_rtc_signal_COMPARE()
647 static void nhw_rtc_signal_OVERFLOW(uint rtc) in nhw_rtc_signal_OVERFLOW() argument
649 struct rtc_status *this = &nhw_rtc_st[rtc]; in nhw_rtc_signal_OVERFLOW()
650 NRF_RTC_Type *RTC_regs = &NRF_RTC_regs[rtc]; in nhw_rtc_signal_OVERFLOW()
661 switch (rtc){ in nhw_rtc_signal_OVERFLOW()
679 nhw_rtc_eval_interrupts(rtc); in nhw_rtc_signal_OVERFLOW()
683 /*static*/ void nhw_rtc_signal_TICK(uint rtc) /*Not yet used, as all TICK functionality is not yet … in nhw_rtc_signal_TICK() argument
685 struct rtc_status *this = &nhw_rtc_st[rtc]; in nhw_rtc_signal_TICK()
686 NRF_RTC_Type *RTC_regs = &NRF_RTC_regs[rtc]; in nhw_rtc_signal_TICK()
697 switch (rtc){ in nhw_rtc_signal_TICK()
715 nhw_rtc_eval_interrupts(rtc); in nhw_rtc_signal_TICK()
807 void nhw_rtc_regw_sideeffect_INTENSET(uint rtc) in NHW_RTC_REGW_SIDEFFECTS_SUBSCRIBE()
809 struct rtc_status *this = &nhw_rtc_st[rtc]; in NHW_RTC_REGW_SIDEFFECTS_SUBSCRIBE()
810 NRF_RTC_Type *RTC_regs = &NRF_RTC_regs[rtc]; in NHW_RTC_REGW_SIDEFFECTS_SUBSCRIBE()
817 nhw_rtc_eval_interrupts(rtc); in NHW_RTC_REGW_SIDEFFECTS_SUBSCRIBE()
821 void nhw_rtc_regw_sideeffect_INTENCLR(uint rtc) in nhw_rtc_regw_sideeffect_INTENCLR() argument
823 struct rtc_status *this = &nhw_rtc_st[rtc]; in nhw_rtc_regw_sideeffect_INTENCLR()
824 NRF_RTC_Type *RTC_regs = &NRF_RTC_regs[rtc]; in nhw_rtc_regw_sideeffect_INTENCLR()
831 nhw_rtc_eval_interrupts(rtc); in nhw_rtc_regw_sideeffect_INTENCLR()
855 void nhw_rtc_regw_sideeffects_EVENTS_all(uint rtc) { in nhw_rtc_regw_sideeffects_EVENTS_all() argument
856 nhw_rtc_eval_interrupts(rtc); in nhw_rtc_regw_sideeffects_EVENTS_all()
859 void nhw_rtc_regw_sideeffects_CC(uint rtc, uint cc_n) { in nhw_rtc_regw_sideeffects_CC() argument
860 struct rtc_status *this = &nhw_rtc_st[rtc]; in nhw_rtc_regw_sideeffects_CC()
863 update_cc_timer(rtc, cc_n); in nhw_rtc_regw_sideeffects_CC()
883 int64_t nhw_rtc_start_time_get(uint rtc) { in nhw_rtc_start_time_get() argument
884 struct rtc_status *this = &nhw_rtc_st[rtc]; in nhw_rtc_start_time_get()