Exemplo n.º 1
0
/*
 * API to initialize the CLOCK_XMC1 APP Interrupts
 */
CLOCK_XMC1_STATUS_t CLOCK_XMC1_Init(CLOCK_XMC1_t *handle)
{
  CLOCK_XMC1_STATUS_t status = CLOCK_XMC1_STATUS_SUCCESS;
  CLOCK_XMC1_STATUS_t loci_event_status = CLOCK_XMC1_STATUS_SUCCESS;
  CLOCK_XMC1_STATUS_t stdbyclkfail_status = CLOCK_XMC1_STATUS_SUCCESS;
  CLOCK_XMC1_STATUS_t loss_ext_clock_event_status = CLOCK_XMC1_STATUS_SUCCESS;
  CLOCK_XMC1_STATUS_t dco1_out_sync_status = CLOCK_XMC1_STATUS_SUCCESS;
  if (handle->init_status == false)
  {
#ifdef CLOCK_XMC1_INTERRUPT_ENABLED

    status = (CLOCK_XMC1_STATUS_t)GLOBAL_SCU_XMC1_Init(handle->global_scu_handleptr);
    if (CLOCK_XMC1_STATUS_SUCCESS == status)
    {
#ifdef CLOCK_XMC1_LOCI_EVENT_ENABLED
      /* Initialization of CPU_CTRL_XMC1 APP */
      loci_event_status = (CLOCK_XMC1_STATUS_t)GLOBAL_SCU_XMC1_RegisterCallback(
                           GLOBAL_SCU_XMC1_EVENT_LOCI, handle->callback_function_loci);
      /* Enable Loss of DCO1 Clock Event */
      XMC_SCU_INTERRUPT_EnableEvent(GLOBAL_SCU_XMC1_EVENT_LOCI);
#endif
#ifdef CLOCK_XMC1_STDBYCLKFAIL_EVENT_ENABLED
      /* Initialization of CPU_CTRL_XMC1 APP */
      stdbyclkfail_status = (CLOCK_XMC1_STATUS_t)GLOBAL_SCU_XMC1_RegisterCallback(
                             GLOBAL_SCU_XMC1_EVENT_STDBYCLKFAIL, handle->callback_function_stdbyclkfail);
      /* Enable Standby Clock Failure Event */
      XMC_SCU_INTERRUPT_EnableEvent(GLOBAL_SCU_XMC1_EVENT_STDBYCLKFAIL);
#endif

#if (UC_SERIES == XMC14)

#ifdef CLOCK_XMC1_LOSS_EXT_CLOCK_EVENT_ENABLED
      /* Initialization of CPU_CTRL_XMC1 APP */
      loss_ext_clock_event_status = (CLOCK_XMC1_STATUS_t)GLOBAL_SCU_XMC1_RegisterCallback(
                                     GLOBAL_SCU_XMC1_EVENT_LOSS_EXT_CLOCK, handle->callback_function_loss_ext_clock);
      /* Enable Loss of external OSC_HP clock Event */
      XMC_SCU_INTERRUPT_EnableEvent(GLOBAL_SCU_XMC1_EVENT_LOSS_EXT_CLOCK);
#endif
#ifdef CLOCK_XMC1_DCO1_OUT_SYNC_EVENT_ENABLED
      /* Initialization of CPU_CTRL_XMC1 APP */
      dco1_out_sync_status = (CLOCK_XMC1_STATUS_t)GLOBAL_SCU_XMC1_RegisterCallback(
                              GLOBAL_SCU_XMC1_EVENT_DCO1_OUT_SYNC, handle->callback_function_dco1_out_sync);
      /* Enable  DCO1 Out of SYNC Event */
      XMC_SCU_INTERRUPT_EnableEvent(GLOBAL_SCU_XMC1_EVENT_DCO1_OUT_SYNC);
#endif

#endif
    }

#endif
    status = (CLOCK_XMC1_STATUS_t)(((uint32_t)loci_event_status) | ((uint32_t)stdbyclkfail_status) |
    		                       ((uint32_t)loss_ext_clock_event_status) | ((uint32_t)dco1_out_sync_status));
    if (CLOCK_XMC1_STATUS_SUCCESS == status)
    {
      handle->init_status = true;
    }
  }
  return (status);
}
Exemplo n.º 2
0
Arquivo: rtc.c Projeto: Lasitha78/elua
/*
 *  This function configures periodic and alarm interrupts
 */
bool RTC_lConfigureInterrupts(const RTC_t *const handler)
{
  uint32_t regval;
  bool interrupt_configured = false;

  /* Enable periodic seconds, minutes, hours days, months and years interrupts */
  regval = (((uint32_t)handler->config->periodic_sec_intr << RTC_MSKSR_MPSE_Pos)
           | ((uint32_t)handler->config->periodic_min_intr << RTC_MSKSR_MPMI_Pos)
           | ((uint32_t)handler->config->periodic_hour_intr << RTC_MSKSR_MPHO_Pos)
           | ((uint32_t)handler->config->periodic_day_intr << RTC_MSKSR_MPDA_Pos)
           | ((uint32_t)handler->config->periodic_month_intr << RTC_MSKSR_MPMO_Pos)
           | ((uint32_t)handler->config->periodic_year_intr << RTC_MSKSR_MPYE_Pos));

  /* Enable RTC periodic interrupt in SCU when any of the periodic interrupts
   * are enabled */
  if (regval != 0U)
  {
    XMC_RTC_EnableEvent(regval);
#if ((UC_FAMILY == XMC4) && (RTC_TIMER_EVENT_TRIG_TO_NMI == 1))
		XMC_SCU_INTERRUPT_EnableEvent((XMC_SCU_INTERRUPT_EVENT_t)XMC_SCU_NMIREQ_RTC_PI);
		XMC_SCU_INTERRUPT_EnableNmiRequest((uint32_t)XMC_SCU_NMIREQ_RTC_PI);
#endif
#if ((UC_FAMILY == XMC4) && (RTC_TIMER_EVENT_TRIG_TO_SCU == 1))
		GLOBAL_SCU_XMC4_EnableEvent((GLOBAL_SCU_XMC4_EVENT_t)GLOBAL_SCU_XMC4_EVENT_RTC_PERIODIC);
#endif
    interrupt_configured = true;
  }


	if (handler->config->alarm_intr == RTC_INT_ALARM_ENABLE)
	{
		XMC_RTC_EnableEvent((uint32_t)XMC_RTC_EVENT_ALARM);
#if ((UC_FAMILY == XMC4) && (RTC_ALARM_EVENT_TRIG_TO_NMI == 1))
		XMC_SCU_INTERRUPT_EnableEvent((XMC_SCU_INTERRUPT_EVENT_t)XMC_SCU_NMIREQ_RTC_AI);
		XMC_SCU_INTERRUPT_EnableNmiRequest((uint32_t)XMC_SCU_NMIREQ_RTC_AI);
#endif
#if ((UC_FAMILY == XMC4) && (RTC_ALARM_EVENT_TRIG_TO_SCU == 1))
		GLOBAL_SCU_XMC4_EnableEvent((GLOBAL_SCU_XMC4_EVENT_t)GLOBAL_SCU_XMC4_EVENT_RTC_ALARM);
#endif

		interrupt_configured = true;
	}


  return (interrupt_configured);
}