nicolas71640 commented on code in PR #12425:
URL: https://github.com/apache/nuttx/pull/12425#discussion_r1620123162


##########
arch/arm/src/xmc4/xmc4_vadc.c:
##########
@@ -0,0 +1,576 @@
+/****************************************************************************
+ * arch/arm/src/xmc4/xmc4_vadc.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ * May include some logic from sample code provided by Infineon:
+ *
+ * Copyright (C) 2011-2015 Infineon Technologies AG. All rights reserved.
+ *
+ * Infineon Technologies AG (Infineon) is supplying this software for use
+ * with Infineon's microcontrollers.  This file can be freely distributed
+ * within development tools that are supporting such microcontrollers.
+ *
+ * THIS SOFTWARE IS PROVIDED AS IS. NO WARRANTIES, WHETHER EXPRESS,
+ * IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS
+ * SOFTWARE. INFINEON SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR
+ * SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <errno.h>
+#include <assert.h>
+
+#include <arch/xmc4/chip.h>
+
+#include "arm_internal.h"
+#include "hardware/xmc4_scu.h"
+#include "xmc4_vadc.h"
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static vadc_group_t *const g_xmc_vadc_group_array[XMC_VADC_MAXIMUM_NUM_GROUPS] 
= {
+                                                                               
   (vadc_group_t *)VADC_G0,
+                                                                               
   (vadc_group_t *)VADC_G1,
+                                                                               
   (vadc_group_t *)VADC_G2,
+                                                                               
   (vadc_group_t *)VADC_G3
+                                                                               
   };
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: xmc4_vadc_global_enable
+ *
+ * Description:
+ *   Ungate the clock to the VADC module (if applicable) and bring the VADC
+ *   module out of reset state.
+ *   Called in xmc4_vadc_global_initialize.
+ *
+ ****************************************************************************/
+
+void xmc4_vadc_global_enable(void)
+{
+  #ifdef XMC4_SCU_GATING
+  /* Check if VADC is gated */
+
+  if ((getreg32(XMC4_SCU_CGATSTAT0) & SCU_CGAT0_VADC) == 1)
+    {
+      /* Disable VADC gating */
+
+      putreg32(SCU_CGAT0_VADC, XMC4_SCU_CGATCLR0);
+    }
+
+  /* Set bit in PRCLR0 to de-assert VADC peripheral reset */
+
+  putreg32(SCU_PR0_VADCRS, XMC4_SCU_PRCLR0);
+  #else
+
+  /* Set bit in PRCLR0 to de-assert VADC peripheral reset */
+
+  putreg32(SCU_PR0_VADCRS, XMC4_SCU_PRCLR0);
+  #endif
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_global_disable
+ *
+ * Description:
+ *   Gate the clock to the VADC module (if applicable) and put the VADC
+ *   module into the reset state
+ *
+ ****************************************************************************/
+
+void xmc4_vadc_global_disable(void)
+{
+  /* Set bit in PRSET0 to assert VADC peripheral reset */
+
+  putreg32(SCU_PR0_VADCRS, XMC4_SCU_PRSET0);
+
+  #ifdef XMC4_SCU_GATING
+  /* Check if VADC is ungated */
+
+  if ((getreg32(XMC4_SCU_CGATSTAT0) & SCU_CGAT0_VADC) == 0)
+    {
+      /* Enable VADC gating */
+
+      putreg32(SCU_CGAT0_VADC, XMC4_SCU_CGATSET0);
+    }
+  #endif
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_global_initialize
+ *
+ * Description:
+ *   Initializes the VADC global module with the given configuration structure.
+ *   It initializes global input classes, boundaries , result resources.
+ *   Configures GLOBICLASS,GLOBBOUND,GLOBRCR registers.
+ *   It also configures the global analog and digital clock dividers
+ *   by setting GLOBCFG register.
+ *
+ ****************************************************************************/
+
+void xmc4_vadc_global_initialize(const vadc_global_config_t *config)
+{
+  /* Enable the VADC module */
+
+  xmc4_vadc_global_enable();
+
+  VADC->CLC = (uint32_t)(config->clc);
+
+  /* Clock configuration, use DIVWC (write control) to write register */
+
+  VADC->GLOBCFG = (uint32_t)(config->globcfg | 
(uint32_t)(VADC_GLOBCFG_DIVWC_MASK));
+
+  /* Global input class 0 configuration */
+
+  VADC->GLOBICLASS[0] = (uint32_t)(config->class0.iclass);
+
+  /* Global input class 1 configuration */
+
+  VADC->GLOBICLASS[1] = (uint32_t)(config->class1.iclass);
+
+  /* Global result generation configuration */
+
+  VADC->GLOBRCR = (uint32_t)(config->globrcr);
+
+  /* Set global boundaries values */
+
+  VADC->GLOBBOUND = (uint32_t)(config->globbound);
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_group_initialize
+ *
+ * Description:
+ *   Initializes the VADC group module with the associated
+ *   configuration structure pointed by config. It initializes group conversion
+ *   class, arbiter configuration, boundary configuration by setting
+ *   GxICLASS,GxARBCFG,GxBOUND, registers.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; A negated errno value is returned to
+ *   indicate the nature of any failure.
+ *
+ ****************************************************************************/
+
+int xmc4_vadc_group_initialize(vadc_group_t *const group_ptr, const 
vadc_group_config_t *config)
+{
+  if (!xmc_vadc_check_group_ptr(group_ptr))
+    {
+      return -EINVAL;
+    }
+
+  /* Configures the group-specific input classes,
+   * each channel is assigned to a class in GxCHCTRy
+   */
+
+  group_ptr->ICLASS[0] = config->class0.iclass;
+  group_ptr->ICLASS[1] = config->class1.iclass;
+
+  /* Configures the group arbitration behavior */
+
+  group_ptr->ARBCFG = config->g_arbcfg;
+
+  /* Configures the group-specific boundaries */
+
+  group_ptr->BOUND = config->g_bound;
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_group_set_powermode
+ *
+ * Description:
+ *   Configures the power mode of a VADC group. For a VADC group to
+ *   actually convert an analog signal, its analog converter must be turned on.
+ *   Configure the register bit field GxARBCFG.ANONC
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; A negated errno value is returned to
+ *   indicate the nature of any failure.
+ *
+ ****************************************************************************/
+
+int xmc4_vadc_group_set_powermode(vadc_group_t *const group_ptr, const 
vadc_group_powermode_t power_mode)
+{
+  if (!xmc_vadc_check_group_ptr(group_ptr) || (power_mode > 
XMC_VADC_GROUP_POWERMODE_NORMAL))
+    {
+      return -EINVAL;
+    }
+
+  uint32_t arbcfg = group_ptr->ARBCFG;
+
+  arbcfg &= ~((uint32_t)VADC_GxARBCFG_ANONC_MASK);
+  arbcfg |= (uint32_t)power_mode;
+
+  group_ptr->ARBCFG = arbcfg;
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_global_start_calibration
+ *
+ * Description:
+ *   Start the calibration process and loops until all active groups
+ *   finish calibration. Call xmc4_vadc_global_enable and
+ *   xmc4_vadc_global_initialize before calibration.
+ *   Configures the register bit field GLOBCFG.SUCAL.
+ *
+ ****************************************************************************/
+
+void xmc4_vadc_global_start_calibration(void)
+{
+  vadc_group_t * group_ptr;
+
+  /* Start Calibration */
+
+  VADC->GLOBCFG |= (uint32_t) VADC_GLOBCFG_SUCAL_MASK;
+
+  /* Loop until all groups to finish calibration */
+
+  for (int i = 0; i < XMC_VADC_MAXIMUM_NUM_GROUPS; i++)
+    {
+      group_ptr = g_xmc_vadc_group_array[i];
+
+      /* Check if group is active */
+
+      if ((group_ptr->ARBCFG) & (uint32_t)(VADC_GxARBCFG_ANONS_MASK))
+        {
+          /* Loop until it finish calibration */
+
+          while ((group_ptr->ARBCFG) & (uint32_t)VADC_GxARBCFG_CAL_MASK)
+            {
+              /* NOP */
+            }
+      }
+    }
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_group_background_enable_arbitrationslot
+ *
+ * Description:
+ *   Enables arbitration slot of the Background request source to
+ *   participate in the arbitration round. Even if a load event occurs the
+ *   Background channel can only be converted when the arbiter comes to the
+ *   Background slot. Thus this must be enabled if any conversion need to take
+ *   place.
+ *   Configure the register bit field GxARBPR.ASEN2.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; A negated errno value is returned to
+ *   indicate the nature of any failure.
+ *
+ ****************************************************************************/
+
+int xmc4_vadc_group_background_enable_arbitrationslot(vadc_group_t *const 
group_ptr)
+{
+  if (!xmc_vadc_check_group_ptr(group_ptr))
+    {
+      return -EINVAL;
+    }
+
+  group_ptr->ARBPR |= (uint32_t)VADC_GxARBPR_ASEN2_MASK;
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_group_background_disable_arbitrationslot
+ *
+ * Description:
+ *   Disables arbitration slot of the Background request source to
+ *   participate in the arbitration round. Even if a load event occurs the
+ *   Background channel can only be converted when the arbiter comes to the
+ *   Background slot. Thus this must be enabled if any conversion need to take
+ *   place.
+ *   Configure the register bit field GxARBPR.ASEN2.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; A negated errno value is returned to
+ *   indicate the nature of any failure.
+ *
+ ****************************************************************************/
+
+int xmc4_vadc_group_background_disable_arbitrationslot(vadc_group_t *const 
group_ptr)
+{
+  if (!xmc_vadc_check_group_ptr(group_ptr))
+    {
+      return -EINVAL;
+    }
+
+  group_ptr->ARBPR &= ~((uint32_t)VADC_GxARBPR_ASEN2_MASK);
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_global_background_initialize
+ *
+ * Description:
+ *   Initializes the Background scan functional block. The BACKGROUND
+ *   SCAN request source functional block converts channels of all VADC groups
+ *   that have not been assigned as a priority channel (priority channels can 
be
+ *   converted only by queue and scan). Related arbitration slot must be
+ *   disabled to configure background request, then re-enabled.
+ *
+ ****************************************************************************/
+
+void xmc4_vadc_global_background_initialize(const vadc_background_config_t 
*config)
+{
+  uint32_t reg;
+  uint32_t conv_start_mask;
+
+  /* Disable background request source to change its parameters */
+
+  for (int i = 0; i < XMC_VADC_MAXIMUM_NUM_GROUPS; i++)
+    {
+      xmc4_vadc_group_background_disable_arbitrationslot((vadc_group_t 
*)g_xmc_vadc_group_array[i]);
+    }
+
+  /* Set start mode */
+
+  conv_start_mask = (uint32_t) 0;
+  if (XMC_VADC_STARTMODE_WFS != (vadc_startmode_t)config->conv_start_mode)
+    {
+      conv_start_mask = (uint32_t)VADC_GxARBPR_CSM2_MASK;
+    }
+
+  /* Configures GxARBPR register for each group */
+
+  for (int i = 0; i < XMC_VADC_MAXIMUM_NUM_GROUPS; i++)
+    {
+      reg = g_xmc_vadc_group_array[i]->ARBPR;
+
+      /* Program the priority of the request source : Background Scan is 
source 2 */
+
+      reg &= ~(uint32_t)(VADC_GxARBPR_PRIO2_MASK);
+      reg |= (uint32_t)((uint32_t)config->req_src_priority << 
VADC_GxARBPR_PRIO2_SHIFT);
+
+      /* Program the start mode */
+
+      reg |= conv_start_mask;
+
+      g_xmc_vadc_group_array[i]->ARBPR = reg;
+    }
+
+  /* program Background Request Source Control register, use XT and GT write 
control bitfields */
+
+  VADC->BRSCTRL = (uint32_t)(config->asctrl | (uint32_t)VADC_BRSCTRL_XTWC_MASK 
| (uint32_t)VADC_BRSCTRL_GTWC_MASK);
+
+  /* program Background Request Source Mode register */
+
+  VADC->BRSMR = (uint32_t)((config->asmr) | 
(uint32_t)((uint32_t)XMC_VADC_GATEMODE_IGNORE << VADC_BRSMR_ENGT_SHIFT));
+  if (XMC_VADC_STARTMODE_CNR == (vadc_startmode_t)(config->conv_start_mode))
+    {
+      VADC->BRSMR |= (uint32_t)VADC_BRSMR_RPTDIS_MASK;
+    }
+
+  /* Re enable request source */
+
+  for (int i = 0; i < XMC_VADC_MAXIMUM_NUM_GROUPS; i++)
+    {
+      xmc4_vadc_group_background_enable_arbitrationslot((vadc_group_t 
*)g_xmc_vadc_group_array[i]);
+    }
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_group_channel_initialize
+ *
+ * Description:
+ *   Initializes the ADC channel for conversion. Must be called after
+ *   request source initialization for each channel to enable their conversion.
+ *   Configures registers GxCHCTRy and boundary flag GxBFL, GxBFLC and GxCHASS.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; A negated errno value is returned to

Review Comment:
   negated => negative



##########
arch/arm/src/xmc4/hardware/xmc4_memorymap.h:
##########
@@ -48,6 +48,7 @@
  ****************************************************************************/
 
 /* Reference: XMC4500 Reference Manual V1.5 2014-07 Microcontrollers. */
+/* This memory map is valid for both XMC45 and XMC4[78] architecture */

Review Comment:
   Squash your commit with a nice name :)



##########
arch/arm/src/xmc4/xmc4_vadc.c:
##########
@@ -0,0 +1,576 @@
+/****************************************************************************
+ * arch/arm/src/xmc4/xmc4_vadc.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ * May include some logic from sample code provided by Infineon:
+ *
+ * Copyright (C) 2011-2015 Infineon Technologies AG. All rights reserved.
+ *
+ * Infineon Technologies AG (Infineon) is supplying this software for use
+ * with Infineon's microcontrollers.  This file can be freely distributed
+ * within development tools that are supporting such microcontrollers.
+ *
+ * THIS SOFTWARE IS PROVIDED AS IS. NO WARRANTIES, WHETHER EXPRESS,
+ * IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS
+ * SOFTWARE. INFINEON SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR
+ * SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <errno.h>
+#include <assert.h>
+
+#include <arch/xmc4/chip.h>
+
+#include "arm_internal.h"
+#include "hardware/xmc4_scu.h"
+#include "xmc4_vadc.h"
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static vadc_group_t *const g_xmc_vadc_group_array[XMC_VADC_MAXIMUM_NUM_GROUPS] 
= {
+                                                                               
   (vadc_group_t *)VADC_G0,
+                                                                               
   (vadc_group_t *)VADC_G1,
+                                                                               
   (vadc_group_t *)VADC_G2,
+                                                                               
   (vadc_group_t *)VADC_G3
+                                                                               
   };
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: xmc4_vadc_global_enable
+ *
+ * Description:
+ *   Ungate the clock to the VADC module (if applicable) and bring the VADC
+ *   module out of reset state.
+ *   Called in xmc4_vadc_global_initialize.
+ *
+ ****************************************************************************/
+
+void xmc4_vadc_global_enable(void)
+{
+  #ifdef XMC4_SCU_GATING
+  /* Check if VADC is gated */
+
+  if ((getreg32(XMC4_SCU_CGATSTAT0) & SCU_CGAT0_VADC) == 1)
+    {
+      /* Disable VADC gating */
+
+      putreg32(SCU_CGAT0_VADC, XMC4_SCU_CGATCLR0);
+    }
+
+  /* Set bit in PRCLR0 to de-assert VADC peripheral reset */
+
+  putreg32(SCU_PR0_VADCRS, XMC4_SCU_PRCLR0);
+  #else
+
+  /* Set bit in PRCLR0 to de-assert VADC peripheral reset */
+
+  putreg32(SCU_PR0_VADCRS, XMC4_SCU_PRCLR0);
+  #endif
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_global_disable
+ *
+ * Description:
+ *   Gate the clock to the VADC module (if applicable) and put the VADC
+ *   module into the reset state
+ *
+ ****************************************************************************/
+
+void xmc4_vadc_global_disable(void)
+{
+  /* Set bit in PRSET0 to assert VADC peripheral reset */
+
+  putreg32(SCU_PR0_VADCRS, XMC4_SCU_PRSET0);
+
+  #ifdef XMC4_SCU_GATING
+  /* Check if VADC is ungated */
+
+  if ((getreg32(XMC4_SCU_CGATSTAT0) & SCU_CGAT0_VADC) == 0)
+    {
+      /* Enable VADC gating */
+
+      putreg32(SCU_CGAT0_VADC, XMC4_SCU_CGATSET0);
+    }
+  #endif
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_global_initialize
+ *
+ * Description:
+ *   Initializes the VADC global module with the given configuration structure.
+ *   It initializes global input classes, boundaries , result resources.
+ *   Configures GLOBICLASS,GLOBBOUND,GLOBRCR registers.
+ *   It also configures the global analog and digital clock dividers
+ *   by setting GLOBCFG register.
+ *
+ ****************************************************************************/
+
+void xmc4_vadc_global_initialize(const vadc_global_config_t *config)
+{
+  /* Enable the VADC module */
+
+  xmc4_vadc_global_enable();
+
+  VADC->CLC = (uint32_t)(config->clc);
+
+  /* Clock configuration, use DIVWC (write control) to write register */
+
+  VADC->GLOBCFG = (uint32_t)(config->globcfg | 
(uint32_t)(VADC_GLOBCFG_DIVWC_MASK));
+
+  /* Global input class 0 configuration */
+
+  VADC->GLOBICLASS[0] = (uint32_t)(config->class0.iclass);
+
+  /* Global input class 1 configuration */
+
+  VADC->GLOBICLASS[1] = (uint32_t)(config->class1.iclass);
+
+  /* Global result generation configuration */
+
+  VADC->GLOBRCR = (uint32_t)(config->globrcr);
+
+  /* Set global boundaries values */
+
+  VADC->GLOBBOUND = (uint32_t)(config->globbound);
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_group_initialize
+ *
+ * Description:
+ *   Initializes the VADC group module with the associated
+ *   configuration structure pointed by config. It initializes group conversion
+ *   class, arbiter configuration, boundary configuration by setting
+ *   GxICLASS,GxARBCFG,GxBOUND, registers.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; A negated errno value is returned to
+ *   indicate the nature of any failure.
+ *
+ ****************************************************************************/
+
+int xmc4_vadc_group_initialize(vadc_group_t *const group_ptr, const 
vadc_group_config_t *config)
+{
+  if (!xmc_vadc_check_group_ptr(group_ptr))
+    {
+      return -EINVAL;
+    }
+
+  /* Configures the group-specific input classes,
+   * each channel is assigned to a class in GxCHCTRy
+   */
+
+  group_ptr->ICLASS[0] = config->class0.iclass;
+  group_ptr->ICLASS[1] = config->class1.iclass;
+
+  /* Configures the group arbitration behavior */
+
+  group_ptr->ARBCFG = config->g_arbcfg;
+
+  /* Configures the group-specific boundaries */
+
+  group_ptr->BOUND = config->g_bound;
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_group_set_powermode
+ *
+ * Description:
+ *   Configures the power mode of a VADC group. For a VADC group to
+ *   actually convert an analog signal, its analog converter must be turned on.
+ *   Configure the register bit field GxARBCFG.ANONC
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; A negated errno value is returned to
+ *   indicate the nature of any failure.
+ *
+ ****************************************************************************/
+
+int xmc4_vadc_group_set_powermode(vadc_group_t *const group_ptr, const 
vadc_group_powermode_t power_mode)
+{
+  if (!xmc_vadc_check_group_ptr(group_ptr) || (power_mode > 
XMC_VADC_GROUP_POWERMODE_NORMAL))
+    {
+      return -EINVAL;
+    }
+
+  uint32_t arbcfg = group_ptr->ARBCFG;
+
+  arbcfg &= ~((uint32_t)VADC_GxARBCFG_ANONC_MASK);
+  arbcfg |= (uint32_t)power_mode;
+
+  group_ptr->ARBCFG = arbcfg;
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_global_start_calibration
+ *
+ * Description:
+ *   Start the calibration process and loops until all active groups
+ *   finish calibration. Call xmc4_vadc_global_enable and
+ *   xmc4_vadc_global_initialize before calibration.
+ *   Configures the register bit field GLOBCFG.SUCAL.
+ *
+ ****************************************************************************/
+
+void xmc4_vadc_global_start_calibration(void)
+{
+  vadc_group_t * group_ptr;
+
+  /* Start Calibration */
+
+  VADC->GLOBCFG |= (uint32_t) VADC_GLOBCFG_SUCAL_MASK;
+
+  /* Loop until all groups to finish calibration */
+
+  for (int i = 0; i < XMC_VADC_MAXIMUM_NUM_GROUPS; i++)
+    {
+      group_ptr = g_xmc_vadc_group_array[i];
+
+      /* Check if group is active */
+
+      if ((group_ptr->ARBCFG) & (uint32_t)(VADC_GxARBCFG_ANONS_MASK))
+        {
+          /* Loop until it finish calibration */
+
+          while ((group_ptr->ARBCFG) & (uint32_t)VADC_GxARBCFG_CAL_MASK)
+            {
+              /* NOP */
+            }
+      }
+    }
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_group_background_enable_arbitrationslot
+ *
+ * Description:
+ *   Enables arbitration slot of the Background request source to
+ *   participate in the arbitration round. Even if a load event occurs the
+ *   Background channel can only be converted when the arbiter comes to the
+ *   Background slot. Thus this must be enabled if any conversion need to take
+ *   place.
+ *   Configure the register bit field GxARBPR.ASEN2.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; A negated errno value is returned to
+ *   indicate the nature of any failure.
+ *
+ ****************************************************************************/
+
+int xmc4_vadc_group_background_enable_arbitrationslot(vadc_group_t *const 
group_ptr)
+{
+  if (!xmc_vadc_check_group_ptr(group_ptr))
+    {
+      return -EINVAL;
+    }
+
+  group_ptr->ARBPR |= (uint32_t)VADC_GxARBPR_ASEN2_MASK;
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_group_background_disable_arbitrationslot
+ *
+ * Description:
+ *   Disables arbitration slot of the Background request source to
+ *   participate in the arbitration round. Even if a load event occurs the
+ *   Background channel can only be converted when the arbiter comes to the
+ *   Background slot. Thus this must be enabled if any conversion need to take
+ *   place.
+ *   Configure the register bit field GxARBPR.ASEN2.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; A negated errno value is returned to
+ *   indicate the nature of any failure.
+ *
+ ****************************************************************************/
+
+int xmc4_vadc_group_background_disable_arbitrationslot(vadc_group_t *const 
group_ptr)
+{
+  if (!xmc_vadc_check_group_ptr(group_ptr))
+    {
+      return -EINVAL;
+    }
+
+  group_ptr->ARBPR &= ~((uint32_t)VADC_GxARBPR_ASEN2_MASK);
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_global_background_initialize
+ *
+ * Description:
+ *   Initializes the Background scan functional block. The BACKGROUND
+ *   SCAN request source functional block converts channels of all VADC groups
+ *   that have not been assigned as a priority channel (priority channels can 
be
+ *   converted only by queue and scan). Related arbitration slot must be
+ *   disabled to configure background request, then re-enabled.
+ *
+ ****************************************************************************/
+
+void xmc4_vadc_global_background_initialize(const vadc_background_config_t 
*config)
+{
+  uint32_t reg;
+  uint32_t conv_start_mask;
+
+  /* Disable background request source to change its parameters */
+
+  for (int i = 0; i < XMC_VADC_MAXIMUM_NUM_GROUPS; i++)
+    {
+      xmc4_vadc_group_background_disable_arbitrationslot((vadc_group_t 
*)g_xmc_vadc_group_array[i]);
+    }
+
+  /* Set start mode */
+
+  conv_start_mask = (uint32_t) 0;
+  if (XMC_VADC_STARTMODE_WFS != (vadc_startmode_t)config->conv_start_mode)
+    {
+      conv_start_mask = (uint32_t)VADC_GxARBPR_CSM2_MASK;
+    }
+
+  /* Configures GxARBPR register for each group */
+
+  for (int i = 0; i < XMC_VADC_MAXIMUM_NUM_GROUPS; i++)
+    {
+      reg = g_xmc_vadc_group_array[i]->ARBPR;
+
+      /* Program the priority of the request source : Background Scan is 
source 2 */
+
+      reg &= ~(uint32_t)(VADC_GxARBPR_PRIO2_MASK);
+      reg |= (uint32_t)((uint32_t)config->req_src_priority << 
VADC_GxARBPR_PRIO2_SHIFT);
+
+      /* Program the start mode */
+
+      reg |= conv_start_mask;
+
+      g_xmc_vadc_group_array[i]->ARBPR = reg;
+    }
+
+  /* program Background Request Source Control register, use XT and GT write 
control bitfields */
+
+  VADC->BRSCTRL = (uint32_t)(config->asctrl | (uint32_t)VADC_BRSCTRL_XTWC_MASK 
| (uint32_t)VADC_BRSCTRL_GTWC_MASK);
+
+  /* program Background Request Source Mode register */
+
+  VADC->BRSMR = (uint32_t)((config->asmr) | 
(uint32_t)((uint32_t)XMC_VADC_GATEMODE_IGNORE << VADC_BRSMR_ENGT_SHIFT));
+  if (XMC_VADC_STARTMODE_CNR == (vadc_startmode_t)(config->conv_start_mode))
+    {
+      VADC->BRSMR |= (uint32_t)VADC_BRSMR_RPTDIS_MASK;
+    }
+
+  /* Re enable request source */
+
+  for (int i = 0; i < XMC_VADC_MAXIMUM_NUM_GROUPS; i++)
+    {
+      xmc4_vadc_group_background_enable_arbitrationslot((vadc_group_t 
*)g_xmc_vadc_group_array[i]);

Review Comment:
   Why do you need this cast ? 



##########
arch/arm/src/xmc4/xmc4_vadc.c:
##########
@@ -0,0 +1,576 @@
+/****************************************************************************
+ * arch/arm/src/xmc4/xmc4_vadc.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ * May include some logic from sample code provided by Infineon:
+ *
+ * Copyright (C) 2011-2015 Infineon Technologies AG. All rights reserved.
+ *
+ * Infineon Technologies AG (Infineon) is supplying this software for use
+ * with Infineon's microcontrollers.  This file can be freely distributed
+ * within development tools that are supporting such microcontrollers.
+ *
+ * THIS SOFTWARE IS PROVIDED AS IS. NO WARRANTIES, WHETHER EXPRESS,
+ * IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS
+ * SOFTWARE. INFINEON SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR
+ * SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <errno.h>
+#include <assert.h>
+
+#include <arch/xmc4/chip.h>
+
+#include "arm_internal.h"
+#include "hardware/xmc4_scu.h"
+#include "xmc4_vadc.h"
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static vadc_group_t *const g_xmc_vadc_group_array[XMC_VADC_MAXIMUM_NUM_GROUPS] 
= {
+                                                                               
   (vadc_group_t *)VADC_G0,
+                                                                               
   (vadc_group_t *)VADC_G1,
+                                                                               
   (vadc_group_t *)VADC_G2,
+                                                                               
   (vadc_group_t *)VADC_G3
+                                                                               
   };
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: xmc4_vadc_global_enable
+ *
+ * Description:
+ *   Ungate the clock to the VADC module (if applicable) and bring the VADC
+ *   module out of reset state.
+ *   Called in xmc4_vadc_global_initialize.
+ *
+ ****************************************************************************/
+
+void xmc4_vadc_global_enable(void)
+{
+  #ifdef XMC4_SCU_GATING
+  /* Check if VADC is gated */
+
+  if ((getreg32(XMC4_SCU_CGATSTAT0) & SCU_CGAT0_VADC) == 1)
+    {
+      /* Disable VADC gating */
+
+      putreg32(SCU_CGAT0_VADC, XMC4_SCU_CGATCLR0);
+    }
+
+  /* Set bit in PRCLR0 to de-assert VADC peripheral reset */
+
+  putreg32(SCU_PR0_VADCRS, XMC4_SCU_PRCLR0);
+  #else
+
+  /* Set bit in PRCLR0 to de-assert VADC peripheral reset */
+
+  putreg32(SCU_PR0_VADCRS, XMC4_SCU_PRCLR0);
+  #endif
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_global_disable
+ *
+ * Description:
+ *   Gate the clock to the VADC module (if applicable) and put the VADC
+ *   module into the reset state
+ *
+ ****************************************************************************/
+
+void xmc4_vadc_global_disable(void)
+{
+  /* Set bit in PRSET0 to assert VADC peripheral reset */
+
+  putreg32(SCU_PR0_VADCRS, XMC4_SCU_PRSET0);
+
+  #ifdef XMC4_SCU_GATING
+  /* Check if VADC is ungated */
+
+  if ((getreg32(XMC4_SCU_CGATSTAT0) & SCU_CGAT0_VADC) == 0)
+    {
+      /* Enable VADC gating */
+
+      putreg32(SCU_CGAT0_VADC, XMC4_SCU_CGATSET0);
+    }
+  #endif
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_global_initialize
+ *
+ * Description:
+ *   Initializes the VADC global module with the given configuration structure.
+ *   It initializes global input classes, boundaries , result resources.
+ *   Configures GLOBICLASS,GLOBBOUND,GLOBRCR registers.
+ *   It also configures the global analog and digital clock dividers
+ *   by setting GLOBCFG register.
+ *
+ ****************************************************************************/
+
+void xmc4_vadc_global_initialize(const vadc_global_config_t *config)
+{
+  /* Enable the VADC module */
+
+  xmc4_vadc_global_enable();
+
+  VADC->CLC = (uint32_t)(config->clc);
+
+  /* Clock configuration, use DIVWC (write control) to write register */
+
+  VADC->GLOBCFG = (uint32_t)(config->globcfg | 
(uint32_t)(VADC_GLOBCFG_DIVWC_MASK));
+
+  /* Global input class 0 configuration */
+
+  VADC->GLOBICLASS[0] = (uint32_t)(config->class0.iclass);
+
+  /* Global input class 1 configuration */
+
+  VADC->GLOBICLASS[1] = (uint32_t)(config->class1.iclass);
+
+  /* Global result generation configuration */
+
+  VADC->GLOBRCR = (uint32_t)(config->globrcr);
+
+  /* Set global boundaries values */
+
+  VADC->GLOBBOUND = (uint32_t)(config->globbound);
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_group_initialize
+ *
+ * Description:
+ *   Initializes the VADC group module with the associated
+ *   configuration structure pointed by config. It initializes group conversion
+ *   class, arbiter configuration, boundary configuration by setting
+ *   GxICLASS,GxARBCFG,GxBOUND, registers.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; A negated errno value is returned to
+ *   indicate the nature of any failure.
+ *
+ ****************************************************************************/
+
+int xmc4_vadc_group_initialize(vadc_group_t *const group_ptr, const 
vadc_group_config_t *config)
+{
+  if (!xmc_vadc_check_group_ptr(group_ptr))
+    {
+      return -EINVAL;
+    }
+
+  /* Configures the group-specific input classes,
+   * each channel is assigned to a class in GxCHCTRy
+   */
+
+  group_ptr->ICLASS[0] = config->class0.iclass;
+  group_ptr->ICLASS[1] = config->class1.iclass;
+
+  /* Configures the group arbitration behavior */
+
+  group_ptr->ARBCFG = config->g_arbcfg;
+
+  /* Configures the group-specific boundaries */
+
+  group_ptr->BOUND = config->g_bound;
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_group_set_powermode
+ *
+ * Description:
+ *   Configures the power mode of a VADC group. For a VADC group to
+ *   actually convert an analog signal, its analog converter must be turned on.
+ *   Configure the register bit field GxARBCFG.ANONC
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; A negated errno value is returned to
+ *   indicate the nature of any failure.
+ *
+ ****************************************************************************/
+
+int xmc4_vadc_group_set_powermode(vadc_group_t *const group_ptr, const 
vadc_group_powermode_t power_mode)
+{
+  if (!xmc_vadc_check_group_ptr(group_ptr) || (power_mode > 
XMC_VADC_GROUP_POWERMODE_NORMAL))
+    {
+      return -EINVAL;
+    }
+
+  uint32_t arbcfg = group_ptr->ARBCFG;
+
+  arbcfg &= ~((uint32_t)VADC_GxARBCFG_ANONC_MASK);
+  arbcfg |= (uint32_t)power_mode;
+
+  group_ptr->ARBCFG = arbcfg;
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_global_start_calibration
+ *
+ * Description:
+ *   Start the calibration process and loops until all active groups
+ *   finish calibration. Call xmc4_vadc_global_enable and
+ *   xmc4_vadc_global_initialize before calibration.
+ *   Configures the register bit field GLOBCFG.SUCAL.
+ *
+ ****************************************************************************/
+
+void xmc4_vadc_global_start_calibration(void)
+{
+  vadc_group_t * group_ptr;
+
+  /* Start Calibration */
+
+  VADC->GLOBCFG |= (uint32_t) VADC_GLOBCFG_SUCAL_MASK;
+
+  /* Loop until all groups to finish calibration */
+
+  for (int i = 0; i < XMC_VADC_MAXIMUM_NUM_GROUPS; i++)
+    {
+      group_ptr = g_xmc_vadc_group_array[i];
+
+      /* Check if group is active */
+
+      if ((group_ptr->ARBCFG) & (uint32_t)(VADC_GxARBCFG_ANONS_MASK))
+        {
+          /* Loop until it finish calibration */
+
+          while ((group_ptr->ARBCFG) & (uint32_t)VADC_GxARBCFG_CAL_MASK)
+            {
+              /* NOP */
+            }
+      }
+    }
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_group_background_enable_arbitrationslot
+ *
+ * Description:
+ *   Enables arbitration slot of the Background request source to
+ *   participate in the arbitration round. Even if a load event occurs the
+ *   Background channel can only be converted when the arbiter comes to the
+ *   Background slot. Thus this must be enabled if any conversion need to take
+ *   place.
+ *   Configure the register bit field GxARBPR.ASEN2.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; A negated errno value is returned to
+ *   indicate the nature of any failure.
+ *
+ ****************************************************************************/
+
+int xmc4_vadc_group_background_enable_arbitrationslot(vadc_group_t *const 
group_ptr)
+{
+  if (!xmc_vadc_check_group_ptr(group_ptr))
+    {
+      return -EINVAL;
+    }
+
+  group_ptr->ARBPR |= (uint32_t)VADC_GxARBPR_ASEN2_MASK;
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_group_background_disable_arbitrationslot
+ *
+ * Description:
+ *   Disables arbitration slot of the Background request source to
+ *   participate in the arbitration round. Even if a load event occurs the
+ *   Background channel can only be converted when the arbiter comes to the
+ *   Background slot. Thus this must be enabled if any conversion need to take
+ *   place.
+ *   Configure the register bit field GxARBPR.ASEN2.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; A negated errno value is returned to
+ *   indicate the nature of any failure.
+ *
+ ****************************************************************************/
+
+int xmc4_vadc_group_background_disable_arbitrationslot(vadc_group_t *const 
group_ptr)
+{
+  if (!xmc_vadc_check_group_ptr(group_ptr))
+    {
+      return -EINVAL;
+    }
+
+  group_ptr->ARBPR &= ~((uint32_t)VADC_GxARBPR_ASEN2_MASK);
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_global_background_initialize
+ *
+ * Description:
+ *   Initializes the Background scan functional block. The BACKGROUND
+ *   SCAN request source functional block converts channels of all VADC groups
+ *   that have not been assigned as a priority channel (priority channels can 
be
+ *   converted only by queue and scan). Related arbitration slot must be
+ *   disabled to configure background request, then re-enabled.
+ *
+ ****************************************************************************/
+
+void xmc4_vadc_global_background_initialize(const vadc_background_config_t 
*config)
+{
+  uint32_t reg;
+  uint32_t conv_start_mask;
+
+  /* Disable background request source to change its parameters */
+
+  for (int i = 0; i < XMC_VADC_MAXIMUM_NUM_GROUPS; i++)
+    {
+      xmc4_vadc_group_background_disable_arbitrationslot((vadc_group_t 
*)g_xmc_vadc_group_array[i]);
+    }
+
+  /* Set start mode */
+
+  conv_start_mask = (uint32_t) 0;
+  if (XMC_VADC_STARTMODE_WFS != (vadc_startmode_t)config->conv_start_mode)
+    {
+      conv_start_mask = (uint32_t)VADC_GxARBPR_CSM2_MASK;
+    }
+
+  /* Configures GxARBPR register for each group */
+
+  for (int i = 0; i < XMC_VADC_MAXIMUM_NUM_GROUPS; i++)
+    {
+      reg = g_xmc_vadc_group_array[i]->ARBPR;
+
+      /* Program the priority of the request source : Background Scan is 
source 2 */
+
+      reg &= ~(uint32_t)(VADC_GxARBPR_PRIO2_MASK);
+      reg |= (uint32_t)((uint32_t)config->req_src_priority << 
VADC_GxARBPR_PRIO2_SHIFT);
+
+      /* Program the start mode */
+
+      reg |= conv_start_mask;
+
+      g_xmc_vadc_group_array[i]->ARBPR = reg;
+    }
+
+  /* program Background Request Source Control register, use XT and GT write 
control bitfields */
+
+  VADC->BRSCTRL = (uint32_t)(config->asctrl | (uint32_t)VADC_BRSCTRL_XTWC_MASK 
| (uint32_t)VADC_BRSCTRL_GTWC_MASK);
+
+  /* program Background Request Source Mode register */
+
+  VADC->BRSMR = (uint32_t)((config->asmr) | 
(uint32_t)((uint32_t)XMC_VADC_GATEMODE_IGNORE << VADC_BRSMR_ENGT_SHIFT));
+  if (XMC_VADC_STARTMODE_CNR == (vadc_startmode_t)(config->conv_start_mode))
+    {
+      VADC->BRSMR |= (uint32_t)VADC_BRSMR_RPTDIS_MASK;
+    }
+
+  /* Re enable request source */
+
+  for (int i = 0; i < XMC_VADC_MAXIMUM_NUM_GROUPS; i++)
+    {
+      xmc4_vadc_group_background_enable_arbitrationslot((vadc_group_t 
*)g_xmc_vadc_group_array[i]);
+    }
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_group_channel_initialize
+ *
+ * Description:
+ *   Initializes the ADC channel for conversion. Must be called after
+ *   request source initialization for each channel to enable their conversion.
+ *   Configures registers GxCHCTRy and boundary flag GxBFL, GxBFLC and GxCHASS.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; A negated errno value is returned to
+ *   indicate the nature of any failure.
+ *
+ ****************************************************************************/
+
+int xmc4_vadc_group_channel_initialize(vadc_group_t *const group_ptr, const 
uint32_t ch_num,
+                                        const vadc_channel_config_t *config)
+{
+  if (!xmc_vadc_check_group_ptr(group_ptr) || (ch_num > 
XMC_VADC_NUM_CHANNELS_PER_GROUP))
+    {
+      return -EINVAL;
+    }
+
+  uint32_t prio  = (uint32_t)config->channel_priority;
+
+  /* Set channel priority, channel_priority must be 0 for background channel */
+
+  uint32_t ch_assign  = group_ptr->CHASS;
+  ch_assign &= ~((uint32_t)((uint32_t)1 << ch_num));
+  ch_assign |= (uint32_t)(prio << ch_num);
+  group_ptr->CHASS = ch_assign;
+
+  /* Alias channel, can replace CH0 and CH1 with another channel number. */
+
+  if (config->alias_channel >= (int32_t)0)
+    {
+      uint32_t mask = (uint32_t)0;
+      if ((uint32_t)1 == ch_num)
+        {
+          mask = VADC_GxALIAS_ALIAS1_SHIFT;
+          group_ptr->ALIAS &= ~(uint32_t)(VADC_GxALIAS_ALIAS1_MASK);
+        }
+      else if ((uint32_t)0 == ch_num)
+        {
+          mask = VADC_GxALIAS_ALIAS0_SHIFT;
+          group_ptr->ALIAS &= ~(uint32_t)(VADC_GxALIAS_ALIAS0_MASK);
+        }
+
+      group_ptr->ALIAS |= (uint32_t)(config->alias_channel << mask);
+    }
+
+  /* Set channel boundaries flag */
+
+  group_ptr->BFL |= config->bfl;
+  #if (XMC_VADC_BOUNDARY_FLAG_SELECT == 1U)
+    group_ptr->BFLC |= config->bflc;
+  #endif
+
+  /* Program the CHCTR register */
+
+  group_ptr->CHCTR[ch_num] = config->chctr;
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_global_background_add_channel_to_sequence
+ *
+ * Description:
+ *   Adds a channel to the background scan sequence. The pending
+ *   register are updated only after a new load event occured.
+ *   Configures the register bit fields of BRSSEL.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; A negated errno value is returned to
+ *   indicate the nature of any failure.
+ *
+ ****************************************************************************/
+
+int xmc4_vadc_global_background_add_channel_to_sequence(const uint32_t 
grp_num, const uint32_t ch_num)
+{
+  if ((grp_num > XMC_VADC_MAXIMUM_NUM_GROUPS) || (ch_num > 
XMC_VADC_NUM_CHANNELS_PER_GROUP))
+    {
+      return -EINVAL;
+    }
+
+  VADC->BRSSEL[grp_num] |= (uint32_t)((uint32_t)1 << ch_num);
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_global_background_enable_autoscan
+ *
+ * Description:
+ *   Enables continuous conversion mode (autoscan). Once all channels
+ *   belonging to a Background request source have been converted, a new  load
+ *   event occurs.
+ *   Configures the register bit field BRSMR.SCAN.
+ *
+ ****************************************************************************/
+
+void xmc4_vadc_global_background_enable_autoscan(void)
+{
+  VADC->BRSMR |= (uint32_t)VADC_BRSMR_SCAN_MASK;
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_global_background_start_conversion
+ *
+ * Description:
+ *   Generates conversion request (Software initiated conversion).
+ *   The background scan must been init.
+ *   Configures the register bit field BRSMR.LDEV.
+ *
+ ****************************************************************************/
+
+void xmc4_vadc_global_background_start_conversion(void)
+{
+  VADC->BRSMR |= (uint32_t)VADC_BRSMR_LDEV_MASK;
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_group_get_result
+ *
+ * Description:
+ *   Returns the result of the conversion in the given group result register.
+ *   Get the register bit field GxRES.RESULT.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; A negated errno value is returned to
+ *   indicate the nature of any failure.
+ *
+ ****************************************************************************/
+
+int xmc4_vadc_group_get_result(vadc_group_t *const group_ptr, const uint32_t 
res_reg, uint16_t *result_ptr)
+{
+  if (!xmc_vadc_check_group_ptr(group_ptr) || (res_reg > 
XMC_VADC_NUM_RESULT_REGISTERS))
+    {
+      return -EINVAL;
+    }
+
+  *result_ptr = ((uint16_t)group_ptr->RES[res_reg]);
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_group_channel_get_result
+ *
+ * Description:
+ *   Returns the result of the conversion of the given group channel.
+ *   Get the register bit field GxRES.RESULT.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; A negated errno value is returned to
+ *   indicate the nature of any failure.
+ *
+ ****************************************************************************/
+
+int xmc4_vadc_group_get_channel_result(vadc_group_t *const group_ptr, const 
uint32_t ch_num, uint16_t *result_ptr)
+{
+  if (!xmc_vadc_check_group_ptr(group_ptr) || (ch_num > 
XMC_VADC_NUM_CHANNELS_PER_GROUP))
+    {
+      return -EINVAL;
+    }
+
+  uint8_t resreg = (uint8_t)((group_ptr->CHCTR[ch_num] & 
(uint32_t)VADC_GxCHCTR_RESREG_MASK) >> VADC_GxCHCTR_RESREG_SHIFT);
+  *result_ptr = ((uint16_t)group_ptr->RES[resreg]);

Review Comment:
   missplaced brackets



##########
arch/arm/src/xmc4/xmc4_vadc.c:
##########
@@ -0,0 +1,576 @@
+/****************************************************************************
+ * arch/arm/src/xmc4/xmc4_vadc.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ * May include some logic from sample code provided by Infineon:
+ *
+ * Copyright (C) 2011-2015 Infineon Technologies AG. All rights reserved.
+ *
+ * Infineon Technologies AG (Infineon) is supplying this software for use
+ * with Infineon's microcontrollers.  This file can be freely distributed
+ * within development tools that are supporting such microcontrollers.
+ *
+ * THIS SOFTWARE IS PROVIDED AS IS. NO WARRANTIES, WHETHER EXPRESS,
+ * IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS
+ * SOFTWARE. INFINEON SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR
+ * SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <errno.h>
+#include <assert.h>
+
+#include <arch/xmc4/chip.h>
+
+#include "arm_internal.h"
+#include "hardware/xmc4_scu.h"
+#include "xmc4_vadc.h"
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static vadc_group_t *const g_xmc_vadc_group_array[XMC_VADC_MAXIMUM_NUM_GROUPS] 
= {
+                                                                               
   (vadc_group_t *)VADC_G0,
+                                                                               
   (vadc_group_t *)VADC_G1,
+                                                                               
   (vadc_group_t *)VADC_G2,
+                                                                               
   (vadc_group_t *)VADC_G3
+                                                                               
   };
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: xmc4_vadc_global_enable
+ *
+ * Description:
+ *   Ungate the clock to the VADC module (if applicable) and bring the VADC
+ *   module out of reset state.
+ *   Called in xmc4_vadc_global_initialize.
+ *
+ ****************************************************************************/
+
+void xmc4_vadc_global_enable(void)
+{
+  #ifdef XMC4_SCU_GATING
+  /* Check if VADC is gated */
+
+  if ((getreg32(XMC4_SCU_CGATSTAT0) & SCU_CGAT0_VADC) == 1)
+    {
+      /* Disable VADC gating */
+
+      putreg32(SCU_CGAT0_VADC, XMC4_SCU_CGATCLR0);
+    }
+
+  /* Set bit in PRCLR0 to de-assert VADC peripheral reset */
+
+  putreg32(SCU_PR0_VADCRS, XMC4_SCU_PRCLR0);
+  #else
+
+  /* Set bit in PRCLR0 to de-assert VADC peripheral reset */
+
+  putreg32(SCU_PR0_VADCRS, XMC4_SCU_PRCLR0);
+  #endif
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_global_disable
+ *
+ * Description:
+ *   Gate the clock to the VADC module (if applicable) and put the VADC
+ *   module into the reset state
+ *
+ ****************************************************************************/
+
+void xmc4_vadc_global_disable(void)
+{
+  /* Set bit in PRSET0 to assert VADC peripheral reset */
+
+  putreg32(SCU_PR0_VADCRS, XMC4_SCU_PRSET0);
+
+  #ifdef XMC4_SCU_GATING
+  /* Check if VADC is ungated */
+
+  if ((getreg32(XMC4_SCU_CGATSTAT0) & SCU_CGAT0_VADC) == 0)
+    {
+      /* Enable VADC gating */
+
+      putreg32(SCU_CGAT0_VADC, XMC4_SCU_CGATSET0);
+    }
+  #endif
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_global_initialize
+ *
+ * Description:
+ *   Initializes the VADC global module with the given configuration structure.
+ *   It initializes global input classes, boundaries , result resources.
+ *   Configures GLOBICLASS,GLOBBOUND,GLOBRCR registers.
+ *   It also configures the global analog and digital clock dividers
+ *   by setting GLOBCFG register.
+ *
+ ****************************************************************************/
+
+void xmc4_vadc_global_initialize(const vadc_global_config_t *config)
+{
+  /* Enable the VADC module */
+
+  xmc4_vadc_global_enable();
+
+  VADC->CLC = (uint32_t)(config->clc);
+
+  /* Clock configuration, use DIVWC (write control) to write register */
+
+  VADC->GLOBCFG = (uint32_t)(config->globcfg | 
(uint32_t)(VADC_GLOBCFG_DIVWC_MASK));
+
+  /* Global input class 0 configuration */
+
+  VADC->GLOBICLASS[0] = (uint32_t)(config->class0.iclass);
+
+  /* Global input class 1 configuration */
+
+  VADC->GLOBICLASS[1] = (uint32_t)(config->class1.iclass);
+
+  /* Global result generation configuration */
+
+  VADC->GLOBRCR = (uint32_t)(config->globrcr);
+
+  /* Set global boundaries values */
+
+  VADC->GLOBBOUND = (uint32_t)(config->globbound);
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_group_initialize
+ *
+ * Description:
+ *   Initializes the VADC group module with the associated
+ *   configuration structure pointed by config. It initializes group conversion
+ *   class, arbiter configuration, boundary configuration by setting
+ *   GxICLASS,GxARBCFG,GxBOUND, registers.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; A negated errno value is returned to
+ *   indicate the nature of any failure.
+ *
+ ****************************************************************************/
+
+int xmc4_vadc_group_initialize(vadc_group_t *const group_ptr, const 
vadc_group_config_t *config)
+{
+  if (!xmc_vadc_check_group_ptr(group_ptr))
+    {
+      return -EINVAL;
+    }
+
+  /* Configures the group-specific input classes,
+   * each channel is assigned to a class in GxCHCTRy
+   */
+
+  group_ptr->ICLASS[0] = config->class0.iclass;
+  group_ptr->ICLASS[1] = config->class1.iclass;
+
+  /* Configures the group arbitration behavior */
+
+  group_ptr->ARBCFG = config->g_arbcfg;
+
+  /* Configures the group-specific boundaries */
+
+  group_ptr->BOUND = config->g_bound;
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_group_set_powermode
+ *
+ * Description:
+ *   Configures the power mode of a VADC group. For a VADC group to
+ *   actually convert an analog signal, its analog converter must be turned on.
+ *   Configure the register bit field GxARBCFG.ANONC
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; A negated errno value is returned to
+ *   indicate the nature of any failure.
+ *
+ ****************************************************************************/
+
+int xmc4_vadc_group_set_powermode(vadc_group_t *const group_ptr, const 
vadc_group_powermode_t power_mode)
+{
+  if (!xmc_vadc_check_group_ptr(group_ptr) || (power_mode > 
XMC_VADC_GROUP_POWERMODE_NORMAL))
+    {
+      return -EINVAL;
+    }
+
+  uint32_t arbcfg = group_ptr->ARBCFG;
+
+  arbcfg &= ~((uint32_t)VADC_GxARBCFG_ANONC_MASK);
+  arbcfg |= (uint32_t)power_mode;
+
+  group_ptr->ARBCFG = arbcfg;
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_global_start_calibration
+ *
+ * Description:
+ *   Start the calibration process and loops until all active groups
+ *   finish calibration. Call xmc4_vadc_global_enable and
+ *   xmc4_vadc_global_initialize before calibration.
+ *   Configures the register bit field GLOBCFG.SUCAL.
+ *
+ ****************************************************************************/
+
+void xmc4_vadc_global_start_calibration(void)
+{
+  vadc_group_t * group_ptr;
+
+  /* Start Calibration */
+
+  VADC->GLOBCFG |= (uint32_t) VADC_GLOBCFG_SUCAL_MASK;
+
+  /* Loop until all groups to finish calibration */
+
+  for (int i = 0; i < XMC_VADC_MAXIMUM_NUM_GROUPS; i++)
+    {
+      group_ptr = g_xmc_vadc_group_array[i];
+
+      /* Check if group is active */
+
+      if ((group_ptr->ARBCFG) & (uint32_t)(VADC_GxARBCFG_ANONS_MASK))
+        {
+          /* Loop until it finish calibration */
+
+          while ((group_ptr->ARBCFG) & (uint32_t)VADC_GxARBCFG_CAL_MASK)
+            {
+              /* NOP */
+            }
+      }
+    }
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_group_background_enable_arbitrationslot
+ *
+ * Description:
+ *   Enables arbitration slot of the Background request source to
+ *   participate in the arbitration round. Even if a load event occurs the
+ *   Background channel can only be converted when the arbiter comes to the
+ *   Background slot. Thus this must be enabled if any conversion need to take
+ *   place.
+ *   Configure the register bit field GxARBPR.ASEN2.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; A negated errno value is returned to
+ *   indicate the nature of any failure.
+ *
+ ****************************************************************************/
+
+int xmc4_vadc_group_background_enable_arbitrationslot(vadc_group_t *const 
group_ptr)
+{
+  if (!xmc_vadc_check_group_ptr(group_ptr))
+    {
+      return -EINVAL;
+    }
+
+  group_ptr->ARBPR |= (uint32_t)VADC_GxARBPR_ASEN2_MASK;
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_group_background_disable_arbitrationslot
+ *
+ * Description:
+ *   Disables arbitration slot of the Background request source to
+ *   participate in the arbitration round. Even if a load event occurs the
+ *   Background channel can only be converted when the arbiter comes to the
+ *   Background slot. Thus this must be enabled if any conversion need to take
+ *   place.
+ *   Configure the register bit field GxARBPR.ASEN2.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; A negated errno value is returned to
+ *   indicate the nature of any failure.
+ *
+ ****************************************************************************/
+
+int xmc4_vadc_group_background_disable_arbitrationslot(vadc_group_t *const 
group_ptr)
+{
+  if (!xmc_vadc_check_group_ptr(group_ptr))
+    {
+      return -EINVAL;
+    }
+
+  group_ptr->ARBPR &= ~((uint32_t)VADC_GxARBPR_ASEN2_MASK);
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_global_background_initialize
+ *
+ * Description:
+ *   Initializes the Background scan functional block. The BACKGROUND
+ *   SCAN request source functional block converts channels of all VADC groups
+ *   that have not been assigned as a priority channel (priority channels can 
be
+ *   converted only by queue and scan). Related arbitration slot must be
+ *   disabled to configure background request, then re-enabled.
+ *
+ ****************************************************************************/
+
+void xmc4_vadc_global_background_initialize(const vadc_background_config_t 
*config)
+{
+  uint32_t reg;
+  uint32_t conv_start_mask;
+
+  /* Disable background request source to change its parameters */
+
+  for (int i = 0; i < XMC_VADC_MAXIMUM_NUM_GROUPS; i++)
+    {
+      xmc4_vadc_group_background_disable_arbitrationslot((vadc_group_t 
*)g_xmc_vadc_group_array[i]);
+    }
+
+  /* Set start mode */
+
+  conv_start_mask = (uint32_t) 0;
+  if (XMC_VADC_STARTMODE_WFS != (vadc_startmode_t)config->conv_start_mode)
+    {
+      conv_start_mask = (uint32_t)VADC_GxARBPR_CSM2_MASK;
+    }
+
+  /* Configures GxARBPR register for each group */
+
+  for (int i = 0; i < XMC_VADC_MAXIMUM_NUM_GROUPS; i++)
+    {
+      reg = g_xmc_vadc_group_array[i]->ARBPR;
+
+      /* Program the priority of the request source : Background Scan is 
source 2 */
+
+      reg &= ~(uint32_t)(VADC_GxARBPR_PRIO2_MASK);
+      reg |= (uint32_t)((uint32_t)config->req_src_priority << 
VADC_GxARBPR_PRIO2_SHIFT);
+
+      /* Program the start mode */
+
+      reg |= conv_start_mask;
+
+      g_xmc_vadc_group_array[i]->ARBPR = reg;
+    }
+
+  /* program Background Request Source Control register, use XT and GT write 
control bitfields */
+
+  VADC->BRSCTRL = (uint32_t)(config->asctrl | (uint32_t)VADC_BRSCTRL_XTWC_MASK 
| (uint32_t)VADC_BRSCTRL_GTWC_MASK);
+
+  /* program Background Request Source Mode register */
+
+  VADC->BRSMR = (uint32_t)((config->asmr) | 
(uint32_t)((uint32_t)XMC_VADC_GATEMODE_IGNORE << VADC_BRSMR_ENGT_SHIFT));
+  if (XMC_VADC_STARTMODE_CNR == (vadc_startmode_t)(config->conv_start_mode))
+    {
+      VADC->BRSMR |= (uint32_t)VADC_BRSMR_RPTDIS_MASK;
+    }
+
+  /* Re enable request source */
+
+  for (int i = 0; i < XMC_VADC_MAXIMUM_NUM_GROUPS; i++)
+    {
+      xmc4_vadc_group_background_enable_arbitrationslot((vadc_group_t 
*)g_xmc_vadc_group_array[i]);
+    }
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_group_channel_initialize
+ *
+ * Description:
+ *   Initializes the ADC channel for conversion. Must be called after
+ *   request source initialization for each channel to enable their conversion.
+ *   Configures registers GxCHCTRy and boundary flag GxBFL, GxBFLC and GxCHASS.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; A negated errno value is returned to
+ *   indicate the nature of any failure.
+ *
+ ****************************************************************************/
+
+int xmc4_vadc_group_channel_initialize(vadc_group_t *const group_ptr, const 
uint32_t ch_num,
+                                        const vadc_channel_config_t *config)
+{
+  if (!xmc_vadc_check_group_ptr(group_ptr) || (ch_num > 
XMC_VADC_NUM_CHANNELS_PER_GROUP))
+    {
+      return -EINVAL;
+    }
+
+  uint32_t prio  = (uint32_t)config->channel_priority;
+
+  /* Set channel priority, channel_priority must be 0 for background channel */
+
+  uint32_t ch_assign  = group_ptr->CHASS;
+  ch_assign &= ~((uint32_t)((uint32_t)1 << ch_num));
+  ch_assign |= (uint32_t)(prio << ch_num);
+  group_ptr->CHASS = ch_assign;
+
+  /* Alias channel, can replace CH0 and CH1 with another channel number. */
+
+  if (config->alias_channel >= (int32_t)0)
+    {
+      uint32_t mask = (uint32_t)0;
+      if ((uint32_t)1 == ch_num)
+        {
+          mask = VADC_GxALIAS_ALIAS1_SHIFT;
+          group_ptr->ALIAS &= ~(uint32_t)(VADC_GxALIAS_ALIAS1_MASK);
+        }
+      else if ((uint32_t)0 == ch_num)
+        {
+          mask = VADC_GxALIAS_ALIAS0_SHIFT;
+          group_ptr->ALIAS &= ~(uint32_t)(VADC_GxALIAS_ALIAS0_MASK);
+        }
+
+      group_ptr->ALIAS |= (uint32_t)(config->alias_channel << mask);
+    }
+
+  /* Set channel boundaries flag */
+
+  group_ptr->BFL |= config->bfl;
+  #if (XMC_VADC_BOUNDARY_FLAG_SELECT == 1U)
+    group_ptr->BFLC |= config->bflc;
+  #endif
+
+  /* Program the CHCTR register */
+
+  group_ptr->CHCTR[ch_num] = config->chctr;
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_global_background_add_channel_to_sequence
+ *
+ * Description:
+ *   Adds a channel to the background scan sequence. The pending
+ *   register are updated only after a new load event occured.
+ *   Configures the register bit fields of BRSSEL.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; A negated errno value is returned to
+ *   indicate the nature of any failure.
+ *
+ ****************************************************************************/
+
+int xmc4_vadc_global_background_add_channel_to_sequence(const uint32_t 
grp_num, const uint32_t ch_num)
+{
+  if ((grp_num > XMC_VADC_MAXIMUM_NUM_GROUPS) || (ch_num > 
XMC_VADC_NUM_CHANNELS_PER_GROUP))
+    {
+      return -EINVAL;
+    }
+
+  VADC->BRSSEL[grp_num] |= (uint32_t)((uint32_t)1 << ch_num);

Review Comment:
   Do you really need the cast of the 1 ?



##########
arch/arm/src/xmc4/xmc4_vadc.c:
##########
@@ -0,0 +1,576 @@
+/****************************************************************************
+ * arch/arm/src/xmc4/xmc4_vadc.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ * May include some logic from sample code provided by Infineon:
+ *
+ * Copyright (C) 2011-2015 Infineon Technologies AG. All rights reserved.
+ *
+ * Infineon Technologies AG (Infineon) is supplying this software for use
+ * with Infineon's microcontrollers.  This file can be freely distributed
+ * within development tools that are supporting such microcontrollers.
+ *
+ * THIS SOFTWARE IS PROVIDED AS IS. NO WARRANTIES, WHETHER EXPRESS,
+ * IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS
+ * SOFTWARE. INFINEON SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR
+ * SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <errno.h>
+#include <assert.h>
+
+#include <arch/xmc4/chip.h>
+
+#include "arm_internal.h"
+#include "hardware/xmc4_scu.h"
+#include "xmc4_vadc.h"
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static vadc_group_t *const g_xmc_vadc_group_array[XMC_VADC_MAXIMUM_NUM_GROUPS] 
= {
+                                                                               
   (vadc_group_t *)VADC_G0,
+                                                                               
   (vadc_group_t *)VADC_G1,
+                                                                               
   (vadc_group_t *)VADC_G2,
+                                                                               
   (vadc_group_t *)VADC_G3
+                                                                               
   };
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: xmc4_vadc_global_enable
+ *
+ * Description:
+ *   Ungate the clock to the VADC module (if applicable) and bring the VADC
+ *   module out of reset state.
+ *   Called in xmc4_vadc_global_initialize.
+ *
+ ****************************************************************************/
+
+void xmc4_vadc_global_enable(void)
+{
+  #ifdef XMC4_SCU_GATING
+  /* Check if VADC is gated */
+
+  if ((getreg32(XMC4_SCU_CGATSTAT0) & SCU_CGAT0_VADC) == 1)
+    {
+      /* Disable VADC gating */
+
+      putreg32(SCU_CGAT0_VADC, XMC4_SCU_CGATCLR0);
+    }
+
+  /* Set bit in PRCLR0 to de-assert VADC peripheral reset */
+
+  putreg32(SCU_PR0_VADCRS, XMC4_SCU_PRCLR0);
+  #else
+
+  /* Set bit in PRCLR0 to de-assert VADC peripheral reset */
+
+  putreg32(SCU_PR0_VADCRS, XMC4_SCU_PRCLR0);
+  #endif
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_global_disable
+ *
+ * Description:
+ *   Gate the clock to the VADC module (if applicable) and put the VADC
+ *   module into the reset state
+ *
+ ****************************************************************************/
+
+void xmc4_vadc_global_disable(void)
+{
+  /* Set bit in PRSET0 to assert VADC peripheral reset */
+
+  putreg32(SCU_PR0_VADCRS, XMC4_SCU_PRSET0);
+
+  #ifdef XMC4_SCU_GATING
+  /* Check if VADC is ungated */
+
+  if ((getreg32(XMC4_SCU_CGATSTAT0) & SCU_CGAT0_VADC) == 0)
+    {
+      /* Enable VADC gating */
+
+      putreg32(SCU_CGAT0_VADC, XMC4_SCU_CGATSET0);
+    }
+  #endif
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_global_initialize
+ *
+ * Description:
+ *   Initializes the VADC global module with the given configuration structure.
+ *   It initializes global input classes, boundaries , result resources.
+ *   Configures GLOBICLASS,GLOBBOUND,GLOBRCR registers.
+ *   It also configures the global analog and digital clock dividers
+ *   by setting GLOBCFG register.
+ *
+ ****************************************************************************/
+
+void xmc4_vadc_global_initialize(const vadc_global_config_t *config)
+{
+  /* Enable the VADC module */
+
+  xmc4_vadc_global_enable();
+
+  VADC->CLC = (uint32_t)(config->clc);
+
+  /* Clock configuration, use DIVWC (write control) to write register */
+
+  VADC->GLOBCFG = (uint32_t)(config->globcfg | 
(uint32_t)(VADC_GLOBCFG_DIVWC_MASK));
+
+  /* Global input class 0 configuration */
+
+  VADC->GLOBICLASS[0] = (uint32_t)(config->class0.iclass);
+
+  /* Global input class 1 configuration */
+
+  VADC->GLOBICLASS[1] = (uint32_t)(config->class1.iclass);
+
+  /* Global result generation configuration */
+
+  VADC->GLOBRCR = (uint32_t)(config->globrcr);
+
+  /* Set global boundaries values */
+
+  VADC->GLOBBOUND = (uint32_t)(config->globbound);
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_group_initialize
+ *
+ * Description:
+ *   Initializes the VADC group module with the associated
+ *   configuration structure pointed by config. It initializes group conversion
+ *   class, arbiter configuration, boundary configuration by setting
+ *   GxICLASS,GxARBCFG,GxBOUND, registers.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; A negated errno value is returned to
+ *   indicate the nature of any failure.
+ *
+ ****************************************************************************/
+
+int xmc4_vadc_group_initialize(vadc_group_t *const group_ptr, const 
vadc_group_config_t *config)
+{
+  if (!xmc_vadc_check_group_ptr(group_ptr))
+    {
+      return -EINVAL;
+    }
+
+  /* Configures the group-specific input classes,
+   * each channel is assigned to a class in GxCHCTRy
+   */
+
+  group_ptr->ICLASS[0] = config->class0.iclass;
+  group_ptr->ICLASS[1] = config->class1.iclass;
+
+  /* Configures the group arbitration behavior */
+
+  group_ptr->ARBCFG = config->g_arbcfg;
+
+  /* Configures the group-specific boundaries */
+
+  group_ptr->BOUND = config->g_bound;
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_group_set_powermode
+ *
+ * Description:
+ *   Configures the power mode of a VADC group. For a VADC group to
+ *   actually convert an analog signal, its analog converter must be turned on.
+ *   Configure the register bit field GxARBCFG.ANONC
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; A negated errno value is returned to
+ *   indicate the nature of any failure.
+ *
+ ****************************************************************************/
+
+int xmc4_vadc_group_set_powermode(vadc_group_t *const group_ptr, const 
vadc_group_powermode_t power_mode)
+{
+  if (!xmc_vadc_check_group_ptr(group_ptr) || (power_mode > 
XMC_VADC_GROUP_POWERMODE_NORMAL))
+    {
+      return -EINVAL;
+    }
+
+  uint32_t arbcfg = group_ptr->ARBCFG;
+
+  arbcfg &= ~((uint32_t)VADC_GxARBCFG_ANONC_MASK);
+  arbcfg |= (uint32_t)power_mode;
+
+  group_ptr->ARBCFG = arbcfg;
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_global_start_calibration
+ *
+ * Description:
+ *   Start the calibration process and loops until all active groups
+ *   finish calibration. Call xmc4_vadc_global_enable and
+ *   xmc4_vadc_global_initialize before calibration.
+ *   Configures the register bit field GLOBCFG.SUCAL.
+ *
+ ****************************************************************************/
+
+void xmc4_vadc_global_start_calibration(void)
+{
+  vadc_group_t * group_ptr;
+
+  /* Start Calibration */
+
+  VADC->GLOBCFG |= (uint32_t) VADC_GLOBCFG_SUCAL_MASK;
+
+  /* Loop until all groups to finish calibration */
+
+  for (int i = 0; i < XMC_VADC_MAXIMUM_NUM_GROUPS; i++)
+    {
+      group_ptr = g_xmc_vadc_group_array[i];
+
+      /* Check if group is active */
+
+      if ((group_ptr->ARBCFG) & (uint32_t)(VADC_GxARBCFG_ANONS_MASK))
+        {
+          /* Loop until it finish calibration */
+
+          while ((group_ptr->ARBCFG) & (uint32_t)VADC_GxARBCFG_CAL_MASK)
+            {
+              /* NOP */
+            }
+      }
+    }
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_group_background_enable_arbitrationslot
+ *
+ * Description:
+ *   Enables arbitration slot of the Background request source to
+ *   participate in the arbitration round. Even if a load event occurs the
+ *   Background channel can only be converted when the arbiter comes to the
+ *   Background slot. Thus this must be enabled if any conversion need to take
+ *   place.
+ *   Configure the register bit field GxARBPR.ASEN2.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; A negated errno value is returned to
+ *   indicate the nature of any failure.
+ *
+ ****************************************************************************/
+
+int xmc4_vadc_group_background_enable_arbitrationslot(vadc_group_t *const 
group_ptr)
+{
+  if (!xmc_vadc_check_group_ptr(group_ptr))
+    {
+      return -EINVAL;
+    }
+
+  group_ptr->ARBPR |= (uint32_t)VADC_GxARBPR_ASEN2_MASK;
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_group_background_disable_arbitrationslot
+ *
+ * Description:
+ *   Disables arbitration slot of the Background request source to
+ *   participate in the arbitration round. Even if a load event occurs the
+ *   Background channel can only be converted when the arbiter comes to the
+ *   Background slot. Thus this must be enabled if any conversion need to take
+ *   place.
+ *   Configure the register bit field GxARBPR.ASEN2.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; A negated errno value is returned to
+ *   indicate the nature of any failure.
+ *
+ ****************************************************************************/
+
+int xmc4_vadc_group_background_disable_arbitrationslot(vadc_group_t *const 
group_ptr)
+{
+  if (!xmc_vadc_check_group_ptr(group_ptr))
+    {
+      return -EINVAL;
+    }
+
+  group_ptr->ARBPR &= ~((uint32_t)VADC_GxARBPR_ASEN2_MASK);
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_global_background_initialize
+ *
+ * Description:
+ *   Initializes the Background scan functional block. The BACKGROUND
+ *   SCAN request source functional block converts channels of all VADC groups
+ *   that have not been assigned as a priority channel (priority channels can 
be
+ *   converted only by queue and scan). Related arbitration slot must be
+ *   disabled to configure background request, then re-enabled.
+ *
+ ****************************************************************************/
+
+void xmc4_vadc_global_background_initialize(const vadc_background_config_t 
*config)
+{
+  uint32_t reg;
+  uint32_t conv_start_mask;
+
+  /* Disable background request source to change its parameters */
+
+  for (int i = 0; i < XMC_VADC_MAXIMUM_NUM_GROUPS; i++)
+    {
+      xmc4_vadc_group_background_disable_arbitrationslot((vadc_group_t 
*)g_xmc_vadc_group_array[i]);
+    }
+
+  /* Set start mode */
+
+  conv_start_mask = (uint32_t) 0;
+  if (XMC_VADC_STARTMODE_WFS != (vadc_startmode_t)config->conv_start_mode)
+    {
+      conv_start_mask = (uint32_t)VADC_GxARBPR_CSM2_MASK;
+    }
+
+  /* Configures GxARBPR register for each group */
+
+  for (int i = 0; i < XMC_VADC_MAXIMUM_NUM_GROUPS; i++)
+    {
+      reg = g_xmc_vadc_group_array[i]->ARBPR;
+
+      /* Program the priority of the request source : Background Scan is 
source 2 */
+
+      reg &= ~(uint32_t)(VADC_GxARBPR_PRIO2_MASK);
+      reg |= (uint32_t)((uint32_t)config->req_src_priority << 
VADC_GxARBPR_PRIO2_SHIFT);
+
+      /* Program the start mode */
+
+      reg |= conv_start_mask;
+
+      g_xmc_vadc_group_array[i]->ARBPR = reg;
+    }
+
+  /* program Background Request Source Control register, use XT and GT write 
control bitfields */
+
+  VADC->BRSCTRL = (uint32_t)(config->asctrl | (uint32_t)VADC_BRSCTRL_XTWC_MASK 
| (uint32_t)VADC_BRSCTRL_GTWC_MASK);
+
+  /* program Background Request Source Mode register */
+
+  VADC->BRSMR = (uint32_t)((config->asmr) | 
(uint32_t)((uint32_t)XMC_VADC_GATEMODE_IGNORE << VADC_BRSMR_ENGT_SHIFT));
+  if (XMC_VADC_STARTMODE_CNR == (vadc_startmode_t)(config->conv_start_mode))
+    {
+      VADC->BRSMR |= (uint32_t)VADC_BRSMR_RPTDIS_MASK;
+    }
+
+  /* Re enable request source */
+
+  for (int i = 0; i < XMC_VADC_MAXIMUM_NUM_GROUPS; i++)
+    {
+      xmc4_vadc_group_background_enable_arbitrationslot((vadc_group_t 
*)g_xmc_vadc_group_array[i]);
+    }
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_group_channel_initialize
+ *
+ * Description:
+ *   Initializes the ADC channel for conversion. Must be called after
+ *   request source initialization for each channel to enable their conversion.
+ *   Configures registers GxCHCTRy and boundary flag GxBFL, GxBFLC and GxCHASS.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; A negated errno value is returned to
+ *   indicate the nature of any failure.
+ *
+ ****************************************************************************/
+
+int xmc4_vadc_group_channel_initialize(vadc_group_t *const group_ptr, const 
uint32_t ch_num,
+                                        const vadc_channel_config_t *config)
+{
+  if (!xmc_vadc_check_group_ptr(group_ptr) || (ch_num > 
XMC_VADC_NUM_CHANNELS_PER_GROUP))
+    {
+      return -EINVAL;
+    }
+
+  uint32_t prio  = (uint32_t)config->channel_priority;
+
+  /* Set channel priority, channel_priority must be 0 for background channel */
+
+  uint32_t ch_assign  = group_ptr->CHASS;
+  ch_assign &= ~((uint32_t)((uint32_t)1 << ch_num));
+  ch_assign |= (uint32_t)(prio << ch_num);
+  group_ptr->CHASS = ch_assign;
+
+  /* Alias channel, can replace CH0 and CH1 with another channel number. */
+
+  if (config->alias_channel >= (int32_t)0)
+    {
+      uint32_t mask = (uint32_t)0;
+      if ((uint32_t)1 == ch_num)
+        {
+          mask = VADC_GxALIAS_ALIAS1_SHIFT;
+          group_ptr->ALIAS &= ~(uint32_t)(VADC_GxALIAS_ALIAS1_MASK);
+        }
+      else if ((uint32_t)0 == ch_num)
+        {
+          mask = VADC_GxALIAS_ALIAS0_SHIFT;
+          group_ptr->ALIAS &= ~(uint32_t)(VADC_GxALIAS_ALIAS0_MASK);
+        }
+
+      group_ptr->ALIAS |= (uint32_t)(config->alias_channel << mask);
+    }
+
+  /* Set channel boundaries flag */
+
+  group_ptr->BFL |= config->bfl;
+  #if (XMC_VADC_BOUNDARY_FLAG_SELECT == 1U)
+    group_ptr->BFLC |= config->bflc;
+  #endif
+
+  /* Program the CHCTR register */
+
+  group_ptr->CHCTR[ch_num] = config->chctr;
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_global_background_add_channel_to_sequence
+ *
+ * Description:
+ *   Adds a channel to the background scan sequence. The pending
+ *   register are updated only after a new load event occured.
+ *   Configures the register bit fields of BRSSEL.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; A negated errno value is returned to
+ *   indicate the nature of any failure.
+ *
+ ****************************************************************************/
+
+int xmc4_vadc_global_background_add_channel_to_sequence(const uint32_t 
grp_num, const uint32_t ch_num)
+{
+  if ((grp_num > XMC_VADC_MAXIMUM_NUM_GROUPS) || (ch_num > 
XMC_VADC_NUM_CHANNELS_PER_GROUP))
+    {
+      return -EINVAL;
+    }
+
+  VADC->BRSSEL[grp_num] |= (uint32_t)((uint32_t)1 << ch_num);
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_global_background_enable_autoscan
+ *
+ * Description:
+ *   Enables continuous conversion mode (autoscan). Once all channels
+ *   belonging to a Background request source have been converted, a new  load
+ *   event occurs.
+ *   Configures the register bit field BRSMR.SCAN.
+ *
+ ****************************************************************************/
+
+void xmc4_vadc_global_background_enable_autoscan(void)
+{
+  VADC->BRSMR |= (uint32_t)VADC_BRSMR_SCAN_MASK;
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_global_background_start_conversion
+ *
+ * Description:
+ *   Generates conversion request (Software initiated conversion).
+ *   The background scan must been init.
+ *   Configures the register bit field BRSMR.LDEV.
+ *
+ ****************************************************************************/
+
+void xmc4_vadc_global_background_start_conversion(void)
+{
+  VADC->BRSMR |= (uint32_t)VADC_BRSMR_LDEV_MASK;
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_group_get_result
+ *
+ * Description:
+ *   Returns the result of the conversion in the given group result register.
+ *   Get the register bit field GxRES.RESULT.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; A negated errno value is returned to
+ *   indicate the nature of any failure.
+ *
+ ****************************************************************************/
+
+int xmc4_vadc_group_get_result(vadc_group_t *const group_ptr, const uint32_t 
res_reg, uint16_t *result_ptr)
+{
+  if (!xmc_vadc_check_group_ptr(group_ptr) || (res_reg > 
XMC_VADC_NUM_RESULT_REGISTERS))
+    {
+      return -EINVAL;
+    }
+
+  *result_ptr = ((uint16_t)group_ptr->RES[res_reg]);

Review Comment:
   missplaced bracket 



##########
arch/arm/src/xmc4/xmc4_vadc.h:
##########
@@ -0,0 +1,641 @@
+/****************************************************************************
+ * arch/arm/src/xmc4/xmc4_vadc.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ * May include some logic from sample code provided by Infineon:
+ *
+ * Copyright (C) 2011-2015 Infineon Technologies AG. All rights reserved.
+ *
+ * Infineon Technologies AG (Infineon) is supplying this software for use
+ * with Infineon's microcontrollers.  This file can be freely distributed
+ * within development tools that are supporting such microcontrollers.
+ *
+ * THIS SOFTWARE IS PROVIDED AS IS. NO WARRANTIES, WHETHER EXPRESS,
+ * IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS
+ * SOFTWARE. INFINEON SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR
+ * SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
+ *
+ ****************************************************************************/
+
+#ifndef __ARCH_ARM_SRC_XMC4_XMC4_VADC_H
+#define __ARCH_ARM_SRC_XMC4_XMC4_VADC_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <stdint.h>
+#include "xmc4_config.h"
+
+#include "hardware/xmc4_vadc.h"
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/**
+ *  Structure to handle the global and groups Input Class configurations.
+ *  Configured parameters are sample time and conversion Mode.
+ */
+
+typedef struct XMC_VADC_INPUT_CLASS_CONFIG
+{
+  /* GLOBICLASSx register config */
+
+  union
+  {
+    struct
+    {
+      uint32_t sample_time_std_conv         : 5;  /* Sample time for channels 
directly connected to VADC. Range : [0x0 to 0x1F] */
+      uint32_t                              : 3;
+      uint32_t conversion_mode_standard     : 3;  /* Conversion mode for 
channels directly connected to VADC.
+                                                   * Uses vadc_convmode_t */
+      uint32_t                              : 5;
+      uint32_t sampling_phase_emux_channel  : 5;  /* Sample time for channels 
connected via EMUX. Range: [0x0 to 0x1F] */
+      uint32_t                              : 3;
+      uint32_t conversion_mode_emux         : 3;  /* Conversion mode for 
channels connected via EMUX to VADC.
+                                                   * Uses vadc_convmode_t */
+      uint32_t                              : 5;
+    };
+    uint32_t iclass;
+  };
+} vadc_input_class_config_t;
+
+/**
+ *   Structure to handle the VADC Global registers configurations
+ */
+
+typedef struct XMC_VADC_GLOBAL_CONFIG
+{
+  /* GLOBBOUND register config */
+
+  union
+  {
+    struct
+    {
+      uint32_t boundary0        : 12;  /* Boundary value for results 
comparison */
+      uint32_t                  : 4;
+      uint32_t boundary1        : 12;  /* Boundary value for results 
comparison */
+      uint32_t                  : 4;
+    };
+    uint32_t globbound;
+  };
+
+  /* GLOBCFG register config */
+
+  union
+  {
+    struct
+    {
+      uint32_t analog_clock_divider   : 5;   /* Clock for the converter. 
Range: [0x0 to 0x1F] */
+      uint32_t                        : 2;
+      uint32_t msb_conversion_clock   : 1;   /* Additional clock cycle for 
analog converter */
+      uint32_t arbiter_clock_divider  : 2;   /* Request source arbiter clock 
divider. Range: [0x0 to 0x3] */
+      uint32_t                        : 5;
+      uint32_t                        : 17;
+    };
+    uint32_t globcfg;
+  };
+
+  /* GLOBICLASS0 register config */
+
+  vadc_input_class_config_t class0;
+
+  /* GLOBICLASS1 register config */
+
+  vadc_input_class_config_t class1;
+
+  /* GLOBRCR register config */
+
+  union
+  {
+    struct
+    {
+      uint32_t                        : 16;
+      uint32_t data_reduction_control : 4;   /* Data reduction stages */
+      uint32_t                        : 4;
+      uint32_t wait_for_read_mode     : 1;   /* Results of the next conversion 
will not be overwritten. */
+      uint32_t                        : 6;
+      uint32_t event_gen_enable       : 1;   /* Generates an event on 
availability of new result. */
+    };
+    uint32_t globrcr;
+  };
+
+  /* CLC register config */
+
+  union
+  {
+    struct
+    {
+      uint32_t module_disable             : 1;   /* Disables the module clock. 
*/
+      uint32_t                            : 2;
+      uint32_t disable_sleep_mode_control : 1;   /* Set it to true in order to 
disable the Sleep mode */
+      uint32_t                            : 28;
+    };
+    uint32_t clc;
+  };
+} vadc_global_config_t;
+
+/**
+ *   Structure to handle the VADC Groups registers configurations
+ */
+
+typedef struct XMC_VADC_GROUP_CONFIG
+{
+  /* GxICLASS0 register config */
+
+  vadc_input_class_config_t   class0;
+
+  /* GxICLASS1 register config */
+
+  vadc_input_class_config_t   class1;
+
+  /* GxBOUND register config */
+
+  union
+  {
+    struct
+    {
+      uint32_t boundary0    : 12;  /* Boundary value for results comparison */
+      uint32_t              : 4;
+      uint32_t boundary1    : 12;  /* Boundary value for results comparison */
+      uint32_t              : 4;
+    };
+    uint32_t g_bound;
+  };
+
+  /* GxARBCFG register config */
+
+  union
+  {
+    struct
+    {
+      uint32_t                            : 4;
+      uint32_t arbitration_round_length   : 2;  /* Number of arbiter slots to 
be considered */
+      uint32_t                            : 1;
+      uint32_t arbiter_mode               : 1;  /* Arbiter mode - Select 
either Continuous mode or Demand based. */
+      uint32_t                            : 24;
+    };
+    uint32_t g_arbcfg;
+  };
+} vadc_group_config_t;
+
+/**
+ *   Structure to handle the VADC Groups Channel registers configurations
+ */
+
+typedef struct XMC_VADC_CHANNEL_CONFIG
+{
+  /* GxCHCTRy register config */
+
+  union
+  {
+    struct
+    {
+      uint32_t input_class                : 2;  /* Input conversion class 
selection.
+                                                 * Uses vadc_channel_conv_t */
+      uint32_t                            : 2;
+      uint32_t lower_boundary_select      : 2;  /* Which boundary register 
serves as lower bound? */
+      uint32_t upper_boundary_select      : 2;  /* Which boundary register 
serves as upper bound? */
+      uint32_t event_gen_criteria         : 2;  /* When should an event be 
generated? */
+      uint32_t sync_conversion            : 1;  /* Enables synchronous 
conversion for the configured channel */
+      uint32_t alternate_reference        : 1;  /* Input reference voltage 
selection either VARef or CH-0. */
+      uint32_t                            : 4;
+      uint32_t result_reg_number          : 4;  /* Group result register 
number */
+      uint32_t use_global_result          : 1;  /* Use global result register 
for background request source channels */
+      uint32_t result_alignment           : 1;  /* Alignment of the results 
read in the result register. */
+      uint32_t                            : 6;
+      uint32_t broken_wire_detect_channel : 2;  /* Source to be used to charge 
the capacitor for BWD feature. */
+      uint32_t broken_wire_detect         : 1;  /* Configures extra phase 
before the capacitor is sampled. */
+    };
+    uint32_t chctr;
+  };
+
+  /* GxBFL register config */
+
+  union
+  {
+    struct
+    {
+      uint32_t                           : 8;
+#if (XMC_VADC_BOUNDARY_FLAG_SELECT == 1U)
+      uint32_t flag_output_condition_ch0 : 1;    /* Condition for which the 
boundary flag should change. */
+      uint32_t flag_output_condition_ch1 : 1;    /* Condition for which the 
boundary flag should change. */
+      uint32_t flag_output_condition_ch2 : 1;    /* Condition for which the 
boundary flag should change. */
+      uint32_t flag_output_condition_ch3 : 1;    /* Condition for which the 
boundary flag should change. */
+#else
+      uint32_t                           : 4;
+#endif
+      uint32_t                           : 4;
+#if (XMC_VADC_BOUNDARY_FLAG_SELECT == 1U)
+      uint32_t invert_boundary_flag_ch0  : 1;    /* Inverts boundary flag 
output. */
+      uint32_t invert_boundary_flag_ch1  : 1;    /* Inverts boundary flag 
output. */
+      uint32_t invert_boundary_flag_ch2  : 1;    /* Inverts boundary flag 
output. */
+      uint32_t invert_boundary_flag_ch3  : 1;    /* Inverts boundary flag 
output. */
+#else
+      uint32_t boundary_flag_output_ch0  : 1;    /* Enable the boundary flag 
output on the specific channel. */
+      uint32_t boundary_flag_output_ch1  : 1;    /* Enable the boundary flag 
output on the specific channel. */
+      uint32_t boundary_flag_output_ch2  : 1;    /* Enable the boundary flag 
output on the specific channel. */
+      uint32_t boundary_flag_output_ch3  : 1;    /* Enable the boundary flag 
output on the specific channel. */
+#endif
+      uint32_t                           : 12;
+    };
+    uint32_t bfl;
+  };
+
+#if (XMC_VADC_BOUNDARY_FLAG_SELECT == 1U)
+  /* GxBFLC register config */
+
+  union
+  {
+    struct
+    {
+      uint32_t boundary_flag_mode_ch0    : 4;     /* Specify the basic 
operation of boundary flag 0 */
+      uint32_t boundary_flag_mode_ch1    : 4;     /* Specify the basic 
operation of boundary flag 1 */
+      uint32_t boundary_flag_mode_ch2    : 4;     /* Specify the basic 
operation of boundary flag 2 */
+      uint32_t boundary_flag_mode_ch3    : 4;     /* Specify the basic 
operation of boundary flag 3 */
+      uint32_t                           : 16;
+    };
+    uint32_t bflc;
+  };
+
+#endif
+
+  bool    channel_priority;              /* Only non priority channels can be 
converted by Background Request Source */
+  int8_t  alias_channel;                 /* Specifies the channel which has to 
be aliased with CH0/CH1.
+                                          * Uses vadc_channel_alias_t */
+} vadc_channel_config_t;
+
+/**
+ *  Structure handle the VADC scan request source. It can be either Channel 
Scan (0) or Background Scan (2).
+ */
+
+typedef struct XMC_VADC_SCAN_CONFIG
+{
+  uint32_t conv_start_mode        : 2;   /* This field determines how scan 
request source would request for
+                                          * Uses vadc_startmode_t */
+  uint32_t req_src_priority       : 2;   /* Request source priority for the 
arbiter. */
+
+  /* BRSCTRL (Background Request) or GxASCTRL (Autoscan Source) register 
config */
+
+  union
+  {
+    struct
+    {
+#if(XMC_VADC_GROUP_SRCREG_AVAILABLE == (1U))
+      uint32_t src_specific_result_reg     : 4;     /* Use any one Group 
related result register as the destination
+                                                     * for all conversions 
results. To use the  individual result register
+                                                     * from each channel 
configuration, configure this field with 0x0 */
+#else
+      uint32_t                    : 4;
+#endif
+      uint32_t                    : 4;
+      uint32_t trigger_signal     : 4;   /* Select one of the 16 possibilities 
for trigger. */
+      uint32_t                    : 1;
+      uint32_t trigger_edge       : 2;   /* Edge selection for trigger signal. 
*/
+      uint32_t                    : 1;
+      uint32_t gate_signal        : 4;   /* Select one of the 16 possibilities 
for gating. */
+      uint32_t                    : 8;
+      uint32_t timer_mode         : 1;   /* Decides whether timer mode for 
equi-distant sampling shall be activated or not. */
+      uint32_t                    : 3;
+    };
+    uint32_t asctrl;
+  };
+
+  /* BRSMR (Background Request) or GxASMR (Autoscan Source) register config */
+
+  union
+  {
+    struct
+    {
+      uint32_t                    : 2;
+      uint32_t external_trigger   : 1;   /* Conversions be initiated by 
external hardware trigger */
+      uint32_t req_src_interrupt  : 1;   /* Request source event can be 
generated after a conversion sequence. */
+      uint32_t enable_auto_scan   : 1;   /* Enables the continuous conversion 
mode. */
+      uint32_t load_mode          : 1;   /* Selects load event mode. */
+      uint32_t                    : 26;
+    };
+    uint32_t asmr;
+  };
+} vadc_scan_config_t;
+
+typedef vadc_scan_config_t vadc_background_config_t;
+
+/* Defines the power mode that can be selected for each group. */
+
+typedef enum XMC_VADC_GROUP_POWERMODE
+{
+  XMC_VADC_GROUP_POWERMODE_OFF       = 0,   /* Group is powered down */
+  XMC_VADC_GROUP_POWERMODE_RESERVED1,       /* Reserved */
+  XMC_VADC_GROUP_POWERMODE_RESERVED2,       /* Reserved */
+  XMC_VADC_GROUP_POWERMODE_NORMAL    = 3    /* Group is powered up */
+} vadc_group_powermode_t;
+
+/* Defines the conversion input classes that can be selected for each channel. 
*/
+
+typedef enum XMC_VADC_CHANNEL_CONV
+{
+  XMC_VADC_CHANNEL_CONV_GROUP_CLASS0 = 0, /* Iclass0 specific to the group */
+  XMC_VADC_CHANNEL_CONV_GROUP_CLASS1,     /* IClass1 specific to the group */
+  XMC_VADC_CHANNEL_CONV_GLOBAL_CLASS0,    /* Iclass0 Module wide */
+  XMC_VADC_CHANNEL_CONV_GLOBAL_CLASS1     /* IClass1 Module wide */
+} vadc_channel_conv_t;
+
+/* Defines channel alias for channels 0 and 1. Other Channels can accept only 
XMC_VADC_CHANNEL_ALIAS_DISABLED. */
+
+typedef enum XMC_VADC_CHANNEL_ALIAS
+{
+  XMC_VADC_CHANNEL_ALIAS_DISABLED = -1,
+  XMC_VADC_CHANNEL_ALIAS_CH0 = 0,
+  XMC_VADC_CHANNEL_ALIAS_CH1 = 1,
+  XMC_VADC_CHANNEL_ALIAS_CH2 = 2,
+  XMC_VADC_CHANNEL_ALIAS_CH3 = 3,
+  XMC_VADC_CHANNEL_ALIAS_CH4 = 4,
+  XMC_VADC_CHANNEL_ALIAS_CH5 = 5,
+  XMC_VADC_CHANNEL_ALIAS_CH6 = 6,
+  XMC_VADC_CHANNEL_ALIAS_CH7 = 7
+} vadc_channel_alias_t;
+
+/* Defines the conversion mode. It defines the resolution of conversion. */
+
+typedef enum XMC_VADC_CONVMODE
+{
+  XMC_VADC_CONVMODE_12BIT       = 0,  /* Results of conversion are 12bits wide 
*/
+  XMC_VADC_CONVMODE_10BIT       = 1,  /* Results of conversion are 10bits wide 
*/
+  XMC_VADC_CONVMODE_8BIT        = 2,  /* Results of conversion are 8bits wide 
*/
+  XMC_VADC_CONVMODE_FASTCOMPARE = 5   /* Input signal compared with a preset 
range */
+} vadc_convmode_t;
+
+/* Defines the mode of operation of a channel, when an ongoing conversion gets 
interrupted in between. */
+
+typedef enum XMC_VADC_STARTMODE
+{
+  XMC_VADC_STARTMODE_WFS = 0, /* An ongoing conversion completes without 
interruption */
+  XMC_VADC_STARTMODE_CIR,     /* An ongoing conversion can be interrupted and 
resumed later */
+  XMC_VADC_STARTMODE_CNR      /* An ongoing conversion can be interrupted and 
never resumed, check GxASMR.RPTDIS */
+} vadc_startmode_t;
+
+/* Defines the condition for gating the conversion requests. It can be used to 
set the ENGT field
+ * of ASMR/BSMR/QMR register respectively for auto_scan/background_scan/queue 
request sources.
+ */
+
+typedef enum XMC_VADC_GATEMODE

Review Comment:
   useless enum name (everywhere) as you  typedef it directly



##########
arch/arm/src/xmc4/xmc4_vadc.c:
##########
@@ -0,0 +1,576 @@
+/****************************************************************************
+ * arch/arm/src/xmc4/xmc4_vadc.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ * May include some logic from sample code provided by Infineon:
+ *
+ * Copyright (C) 2011-2015 Infineon Technologies AG. All rights reserved.
+ *
+ * Infineon Technologies AG (Infineon) is supplying this software for use
+ * with Infineon's microcontrollers.  This file can be freely distributed
+ * within development tools that are supporting such microcontrollers.
+ *
+ * THIS SOFTWARE IS PROVIDED AS IS. NO WARRANTIES, WHETHER EXPRESS,
+ * IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS
+ * SOFTWARE. INFINEON SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR
+ * SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <errno.h>
+#include <assert.h>
+
+#include <arch/xmc4/chip.h>
+
+#include "arm_internal.h"
+#include "hardware/xmc4_scu.h"
+#include "xmc4_vadc.h"
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static vadc_group_t *const g_xmc_vadc_group_array[XMC_VADC_MAXIMUM_NUM_GROUPS] 
= {
+                                                                               
   (vadc_group_t *)VADC_G0,
+                                                                               
   (vadc_group_t *)VADC_G1,
+                                                                               
   (vadc_group_t *)VADC_G2,
+                                                                               
   (vadc_group_t *)VADC_G3
+                                                                               
   };
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: xmc4_vadc_global_enable
+ *
+ * Description:
+ *   Ungate the clock to the VADC module (if applicable) and bring the VADC
+ *   module out of reset state.
+ *   Called in xmc4_vadc_global_initialize.
+ *
+ ****************************************************************************/
+
+void xmc4_vadc_global_enable(void)
+{
+  #ifdef XMC4_SCU_GATING
+  /* Check if VADC is gated */
+
+  if ((getreg32(XMC4_SCU_CGATSTAT0) & SCU_CGAT0_VADC) == 1)
+    {
+      /* Disable VADC gating */
+
+      putreg32(SCU_CGAT0_VADC, XMC4_SCU_CGATCLR0);
+    }
+
+  /* Set bit in PRCLR0 to de-assert VADC peripheral reset */
+
+  putreg32(SCU_PR0_VADCRS, XMC4_SCU_PRCLR0);
+  #else
+
+  /* Set bit in PRCLR0 to de-assert VADC peripheral reset */
+
+  putreg32(SCU_PR0_VADCRS, XMC4_SCU_PRCLR0);
+  #endif
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_global_disable
+ *
+ * Description:
+ *   Gate the clock to the VADC module (if applicable) and put the VADC
+ *   module into the reset state
+ *
+ ****************************************************************************/
+
+void xmc4_vadc_global_disable(void)
+{
+  /* Set bit in PRSET0 to assert VADC peripheral reset */
+
+  putreg32(SCU_PR0_VADCRS, XMC4_SCU_PRSET0);
+
+  #ifdef XMC4_SCU_GATING
+  /* Check if VADC is ungated */
+
+  if ((getreg32(XMC4_SCU_CGATSTAT0) & SCU_CGAT0_VADC) == 0)
+    {
+      /* Enable VADC gating */
+
+      putreg32(SCU_CGAT0_VADC, XMC4_SCU_CGATSET0);
+    }
+  #endif
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_global_initialize
+ *
+ * Description:
+ *   Initializes the VADC global module with the given configuration structure.
+ *   It initializes global input classes, boundaries , result resources.
+ *   Configures GLOBICLASS,GLOBBOUND,GLOBRCR registers.
+ *   It also configures the global analog and digital clock dividers
+ *   by setting GLOBCFG register.
+ *
+ ****************************************************************************/
+
+void xmc4_vadc_global_initialize(const vadc_global_config_t *config)
+{
+  /* Enable the VADC module */
+
+  xmc4_vadc_global_enable();
+
+  VADC->CLC = (uint32_t)(config->clc);
+
+  /* Clock configuration, use DIVWC (write control) to write register */
+
+  VADC->GLOBCFG = (uint32_t)(config->globcfg | 
(uint32_t)(VADC_GLOBCFG_DIVWC_MASK));
+
+  /* Global input class 0 configuration */
+
+  VADC->GLOBICLASS[0] = (uint32_t)(config->class0.iclass);
+
+  /* Global input class 1 configuration */
+
+  VADC->GLOBICLASS[1] = (uint32_t)(config->class1.iclass);
+
+  /* Global result generation configuration */
+
+  VADC->GLOBRCR = (uint32_t)(config->globrcr);
+
+  /* Set global boundaries values */
+
+  VADC->GLOBBOUND = (uint32_t)(config->globbound);
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_group_initialize
+ *
+ * Description:
+ *   Initializes the VADC group module with the associated
+ *   configuration structure pointed by config. It initializes group conversion
+ *   class, arbiter configuration, boundary configuration by setting
+ *   GxICLASS,GxARBCFG,GxBOUND, registers.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; A negated errno value is returned to
+ *   indicate the nature of any failure.
+ *
+ ****************************************************************************/
+
+int xmc4_vadc_group_initialize(vadc_group_t *const group_ptr, const 
vadc_group_config_t *config)
+{
+  if (!xmc_vadc_check_group_ptr(group_ptr))
+    {
+      return -EINVAL;
+    }
+
+  /* Configures the group-specific input classes,
+   * each channel is assigned to a class in GxCHCTRy
+   */
+
+  group_ptr->ICLASS[0] = config->class0.iclass;
+  group_ptr->ICLASS[1] = config->class1.iclass;
+
+  /* Configures the group arbitration behavior */
+
+  group_ptr->ARBCFG = config->g_arbcfg;
+
+  /* Configures the group-specific boundaries */
+
+  group_ptr->BOUND = config->g_bound;
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_group_set_powermode
+ *
+ * Description:
+ *   Configures the power mode of a VADC group. For a VADC group to
+ *   actually convert an analog signal, its analog converter must be turned on.
+ *   Configure the register bit field GxARBCFG.ANONC
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; A negated errno value is returned to
+ *   indicate the nature of any failure.
+ *
+ ****************************************************************************/
+
+int xmc4_vadc_group_set_powermode(vadc_group_t *const group_ptr, const 
vadc_group_powermode_t power_mode)
+{
+  if (!xmc_vadc_check_group_ptr(group_ptr) || (power_mode > 
XMC_VADC_GROUP_POWERMODE_NORMAL))
+    {
+      return -EINVAL;
+    }
+
+  uint32_t arbcfg = group_ptr->ARBCFG;
+
+  arbcfg &= ~((uint32_t)VADC_GxARBCFG_ANONC_MASK);
+  arbcfg |= (uint32_t)power_mode;
+
+  group_ptr->ARBCFG = arbcfg;
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_global_start_calibration
+ *
+ * Description:
+ *   Start the calibration process and loops until all active groups
+ *   finish calibration. Call xmc4_vadc_global_enable and
+ *   xmc4_vadc_global_initialize before calibration.
+ *   Configures the register bit field GLOBCFG.SUCAL.
+ *
+ ****************************************************************************/
+
+void xmc4_vadc_global_start_calibration(void)
+{
+  vadc_group_t * group_ptr;
+
+  /* Start Calibration */
+
+  VADC->GLOBCFG |= (uint32_t) VADC_GLOBCFG_SUCAL_MASK;
+
+  /* Loop until all groups to finish calibration */
+
+  for (int i = 0; i < XMC_VADC_MAXIMUM_NUM_GROUPS; i++)
+    {
+      group_ptr = g_xmc_vadc_group_array[i];
+
+      /* Check if group is active */
+
+      if ((group_ptr->ARBCFG) & (uint32_t)(VADC_GxARBCFG_ANONS_MASK))
+        {
+          /* Loop until it finish calibration */
+
+          while ((group_ptr->ARBCFG) & (uint32_t)VADC_GxARBCFG_CAL_MASK)
+            {
+              /* NOP */
+            }
+      }
+    }
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_group_background_enable_arbitrationslot
+ *
+ * Description:
+ *   Enables arbitration slot of the Background request source to
+ *   participate in the arbitration round. Even if a load event occurs the
+ *   Background channel can only be converted when the arbiter comes to the
+ *   Background slot. Thus this must be enabled if any conversion need to take
+ *   place.
+ *   Configure the register bit field GxARBPR.ASEN2.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; A negated errno value is returned to
+ *   indicate the nature of any failure.
+ *
+ ****************************************************************************/
+
+int xmc4_vadc_group_background_enable_arbitrationslot(vadc_group_t *const 
group_ptr)
+{
+  if (!xmc_vadc_check_group_ptr(group_ptr))
+    {
+      return -EINVAL;
+    }
+
+  group_ptr->ARBPR |= (uint32_t)VADC_GxARBPR_ASEN2_MASK;
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_group_background_disable_arbitrationslot
+ *
+ * Description:
+ *   Disables arbitration slot of the Background request source to
+ *   participate in the arbitration round. Even if a load event occurs the
+ *   Background channel can only be converted when the arbiter comes to the
+ *   Background slot. Thus this must be enabled if any conversion need to take
+ *   place.
+ *   Configure the register bit field GxARBPR.ASEN2.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; A negated errno value is returned to
+ *   indicate the nature of any failure.
+ *
+ ****************************************************************************/
+
+int xmc4_vadc_group_background_disable_arbitrationslot(vadc_group_t *const 
group_ptr)
+{
+  if (!xmc_vadc_check_group_ptr(group_ptr))
+    {
+      return -EINVAL;
+    }
+
+  group_ptr->ARBPR &= ~((uint32_t)VADC_GxARBPR_ASEN2_MASK);
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_global_background_initialize
+ *
+ * Description:
+ *   Initializes the Background scan functional block. The BACKGROUND
+ *   SCAN request source functional block converts channels of all VADC groups
+ *   that have not been assigned as a priority channel (priority channels can 
be
+ *   converted only by queue and scan). Related arbitration slot must be
+ *   disabled to configure background request, then re-enabled.
+ *
+ ****************************************************************************/
+
+void xmc4_vadc_global_background_initialize(const vadc_background_config_t 
*config)
+{
+  uint32_t reg;
+  uint32_t conv_start_mask;
+
+  /* Disable background request source to change its parameters */
+
+  for (int i = 0; i < XMC_VADC_MAXIMUM_NUM_GROUPS; i++)
+    {
+      xmc4_vadc_group_background_disable_arbitrationslot((vadc_group_t 
*)g_xmc_vadc_group_array[i]);
+    }
+
+  /* Set start mode */
+
+  conv_start_mask = (uint32_t) 0;
+  if (XMC_VADC_STARTMODE_WFS != (vadc_startmode_t)config->conv_start_mode)
+    {
+      conv_start_mask = (uint32_t)VADC_GxARBPR_CSM2_MASK;
+    }
+
+  /* Configures GxARBPR register for each group */
+
+  for (int i = 0; i < XMC_VADC_MAXIMUM_NUM_GROUPS; i++)
+    {
+      reg = g_xmc_vadc_group_array[i]->ARBPR;
+
+      /* Program the priority of the request source : Background Scan is 
source 2 */
+
+      reg &= ~(uint32_t)(VADC_GxARBPR_PRIO2_MASK);
+      reg |= (uint32_t)((uint32_t)config->req_src_priority << 
VADC_GxARBPR_PRIO2_SHIFT);
+
+      /* Program the start mode */
+
+      reg |= conv_start_mask;
+
+      g_xmc_vadc_group_array[i]->ARBPR = reg;
+    }
+
+  /* program Background Request Source Control register, use XT and GT write 
control bitfields */
+
+  VADC->BRSCTRL = (uint32_t)(config->asctrl | (uint32_t)VADC_BRSCTRL_XTWC_MASK 
| (uint32_t)VADC_BRSCTRL_GTWC_MASK);
+
+  /* program Background Request Source Mode register */
+
+  VADC->BRSMR = (uint32_t)((config->asmr) | 
(uint32_t)((uint32_t)XMC_VADC_GATEMODE_IGNORE << VADC_BRSMR_ENGT_SHIFT));
+  if (XMC_VADC_STARTMODE_CNR == (vadc_startmode_t)(config->conv_start_mode))
+    {
+      VADC->BRSMR |= (uint32_t)VADC_BRSMR_RPTDIS_MASK;
+    }
+
+  /* Re enable request source */
+
+  for (int i = 0; i < XMC_VADC_MAXIMUM_NUM_GROUPS; i++)
+    {
+      xmc4_vadc_group_background_enable_arbitrationslot((vadc_group_t 
*)g_xmc_vadc_group_array[i]);
+    }
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_group_channel_initialize
+ *
+ * Description:
+ *   Initializes the ADC channel for conversion. Must be called after
+ *   request source initialization for each channel to enable their conversion.
+ *   Configures registers GxCHCTRy and boundary flag GxBFL, GxBFLC and GxCHASS.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; A negated errno value is returned to
+ *   indicate the nature of any failure.
+ *
+ ****************************************************************************/
+
+int xmc4_vadc_group_channel_initialize(vadc_group_t *const group_ptr, const 
uint32_t ch_num,
+                                        const vadc_channel_config_t *config)
+{
+  if (!xmc_vadc_check_group_ptr(group_ptr) || (ch_num > 
XMC_VADC_NUM_CHANNELS_PER_GROUP))
+    {
+      return -EINVAL;
+    }
+
+  uint32_t prio  = (uint32_t)config->channel_priority;
+
+  /* Set channel priority, channel_priority must be 0 for background channel */
+
+  uint32_t ch_assign  = group_ptr->CHASS;
+  ch_assign &= ~((uint32_t)((uint32_t)1 << ch_num));
+  ch_assign |= (uint32_t)(prio << ch_num);
+  group_ptr->CHASS = ch_assign;
+
+  /* Alias channel, can replace CH0 and CH1 with another channel number. */
+
+  if (config->alias_channel >= (int32_t)0)
+    {
+      uint32_t mask = (uint32_t)0;
+      if ((uint32_t)1 == ch_num)
+        {
+          mask = VADC_GxALIAS_ALIAS1_SHIFT;
+          group_ptr->ALIAS &= ~(uint32_t)(VADC_GxALIAS_ALIAS1_MASK);
+        }
+      else if ((uint32_t)0 == ch_num)
+        {
+          mask = VADC_GxALIAS_ALIAS0_SHIFT;
+          group_ptr->ALIAS &= ~(uint32_t)(VADC_GxALIAS_ALIAS0_MASK);
+        }
+
+      group_ptr->ALIAS |= (uint32_t)(config->alias_channel << mask);
+    }
+
+  /* Set channel boundaries flag */
+
+  group_ptr->BFL |= config->bfl;
+  #if (XMC_VADC_BOUNDARY_FLAG_SELECT == 1U)
+    group_ptr->BFLC |= config->bflc;
+  #endif
+
+  /* Program the CHCTR register */
+
+  group_ptr->CHCTR[ch_num] = config->chctr;
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_global_background_add_channel_to_sequence
+ *
+ * Description:
+ *   Adds a channel to the background scan sequence. The pending
+ *   register are updated only after a new load event occured.
+ *   Configures the register bit fields of BRSSEL.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; A negated errno value is returned to
+ *   indicate the nature of any failure.
+ *
+ ****************************************************************************/
+
+int xmc4_vadc_global_background_add_channel_to_sequence(const uint32_t 
grp_num, const uint32_t ch_num)
+{
+  if ((grp_num > XMC_VADC_MAXIMUM_NUM_GROUPS) || (ch_num > 
XMC_VADC_NUM_CHANNELS_PER_GROUP))
+    {
+      return -EINVAL;
+    }
+
+  VADC->BRSSEL[grp_num] |= (uint32_t)((uint32_t)1 << ch_num);
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_global_background_enable_autoscan
+ *
+ * Description:
+ *   Enables continuous conversion mode (autoscan). Once all channels
+ *   belonging to a Background request source have been converted, a new  load
+ *   event occurs.
+ *   Configures the register bit field BRSMR.SCAN.
+ *
+ ****************************************************************************/
+
+void xmc4_vadc_global_background_enable_autoscan(void)
+{
+  VADC->BRSMR |= (uint32_t)VADC_BRSMR_SCAN_MASK;
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_global_background_start_conversion
+ *
+ * Description:
+ *   Generates conversion request (Software initiated conversion).
+ *   The background scan must been init.
+ *   Configures the register bit field BRSMR.LDEV.
+ *
+ ****************************************************************************/
+
+void xmc4_vadc_global_background_start_conversion(void)
+{
+  VADC->BRSMR |= (uint32_t)VADC_BRSMR_LDEV_MASK;
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_group_get_result
+ *
+ * Description:
+ *   Returns the result of the conversion in the given group result register.
+ *   Get the register bit field GxRES.RESULT.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; A negated errno value is returned to
+ *   indicate the nature of any failure.
+ *
+ ****************************************************************************/
+
+int xmc4_vadc_group_get_result(vadc_group_t *const group_ptr, const uint32_t 
res_reg, uint16_t *result_ptr)
+{
+  if (!xmc_vadc_check_group_ptr(group_ptr) || (res_reg > 
XMC_VADC_NUM_RESULT_REGISTERS))
+    {
+      return -EINVAL;
+    }
+
+  *result_ptr = ((uint16_t)group_ptr->RES[res_reg]);
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: xmc4_vadc_group_channel_get_result
+ *
+ * Description:
+ *   Returns the result of the conversion of the given group channel.
+ *   Get the register bit field GxRES.RESULT.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; A negated errno value is returned to
+ *   indicate the nature of any failure.
+ *
+ ****************************************************************************/
+
+int xmc4_vadc_group_get_channel_result(vadc_group_t *const group_ptr, const 
uint32_t ch_num, uint16_t *result_ptr)
+{
+  if (!xmc_vadc_check_group_ptr(group_ptr) || (ch_num > 
XMC_VADC_NUM_CHANNELS_PER_GROUP))
+    {
+      return -EINVAL;
+    }
+
+  uint8_t resreg = (uint8_t)((group_ptr->CHCTR[ch_num] & 
(uint32_t)VADC_GxCHCTR_RESREG_MASK) >> VADC_GxCHCTR_RESREG_SHIFT);

Review Comment:
   This seems strange, you shift back the mask ? 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to