ADC Callback Function

When the ADC is configured in callback mode, a user-defined function is set to run when a desired ADC interrupt occurs. The predefined ADC conditions for excecuting an interrupt are: buffer received, window hit, and conversion error. In this example it is desirable to recieve an interrupt when the ADC conversion is complete, i.e. when the result buffer is recieved.

A basic rule of thumb is to minimize the excecution time of the callback function. In this example, this is ensured by signaling the application with a globally defined conversion complete-flag.
/* ADC Callback Function */
void adc_complete_callback(const struct adc_module *const module)
{
    /* Set ADC conversion ended flag */
    adc_read_done = true;
}
The callback function is enabled with the following function where the ADC_CALLBACK_READ_BUFFER parameter indicates that the callback function is to be associated with a complete conversion.
/* Enable ADC Callback Function */
void configure_adc_callbacks(void)
{
	adc_register_callback(&adc_instance,
			adc_complete_callback, ADC_CALLBACK_READ_BUFFER);
	adc_enable_callback(&adc_instance, ADC_CALLBACK_READ_BUFFER);
}