/**
 *  \brief I2C interface initialized using the XMC-Library
 *  
 *  \param [in] i2c_channel Constant pointer to the USIC communication channel
 *  \param [in] usic_sda_output USIC Data-PIN
 *  \param [in] usic_scl_output USIC Clock-PIN
 *  \param [in] port_config Constant pointer to the GPIO-Port
 *  \param [in] pin_number_sda PIN-number of data-PIN
 *  \param [in] pin_number_scl PIN-number of clock-PIN
 *  \param [in] gpio_config_sda Constant pointer to GPIO channel structure of the data-PIN
 *  \param [in] gpio_config_scl Constant pointer to GPIO channel structure of the clock-PIN
 *  \param [in] pin_config Constant pointer to I2C channel structure
 * 
 *  
 *  \details Initializes the I2C channel
 *  \details Pin-Configuration is being done
 *  \details NO FIFO-Buffer is included!
 */
void setupI2CInterface(XMC_USIC_CH_t *const i2c_channel,const uint8_t usic_sda_output,const uint8_t usic_scl_output, XMC_GPIO_PORT_t *const port_config,const uint8_t pin_number_sda,const uint8_t pin_number_scl,
		const XMC_GPIO_CONFIG_t *const gpio_config_sda,const XMC_GPIO_CONFIG_t *const gpio_config_scl,const XMC_I2C_CH_CONFIG_t *const pin_config)
{
	XMC_I2C_CH_Init(i2c_channel,pin_config);
	XMC_I2C_CH_SetInputSource(i2c_channel, XMC_I2C_CH_INPUT_SDA, usic_sda_output);
	XMC_I2C_CH_SetInputSource(i2c_channel, XMC_I2C_CH_INPUT_SCL, usic_scl_output);
	XMC_I2C_CH_Start(i2c_channel);
	//Pin-Configuration
	XMC_GPIO_Init(port_config, (uint8_t)pin_number_sda, gpio_config_sda);
	XMC_GPIO_Init(port_config, (uint8_t)pin_number_scl, gpio_config_scl);
}
/*
 * @brief Changes the baudrate of UART channel.
 *
 * @param UART_t * Pointer to the UART APP handle.
 * @param baud Value of new baudrate.
 * @param oversampling Number of samples to be considered for each symbol. 16 is the standard value.
 *
 * @return UART_STATUS_t UART_STATUS_SUCCESS if baudrate changed successfully.
 *                       UART_STATUS_BUSY if the UART channel is busy.
 *
 * \par<b>Description:</b><br>
 * The function stops the channel, calculates the clock divider values to achieve the desired baudrate.
 * Sets the divider values and reconfigures the channel as per the configuration in the UI. The channel is
 * enabled at the end of configuration.
 */
UART_STATUS_t UART_SetBaudrate(const UART_t * handle, uint32_t baud, uint32_t oversampling)
{
  UART_STATUS_t ret_stat = UART_STATUS_BUSY;
  const UART_TX_CONFIG_t * ptr_tx_conf = handle->config->tx_pin_config;

  XMC_ASSERT("UART_SetBaudrate: UART APP handle invalid", ((handle != NULL)&&
            ((handle->config != NULL) && (handle->runtime != NULL))))

  if ((handle->runtime->tx_busy == false) && (handle->runtime->rx_busy == false))
  {
    /* Set UART TX pin as input pin to avoid spikes on the pin.*/
    if (handle->config->mode != UART_MODE_LOOPBACK)
    {
      XMC_GPIO_SetMode(ptr_tx_conf->port, ptr_tx_conf->pin, XMC_GPIO_MODE_INPUT_TRISTATE);
    }
    /* Stop the UART channel before changing the baudrate.*/
    if (XMC_UART_CH_Stop(handle->channel) == XMC_UART_CH_STATUS_OK)
    {
      /*Change the baudrate*/
      ret_stat = (UART_STATUS_t)XMC_UART_CH_SetBaudrate(handle->channel, baud, oversampling);
      /*Set the sample point if the baudrate is modified*/
      if (ret_stat == UART_STATUS_SUCCESS)
      {
        XMC_UART_CH_SetSamplePoint(handle->channel, (uint32_t)(oversampling >> 1U)+1U);
      }
      /*Enable UART*/
      XMC_UART_CH_Start(handle->channel);
      /* Initialize UART TX pin */
      if (handle->config->mode != UART_MODE_LOOPBACK)
      {
        XMC_GPIO_Init(ptr_tx_conf->port, ptr_tx_conf->pin, ptr_tx_conf->config);
      }
    }
Esempio n. 3
0
/*
 * API to initialize the PIN_INTERRUPT APP ERU Event Trigger Logic, Output Gating Unit Hardware initialization
 * and NVIC node configuration.
 */
PIN_INTERRUPT_STATUS_t PIN_INTERRUPT_Init(const PIN_INTERRUPT_t *const handle)
{
  XMC_ASSERT("PIN_INTERRUPT_Init: PIN_INTERRUPT APP handle function pointer uninitialized", (handle != NULL));

  /* Initializes input pin characteristics */
  XMC_GPIO_Init(handle->port, handle->pin, &handle->gpio_config);
  /* ERU Event Trigger Logic Hardware initialization based on UI */
  XMC_ERU_ETL_Init(handle->eru, handle->etl, &handle->etl_config);
  /* OGU is configured to generate event on configured trigger edge */
  XMC_ERU_OGU_SetServiceRequestMode(handle->eru, handle->ogu, XMC_ERU_OGU_SERVICE_REQUEST_ON_TRIGGER);
#if (UC_FAMILY == XMC1)
  /* Configure NVIC node and priority */
  NVIC_SetPriority((IRQn_Type)handle->IRQn, handle->irq_priority);
#else
  /* Configure NVIC node, priority and subpriority */
  NVIC_SetPriority((IRQn_Type)handle->IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),
                    handle->irq_priority, handle->irq_subpriority));
#endif
#if (UC_SERIES == XMC14)
  XMC_SCU_SetInterruptControl((IRQn_Type)handle->IRQn, (XMC_SCU_IRQCTRL_t)handle->irqctrl);
#endif
  if (true == handle->enable_at_init)
  {
    /* Clear pending interrupt before enabling it */
    NVIC_ClearPendingIRQ((IRQn_Type)handle->IRQn);
    /* Enable NVIC node */
    NVIC_EnableIRQ((IRQn_Type)handle->IRQn);
  }
  return (PIN_INTERRUPT_STATUS_SUCCESS);
}
Esempio n. 4
0
/*Channel initialization function*/
UART_STATUS_t UART_0_init()
{
  UART_STATUS_t status = UART_STATUS_SUCCESS;
  status = (UART_STATUS_t)GLOBAL_DMA_Init(&GLOBAL_DMA_0);
  XMC_DMA_CH_Init(XMC_DMA0, 5U, &UART_0_tx_dma_ch_config);
  XMC_DMA_CH_EnableEvent(XMC_DMA0,  5U, XMC_DMA_CH_EVENT_TRANSFER_COMPLETE);

  XMC_DMA_CH_Init(XMC_DMA0, 4U, &UART_0_rx_dma_ch_config);
  XMC_DMA_CH_EnableEvent(XMC_DMA0,  4U, XMC_DMA_CH_EVENT_TRANSFER_COMPLETE);

  /*Configure Receive pin*/
  XMC_GPIO_Init((XMC_GPIO_PORT_t *)RX_PIN_PORT_BASE, 4U, &UART_0_rx_pin_config);
  /* Initialize USIC channel in UART mode*/
  XMC_UART_CH_Init(SELECTED_UART_CHANNEL, &UART_0_channel_config);
  /*Set input source path*/
  XMC_USIC_CH_SetInputSource(SELECTED_UART_CHANNEL, XMC_USIC_CH_INPUT_DX0, SOURCE_INPUT_SELECT);
  /* Start UART */
  XMC_UART_CH_Start(SELECTED_UART_CHANNEL);

  /* Initialize UART TX pin */
  XMC_GPIO_Init((XMC_GPIO_PORT_t *)TX_PIN_PORT_BASE, 5U, &UART_0_tx_pin_config);

  /*Set service request for transmit interrupt*/
  XMC_USIC_CH_SetInterruptNodePointer(SELECTED_UART_CHANNEL, XMC_USIC_CH_INTERRUPT_NODE_POINTER_TRANSMIT_BUFFER,
     0U);
  /*Set service request for receive interrupt*/
  XMC_USIC_CH_SetInterruptNodePointer(SELECTED_UART_CHANNEL, XMC_USIC_CH_INTERRUPT_NODE_POINTER_RECEIVE,
     1U);
  XMC_USIC_CH_SetInterruptNodePointer(SELECTED_UART_CHANNEL, XMC_USIC_CH_INTERRUPT_NODE_POINTER_ALTERNATE_RECEIVE,
     1U);
  /*Set service request for UART protocol events*/
  XMC_USIC_CH_SetInterruptNodePointer(SELECTED_UART_CHANNEL, XMC_USIC_CH_INTERRUPT_NODE_POINTER_PROTOCOL,
     2U);
  /*Register transfer complete event handler*/
  XMC_DMA_CH_SetEventHandler(XMC_DMA0, 4U, UART_0_dma_rx_handler);
  /*Register transfer complete event handler*/
  XMC_DMA_CH_SetEventHandler(XMC_DMA0, 5U, UART_0_dma_tx_handler);
  /* make DMA ready for transmission*/
  XMC_USIC_CH_TriggerServiceRequest(SELECTED_UART_CHANNEL, 0U);
  return status;
}
Esempio n. 5
0
DIGITAL_IO_STATUS_t DIGITAL_IO_Init(const DIGITAL_IO_t *const handler)
{
  XMC_ASSERT("DIGITAL_IO_Init: handler null pointer", handler != NULL);

  /* Initializes input / output characteristics */
  XMC_GPIO_Init(handler->gpio_port, handler->gpio_pin, &handler->gpio_config);

  /*Configure hardware port control*/
  XMC_GPIO_SetHardwareControl(handler->gpio_port, handler->gpio_pin, handler->hwctrl);

  return (DIGITAL_IO_STATUS_OK);
}
Esempio n. 6
0
/*Channel initialization function*/
UART_STATUS_t TempUart_init()
{
  UART_STATUS_t status = UART_STATUS_SUCCESS;
  /*Configure Receive pin*/
  XMC_GPIO_Init((XMC_GPIO_PORT_t *)PORT5_BASE, 0U, &TempUart_rx_pin_config);
  /* Initialize USIC channel in UART mode*/
  XMC_UART_CH_Init(XMC_UART0_CH0, &TempUart_channel_config);
  /*Set input source path*/
  XMC_USIC_CH_SetInputSource(XMC_UART0_CH0, XMC_USIC_CH_INPUT_DX0, 3U);
  /* Start UART */
  XMC_UART_CH_Start(XMC_UART0_CH0);

  /* Initialize UART TX pin */
  XMC_GPIO_Init((XMC_GPIO_PORT_t *)PORT5_BASE, 1U, &TempUart_tx_pin_config);

  /*Set service request for transmit interrupt*/
  XMC_USIC_CH_SetInterruptNodePointer(XMC_UART0_CH0, XMC_USIC_CH_INTERRUPT_NODE_POINTER_TRANSMIT_BUFFER,
     3U);
  /*Set service request for receive interrupt*/
  XMC_USIC_CH_SetInterruptNodePointer(XMC_UART0_CH0, XMC_USIC_CH_INTERRUPT_NODE_POINTER_RECEIVE,
     5U);
  XMC_USIC_CH_SetInterruptNodePointer(XMC_UART0_CH0, XMC_USIC_CH_INTERRUPT_NODE_POINTER_ALTERNATE_RECEIVE,
     5U);
  /*Set service request for UART protocol events*/
  XMC_USIC_CH_SetInterruptNodePointer(XMC_UART0_CH0, XMC_USIC_CH_INTERRUPT_NODE_POINTER_PROTOCOL,
     0U);
  /*Set priority and enable NVIC node for transmit interrupt*/
  NVIC_SetPriority((IRQn_Type)87, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),
                        18U, 0U));
  NVIC_EnableIRQ((IRQn_Type)87);
  /*Set priority and enable NVIC node for receive interrupt*/
  NVIC_SetPriority((IRQn_Type)89, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),
                      18U, 0U));
  NVIC_EnableIRQ((IRQn_Type)89);
  return status;
}
Esempio n. 7
0
/* API initializes the Segger library */
GUI_SEGGERLIBRARY_STATUS_t GUI_SEGGERLIBRARY_Init(GUI_SEGGERLIBRARY_t *handle)
{
  GUI_SEGGERLIBRARY_STATUS_t status;

  status = GUI_SEGGERLIBRARY_STATUS_SUCCESS;

#if (GUI_SEGGERLIBRARY_RTOS_PRESENT == 0)
  status = (GUI_SEGGERLIBRARY_STATUS_t)SYSTIMER_Init(handle->systimer_handler);
#endif

#if (CMSIS_RTOS_RTX_PRESENT == 1)
  status = (GUI_SEGGERLIBRARY_STATUS_t)CMSIS_RTOS_RTX_Init(&CMSIS_RTOS_RTX_0);
#endif

  if (status == GUI_SEGGERLIBRARY_STATUS_SUCCESS)
  {
    /* Initialize SPI as well as the port and pin for GPIO */
    #if (SPI_INTERFACE == 1)
      status = (GUI_SEGGERLIBRARY_STATUS_t)SPI_MASTER_Init(handle->spi_master_handler);

      #if !USER_DEFINED_LCD
		if (status == GUI_SEGGERLIBRARY_STATUS_SUCCESS)
		{
		  XMC_GPIO_Init(handle->config->portNo, handle->config->pinNo, handle->config->gpio);

		  status = GUI_SEGGERLIBRARY_STATUS_SUCCESS;
		}
		else
		{
		  status = GUI_SEGGERLIBRARY_STATUS_FAILURE;
		}
      #endif
    #endif

    if (handle->enable_at_init == true)
    {
      GUI_Init();
    }
  }
  else
  {
    status = GUI_SEGGERLIBRARY_STATUS_FAILURE;
  }

  return (status);
}
Esempio n. 8
0
/* This function initializes the app */
PWM_CCU4_STATUS_t PWM_CCU4_Init(PWM_CCU4_t* handle_ptr)
{
  PWM_CCU4_STATUS_t status;
  GLOBAL_CCU4_STATUS_t status_ccu4_global;
  uint32_t frequency_module;
  uint32_t prescalar;

  status = PWM_CCU4_STATUS_FAILURE;
  status_ccu4_global = GLOBAL_CCU4_STATUS_FAILURE;
  XMC_ASSERT("PWM_CCU4_Init:handle_ptr is NULL", (handle_ptr != NULL));

  if (PWM_CCU4_STATE_UNINITIALIZED == handle_ptr->state)
  {
    /* Initialize consumed Apps */
    status_ccu4_global = GLOBAL_CCU4_Init(handle_ptr->config_ptr->global_ccu4_handle);

    /* Initialize CCU4x_CC4y slice */
    if (GLOBAL_CCU4_STATUS_SUCCESS == status_ccu4_global)
    {
      XMC_DEBUG("PWM_CCU4_Init:Initilizing slice");

      /* Configure CCU4x_CC4y slice as timer */
      XMC_CCU4_SLICE_CompareInit(handle_ptr->ccu4_slice_ptr, handle_ptr->config_ptr->ccu4_cc4_slice_timer_ptr);
      /* Set period match value of the timer  */
      XMC_CCU4_SLICE_SetTimerPeriodMatch(handle_ptr->ccu4_slice_ptr, handle_ptr->config_ptr->period_value);

      /* Set timer compare match value for channel 1 */
      XMC_CCU4_SLICE_SetTimerCompareMatch(handle_ptr->ccu4_slice_ptr, (uint16_t) handle_ptr->config_ptr->compare_value);

      if (1U == handle_ptr->config_ptr->ccu4_cc4_slice_timer_ptr->mcm_enable)
      {
        XMC_CCU4_SetMultiChannelShadowTransferMode(handle_ptr->ccu4_module_ptr,
                                                   (uint32_t) handle_ptr->config_ptr->mcm_shadow_txfr_mode);
      }

#if (UC_SERIES == XMC14) /*below feature available in XMC14xx devices */
      XMC_CCU4_SLICE_SetShadowTransferMode(handle_ptr->ccu4_slice_ptr, handle_ptr->config_ptr->shadow_transfer_mode);
      XMC_CCU4_SLICE_WriteImmediateAfterShadowTransfer(handle_ptr->ccu4_slice_ptr,
                                                       handle_ptr->config_ptr->immediate_write);
      XMC_CCU4_SLICE_EnableAutomaticShadowTransferRequest(handle_ptr->ccu4_slice_ptr,
                                                          handle_ptr->config_ptr->automatic_shadow_transfer);
      if((bool)true == handle_ptr->config_ptr->cascaded_shadow_txfr_enable)
      {
        XMC_CCU4_SLICE_EnableCascadedShadowTransfer(handle_ptr->ccu4_slice_ptr);
      }
#endif

      /* Transfer value from shadow timer registers to actual timer registers */
      XMC_CCU4_EnableShadowTransfer(handle_ptr->ccu4_module_ptr, handle_ptr->shadow_txfr_msk);
      XMC_CCU4_EnableShadowTransfer(handle_ptr->ccu4_module_ptr, handle_ptr->dither_shadow_txfr_msk);

      /* Configure events */
      PWM_CCU4_lConfigure_Events(handle_ptr);

      /* Enable the interrupts */
      PWM_CCU4_lInit_Interrupt(handle_ptr);

      /*Initializes the GPIO*/
      if ((bool) true == handle_ptr->config_ptr->gpio_ch_out_enable)
      {
        XMC_GPIO_Init(handle_ptr->config_ptr->gpio_ch_out_ptr, handle_ptr->config_ptr->gpio_ch_out_pin,
                      handle_ptr->config_ptr->gpio_ch_out_config_ptr);
      }

      frequency_module = handle_ptr->config_ptr->global_ccu4_handle->module_frequency;
      prescalar = (uint32_t) handle_ptr->config_ptr->ccu4_cc4_slice_timer_ptr->prescaler_initval;
      frequency_module = frequency_module / ((uint32_t) 1 << prescalar);
      handle_ptr->frequency_tclk = frequency_module;

      handle_ptr->state = PWM_CCU4_STATE_INITIALIZED;
      status = PWM_CCU4_STATUS_SUCCESS;

      /* Start the PWM generation if start at initialization is enabled */
      if ((bool) true == handle_ptr->config_ptr->start_control)
      {
        status = PWM_CCU4_Start(handle_ptr);
      }
    }
    else
    {
      handle_ptr->state = PWM_CCU4_STATE_UNINITIALIZED;
    }

  }
  else
  {
    status = PWM_CCU4_STATUS_ALREADY_INITIALIZED;
    XMC_DEBUG("PWM_CCU4_Init:PWM_CCU4_STATUS_ALREADY_INITIALIZED");
  }

  return (status);
} /* end of PWM_CCU4_Init() api */