/* Gets the time remaining until the first timer with the matching set of flags expires.  */
sl_status_t sl_sleeptimer_get_remaining_time_of_first_timer(uint16_t option_flags, uint32_t *time_remaining)
/* Gets the time remaining until the first timer with the matching set of flags expires.  */
sl_status_t sl_sleeptimer_get_remaining_time_of_first_timer(uint16_t option_flags, uint32_t *time_remaining)
{
  CORE_DECLARE_IRQ_STATE;
  sl_sleeptimer_timer_handle_t *current;
  uint32_t time = 0;
  CORE_ENTER_ATOMIC();
  current = timer_head;
  while (current != NULL) {
    time += current->delta;
    if (current->option_flags == option_flags) {
      if (time > (sleeptimer_hal_get_counter() - last_delta_update_count)) {
        time -= (sleeptimer_hal_get_counter() - last_delta_update_count);
      } else {
        time = 0;
      }
      *time_remaining = time;
      CORE_EXIT_ATOMIC();
      return SL_STATUS_OK;
    }
    current = current->next;
  }
  CORE_EXIT_ATOMIC();
  return SL_STATUS_EMPTY;
}