mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Revision:
324:406fd2029f23
Parent:
149:1fb5f62b92bd
--- a/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_KPSDK_CODE/hal/adc/fsl_adc_hal.c	Mon Sep 15 15:30:06 2014 +0100
+++ b/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_KPSDK_CODE/hal/adc/fsl_adc_hal.c	Thu Sep 18 14:00:17 2014 +0100
@@ -1,114 +1,152 @@
 /*
-* Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without modification,
-* are permitted provided that the following conditions are met:
-*
-* o Redistributions of source code must retain the above copyright notice, this list
-*   of conditions and the following disclaimer.
-*
-* o Redistributions in binary form must reproduce the above copyright notice, this
-*   list of conditions and the following disclaimer in the documentation and/or
-*   other materials provided with the distribution.
-*
-* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
-*   contributors may be used to endorse or promote products derived from this
-*   software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
-* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ *   of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ *   list of conditions and the following disclaimer in the documentation and/or
+ *   other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ *   contributors may be used to endorse or promote products derived from this
+ *   software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
 
 #include "fsl_adc_hal.h"
-#include "fsl_device_registers.h"
-#include <assert.h>
 
-/*******************************************************************************
- * Code
- ******************************************************************************/
-
-/*FUNCTION**********************************************************************
+/*FUNCTION*********************************************************************
+ *
+ * Function Name : ADC_HAL_Init
+ * Description   :Reset all the registers into a known state for ADC
+ * module. This known state is the default value indicated by the Reference
+ * manual. It is strongly recommended to call this API before any operations
+ * when initializing the ADC module. Note registers for calibration would not
+ * be cleared in this function.
  *
- * Function Name : adc_hal_start_calibration 
- * Description   : This function is to clear the calibrate flag bit and then set
- * the enable bit to start the calibration.
- * 
- *END**************************************************************************/
-adc_status_t adc_hal_start_calibration(uint32_t instance)
+ *END*************************************************************************/
+void ADC_HAL_Init(uint32_t baseAddr)
 {
-    assert(instance < HW_ADC_INSTANCE_COUNT);
-    
-    /* Execute the calibration */
-    HW_ADC_SC3_SET(instance, BM_ADC_SC3_CALF); /* Clear the calibration's flag */
-    BW_ADC_SC3_CAL(instance, 1U);  /* Enable the calibration */
-    while (!adc_hal_is_conversion_completed(instance, 0U)) 
-    {} /* Wait conversion is competed */
-    if (adc_hal_is_calibration_fail(instance))
-    {
-        return kStatus_ADC_Failed; /* Check for calibration fail error and return */
-    }
-    return kStatus_ADC_Success;
+    HW_ADC_CFG1_WR(baseAddr, 0U);
+    HW_ADC_CFG2_WR(baseAddr, 0U);
+    HW_ADC_CV1_WR(baseAddr, 0U);
+    HW_ADC_CV2_WR(baseAddr, 0U);
+    HW_ADC_SC2_WR(baseAddr, 0U);
+    HW_ADC_SC3_WR(baseAddr, 0U);
+#if FSL_FEATURE_ADC_HAS_PGA
+    HW_ADC_PGA_WR(baseAddr, 0U);
+#endif /* FSL_FEATURE_ADC_HAS_PGA */
 }
 
-/*FUNCTION**********************************************************************
+/*FUNCTION*********************************************************************
+ *
+ * Function Name : ADC_HAL_SetHwCmpMode
+ * Description   :Set the asserted compare range when enabling hardware
+ * compare function. About the selection of range mode, see to the description
+ * for "adc_hw_cmp_range_mode_t".
  *
- * Function Name : adc_hal_get_calibration_PG 
- * Description   : This function is to get the CLP0 - CLP4 and CLPS and 
- * accumulate them, and then return the value that can be set to PG directly. 
- * 
- *END**************************************************************************/
-uint32_t adc_hal_get_calibration_PG(uint32_t instance)
+ *END*************************************************************************/
+void ADC_HAL_SetHwCmpMode(uint32_t baseAddr, adc_hw_cmp_range_mode_t mode)
 {
-    assert(instance < HW_ADC_INSTANCE_COUNT);
-    uint32_t cal_var;
-    
+    switch (mode)
+    {
+    case kAdcHwCmpRangeModeOf1:
+        ADC_HAL_SetHwCmpGreaterCmd(baseAddr, false);
+        ADC_HAL_SetHwCmpRangeCmd(baseAddr, false);
+        break;
+    case kAdcHwCmpRangeModeOf2:
+        ADC_HAL_SetHwCmpGreaterCmd(baseAddr, true);
+        ADC_HAL_SetHwCmpRangeCmd(baseAddr, false);
+        break;
+    case kAdcHwCmpRangeModeOf3:
+        ADC_HAL_SetHwCmpGreaterCmd(baseAddr, false);
+        ADC_HAL_SetHwCmpRangeCmd(baseAddr, true);
+        break;
+    case kAdcHwCmpRangeModeOf4:
+        ADC_HAL_SetHwCmpGreaterCmd(baseAddr, true);
+        ADC_HAL_SetHwCmpRangeCmd(baseAddr, true);
+        break;
+    default:
+        break;
+    }
+}
+
+#if FSL_FEATURE_ADC_HAS_CALIBRATION
+
+/*FUNCTION*********************************************************************
+ *
+ * Function Name : ADC_HAL_GetAutoPlusSideGainValue 
+ * Description   :  Get the values of CLP0 - CLP4 and CLPS internally,
+ * accumulate them, and return the value that can be used to be set in PG
+ * register directly. Note that this API should be called after the process of
+ * auto calibration has been done.
+ *
+ *END*************************************************************************/
+uint16_t ADC_HAL_GetAutoPlusSideGainValue(uint32_t baseAddr)
+{
+    uint16_t cal_var;
+
     /* Calculate plus-side calibration */
     cal_var = 0U;
-    cal_var += BR_ADC_CLP0_CLP0(instance);
-    cal_var += BR_ADC_CLP1_CLP1(instance);
-    cal_var += BR_ADC_CLP2_CLP2(instance);
-    cal_var += BR_ADC_CLP3_CLP3(instance);
-    cal_var += BR_ADC_CLP4_CLP4(instance);
-    cal_var += BR_ADC_CLPS_CLPS(instance);
+    cal_var += BR_ADC_CLP0_CLP0(baseAddr);
+    cal_var += BR_ADC_CLP1_CLP1(baseAddr);
+    cal_var += BR_ADC_CLP2_CLP2(baseAddr);
+    cal_var += BR_ADC_CLP3_CLP3(baseAddr);
+    cal_var += BR_ADC_CLP4_CLP4(baseAddr);
+    cal_var += BR_ADC_CLPS_CLPS(baseAddr);
     cal_var = 0x8000U | (cal_var>>1U);
-    
+
     return cal_var;
 }
 
-/*FUNCTION**********************************************************************
+#if FSL_FEATURE_ADC_HAS_DIFF_MODE
+
+/*FUNCTION*********************************************************************
  *
- * Function Name : adc_hal_get_calibration_MG 
- * Description   : This function is to get the CLM0 - CLM4 and CLMS and 
- * accumulate them, and then return the value that can be set to MG directly. 
- * 
- *END**************************************************************************/
-uint32_t adc_hal_get_calibration_MG(uint32_t instance)
+ * Function Name : ADC_HAL_GetAutoMinusSideGainValue 
+ * Description   : Get the values of CLM0 - CLM4 and CLMS internally,
+ * accumulate them, and return the value that can be used to be set in MG
+ * register directly. Note that this API should be called after the process of
+ * auto calibration has been done.
+ *
+ *END*************************************************************************/
+uint16_t ADC_HAL_GetAutoMinusSideGainValue(uint32_t baseAddr)
 {
-    assert(instance < HW_ADC_INSTANCE_COUNT);
-    uint32_t cal_var;
-    
+    uint16_t cal_var;
+
     /* Calculate minus-side calibration */
     cal_var = 0U;
-    cal_var += BR_ADC_CLM0_CLM0(instance);
-    cal_var += BR_ADC_CLM1_CLM1(instance);
-    cal_var += BR_ADC_CLM2_CLM2(instance);
-    cal_var += BR_ADC_CLM3_CLM3(instance);
-    cal_var += BR_ADC_CLM4_CLM4(instance);
-    cal_var += BR_ADC_CLMS_CLMS(instance);
+    cal_var += BR_ADC_CLM0_CLM0(baseAddr);
+    cal_var += BR_ADC_CLM1_CLM1(baseAddr);
+    cal_var += BR_ADC_CLM2_CLM2(baseAddr);
+    cal_var += BR_ADC_CLM3_CLM3(baseAddr);
+    cal_var += BR_ADC_CLM4_CLM4(baseAddr);
+    cal_var += BR_ADC_CLMS_CLMS(baseAddr);
     cal_var = 0x8000U | (cal_var>>1U);
-    
+
     return cal_var;
 }
 
-/*******************************************************************************
+#endif /* FSL_FEATURE_ADC_HAS_DIFF_MODE */
+
+#endif /* FSL_FEATURE_ADC_HAS_CALIBRATION */
+
+/******************************************************************************
  * EOF
- ******************************************************************************/
+ *****************************************************************************/
+