ADC_MEASUREMENT: ADC_MEASUREMENT.c Source File

ADC MEASUREMENT

ADC_MEASUREMENT
ADC_MEASUREMENT.c
Go to the documentation of this file.
00001 
00089 /***********************************************************************************************************************
00090  * HEADER FILES
00091  **********************************************************************************************************************/
00092 #include "adc_measurement.h"
00093 
00094 /***********************************************************************************************************************
00095  * MACROS
00096  **********************************************************************************************************************/
00097 
00098 /***********************************************************************************************************************
00099  * LOCAL DATA
00100  **********************************************************************************************************************/
00101 
00102 /***********************************************************************************************************************
00103  * LOCAL ROUTINES
00104  **********************************************************************************************************************/
00105 
00106 /**********************************************************************************************************************
00107  * API IMPLEMENTATION
00108  **********************************************************************************************************************/
00109 
00110 /*This function returns the version of the ADC_MEASUREMENT App*/
00111 DAVE_APP_VERSION_t ADC_MEASUREMENT_GetAppVersion(void)
00112 {
00113   DAVE_APP_VERSION_t version;
00114 
00115   version.major = (uint8_t) ADC_MEASUREMENT_MAJOR_VERSION;
00116   version.minor = (uint8_t) ADC_MEASUREMENT_MINOR_VERSION;
00117   version.patch = (uint8_t) ADC_MEASUREMENT_PATCH_VERSION;
00118 
00119   return version;
00120 }
00121 
00122 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
00123 /* Initialization routine to call ADC LLD API's */
00124 ADC_MEASUREMENT_STATUS_t ADC_MEASUREMENT_Init(ADC_MEASUREMENT_t *const handle_ptr)
00125 {
00126   const ADC_MEASUREMENT_CHANNEL_t *indexed;
00127   uint8_t j;
00128   ADC_MEASUREMENT_STATUS_t status;
00129 
00130   XMC_ASSERT("ADC_MEASUREMENT_Init:Invalid handle_ptr", (handle_ptr != NULL))
00131 
00132   if (ADC_MEASUREMENT_STATUS_UNINITIALIZED == handle_ptr->init_state)
00133   {
00134     /* Call the function to initialise Clock and ADC global functional units*/
00135     status = (ADC_MEASUREMENT_STATUS_t) GLOBAL_ADC_Init(handle_ptr->global_handle);
00136   
00137     /*Initialize the Global Conversion class 0*/
00138     XMC_VADC_GLOBAL_InputClassInit(handle_ptr->global_handle->module_ptr,*handle_ptr->iclass_config_handle,
00139                                               XMC_VADC_GROUP_CONV_STD,ADC_MEASUREMENT_ICLASS_NUM);
00140 #if (UC_SERIES == XMC11)
00141     /*Initialize the Global Conversion class 1*/
00142     XMC_VADC_GLOBAL_InputClassInit(handle_ptr->global_handle->module_ptr,*handle_ptr->iclass_config_handle,
00143                                               XMC_VADC_GROUP_CONV_STD,ADC_MEASUREMENT_ICLASS_NUM_XMC11);
00144 #endif
00145   
00146     /* Initialize the Background Scan hardware */
00147     XMC_VADC_GLOBAL_BackgroundInit(handle_ptr->global_handle->module_ptr, handle_ptr->backgnd_config_handle);
00148   
00149 #if (XMC_VADC_GROUP_AVAILABLE == 0U)
00150     /* Initialize the global result register */
00151     XMC_VADC_GLOBAL_ResultInit(handle_ptr->global_handle->module_ptr,handle_ptr->array->res_handle);
00152 #endif
00153 
00154     for (j = (uint8_t)0; j < (uint8_t)ADC_MEASUREMENT_MAXCHANNELS; j++)
00155     {
00156       indexed = handle_ptr->array->channel_array[j];
00157 #if (XMC_VADC_GROUP_AVAILABLE == 1U)
00158       /* Initialize for configured channels*/
00159       XMC_VADC_GROUP_ChannelInit(indexed->group_handle,(uint32_t)indexed->ch_num, indexed->ch_handle);
00160   
00161       /* Initialize for configured result registers */
00162       XMC_VADC_GROUP_ResultInit(indexed->group_handle, (uint32_t)indexed->ch_handle->result_reg_number,
00163                                 indexed->res_handle);
00164 #endif
00165       /* Add all channels into the Background Request Source Channel Select Register */
00166       XMC_VADC_GLOBAL_BackgroundAddChannelToSequence(handle_ptr->global_handle->module_ptr,
00167                                                      (uint32_t)indexed->group_index, (uint32_t)indexed->ch_num);
00168 
00169 #ifdef ADC_MEASUREMENT_ANALOG_IO_USED
00170       /* ANALOG_IO initialization for the channel*/
00171       if(indexed->analog_io_config != NULL)
00172       {
00173         status |= (ADC_MEASUREMENT_STATUS_t) ANALOG_IO_Init(indexed->analog_io_config);
00174       }
00175 #endif
00176     }
00177 #if(UC_SERIES != XMC11)
00178     if ((handle_ptr->backgnd_config_handle->req_src_interrupt) && (handle_ptr->req_src_intr_handle != NULL ))
00179     {
00180 #if (UC_FAMILY == XMC1)
00181       NVIC_SetPriority((IRQn_Type)handle_ptr->req_src_intr_handle->node_id,
00182                         handle_ptr->req_src_intr_handle->priority);
00183 #else
00184       NVIC_SetPriority((IRQn_Type)handle_ptr->req_src_intr_handle->node_id,
00185                         NVIC_EncodePriority(NVIC_GetPriorityGrouping(),
00186                         handle_ptr->req_src_intr_handle->priority, handle_ptr->req_src_intr_handle->sub_priority));
00187 #endif
00188       /* Connect background Request Source Event to NVIC node */
00189       XMC_VADC_GLOBAL_BackgroundSetReqSrcEventInterruptNode(handle_ptr->global_handle->module_ptr,
00190                                                          (XMC_VADC_SR_t) handle_ptr->srv_req_node);
00191     
00192       /* Enable Background Scan Request source IRQ */
00193       NVIC_EnableIRQ((IRQn_Type)handle_ptr->req_src_intr_handle->node_id);
00194 #ifdef ADC_MEASUREMENT_NON_DEFAULT_IRQ_SOURCE_SELECTED
00195   XMC_SCU_SetInterruptControl(handle_ptr->req_src_intr_handle->node_id,
00196                               ((handle_ptr->req_src_intr_handle->node_id << 8) | handle_ptr->req_src_intr_handle->irqctrl));
00197 #endif
00198     }
00199 #else /* Selected device is XMC11*/
00200     XMC_VADC_GLOBAL_SetResultEventInterruptNode(handle_ptr->global_handle->module_ptr, handle_ptr->srv_req_node );
00201 #ifdef ADC_MEASUREMENT_CPU_1X /* End of single measurement is enabled*/
00202     NVIC_SetPriority((IRQn_Type)handle_ptr->result_intr_handle->node_id,
00203                             handle_ptr->result_intr_handle->priority);
00204 
00205     /* Enable Background Scan Request source IRQ */
00206     NVIC_EnableIRQ((IRQn_Type)handle_ptr->result_intr_handle->node_id);
00207 #endif
00208 #endif
00209     /* Mux Configuration is done*/
00210     if (handle_ptr->mux_config != NULL)
00211     {
00212         (handle_ptr->mux_config)();
00213     }
00214   
00215     if (handle_ptr->start_conversion != (bool)false)
00216     {
00217       /* Start conversion manually using load event trigger*/
00218       XMC_VADC_GLOBAL_BackgroundTriggerConversion(handle_ptr->global_handle->module_ptr);
00219     }
00220     handle_ptr->init_state = status;
00221   }
00222   return (handle_ptr->init_state);
00223 }
00224 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
00225 
00226 /* This API will Software trigger ADC Background request source and starts conversion*/
00227 void ADC_MEASUREMENT_StartConversion(ADC_MEASUREMENT_t *const handle_ptr)
00228 {
00229   XMC_ASSERT("ADC_MEASUREMENT_Start:Invalid handle_ptr", (handle_ptr != NULL))
00230 
00231   /* Generate a load event to start background request source conversion*/
00232   XMC_VADC_GLOBAL_BackgroundTriggerConversion(handle_ptr->global_handle->module_ptr);
00233 }
00234 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
00235 #if(XMC_VADC_GROUP_AVAILABLE == 1U)
00236 /* This API will get the result of a conversion for a specific channel*/
00237 XMC_VADC_RESULT_SIZE_t ADC_MEASUREMENT_GetResult(ADC_MEASUREMENT_CHANNEL_t *const handle_ptr)
00238 {
00239   XMC_VADC_RESULT_SIZE_t result;
00240 
00241   XMC_ASSERT("ADC_MEASUREMENT_GetResult:Invalid handle_ptr", (handle_ptr != NULL))
00242 
00243   result = XMC_VADC_GROUP_GetResult(handle_ptr->group_handle, handle_ptr->ch_handle->result_reg_number);
00244 
00245   return (result);
00246 }
00247 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
00248 
00249 /* This API will get the result of a conversion for a specific channel. It will return the complete result register*/
00250 uint32_t ADC_MEASUREMENT_GetDetailedResult(ADC_MEASUREMENT_CHANNEL_t *const handle_ptr)
00251 {
00252   uint32_t result;
00253 
00254   XMC_ASSERT("ADC_MEASUREMENT_GetDetailedResult:Invalid handle_ptr", (handle_ptr != NULL))
00255 
00256   result = XMC_VADC_GROUP_GetDetailedResult(handle_ptr->group_handle, handle_ptr->ch_handle->result_reg_number);
00257 
00258   return (result);
00259 }
00260 
00261 #else /* Applicable for XMC1100 devices */
00262 /* This API will get the result of the conversion from the global result
00263  *
00264  * This API has been deprecated. Use ADC_MEASUREMENT_GetGlobalResult() to get the global result.
00265  * */
00266 XMC_VADC_RESULT_SIZE_t ADC_MEASUREMENT_GetResult(ADC_MEASUREMENT_t *const handle_ptr)
00267 {
00268   XMC_VADC_RESULT_SIZE_t result;
00269 
00270   XMC_ASSERT("ADC_MEASUREMENT_GetResult:Invalid handle_ptr", (handle_ptr != NULL))
00271 
00272   XMC_UNUSED_ARG(handle_ptr);
00273 
00274   result = ADC_MEASUREMENT_GetGlobalResult();
00275   return (result);
00276 }
00277 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
00278 
00279 /* This API will get the result of a conversion for a specific channel. It will return the global result register
00280  *
00281  * This API has been deprecated. Use ADC_MEASUREMENT_GetGlobalDetailedResult() to get the global result.
00282  * */
00283 uint32_t ADC_MEASUREMENT_GetDetailedResult(ADC_MEASUREMENT_t *const handle_ptr)
00284 {
00285   uint32_t result;
00286 
00287   XMC_ASSERT("ADC_MEASUREMENT_GetDetailedResult:Invalid handle_ptr", (handle_ptr != NULL))
00288 
00289   XMC_UNUSED_ARG(handle_ptr);
00290 
00291   /* Needed only for XMC1100 devices to read global result register*/
00292   result = ADC_MEASUREMENT_GetGlobalDetailedResult();
00293   return (result);
00294 }
00295 #endif