contiki-os/contiki — pull request #398 by areaarea (2013-10-30 00:05:49+00:00)
Title: ADC driver for cc2538 (re-pull request)

Here is an ADC driver for the cc2538. It is a arch specific implementation right now, but I think the method is definitely scalable and abstractable. General flow of the driver:

adc_init() does very little but set flags and the interrupt. The real setup of each pin happens in the adc_register_pin() function. It currently supports single ended reads on A0:7 or differential reads on A01:67. The register function sets up an element that allows the pins to be tracked and serviced independently from each other. A callback function is registered for the independent pin such that any number of modules can register the pin and the ADC driver needs no information on data handling itself. The upside is that you can fire all the pins on different time scales and from different modules. The down side is there is a fundamental limit of 128sps and rounding make *exact* *jitter-free* measurements difficult (although power of 2 sps rates should have limited jitter.)

There is a process that runs for the driver that fires at 128Hz and counts down all the 'timers' of all the active pins. When any (or all) pins need servicing, there is a helper function that handles the traversing of the structure and the isr() dispatches the data to the related cb function.

Was related to the discussion I tried to start in #384 but maybe an actual implementation will aid that discussion.