+#if CONFIG_KERN
+ #include <cfg/module.h>
+
+ #include <kern/proc.h>
+ #include <kern/signal.h>
+
+ #include <drv/irq_cm3.h>
+
+
+ #if !CONFIG_KERN_SIGNALS
+ #error Signals must be active to use ADC with kernel
+ #endif
+
+ /* Signal adc convertion end */
+ #define SIG_ADC_COMPLETE SIG_USER0
+
+ /* ADC waiting process */
+ static struct Process *adc_process;
+
+ /**
+ * ADC ISR.
+ * Simply signal the adc process that convertion is complete.
+ */
+ static DECLARE_ISR(adc_conversion_end_irq)
+ {
+ sig_post(adc_process, SIG_ADC_COMPLETE);
+
+ /* Clear the status bit */
+ adc->SR &= ~BV(SR_EOC);
+ }
+
+ static void adc_enable_irq(void)
+ {
+ /* Register the IRQ handler */
+ sysirq_setHandler(ADC_IRQHANDLER, adc_conversion_end_irq);
+ adc->CR1 |= BV(CR1_EOCIE);
+ }
+
+#endif /* CONFIG_KERN */
+