34 #include "lib/sensors.h"
38 #define ADC12MCTL_NO(adcno) ((unsigned char *) ADC12MCTL0_)[adcno]
40 static int (* adc12_irq[8])(void);
41 static int (* port1_irq[8])(void);
42 static unsigned char adcflags;
45 interrupt(PORT1_VECTOR)
49 ENERGEST_ON(ENERGEST_TYPE_IRQ);
50 for(i = 0; i < 8; i++) {
51 if((P1IFG & (1 << i)) && port1_irq[i] !=
NULL) {
52 if((port1_irq[i])()) {
58 ENERGEST_OFF(ENERGEST_TYPE_IRQ);
61 interrupt (ADC_VECTOR)
65 ENERGEST_ON(ENERGEST_TYPE_IRQ);
66 for(i = 0; i < 8; i++) {
67 if(adc12_irq[i] !=
NULL) {
68 if((adc12_irq[i])()) {
73 ENERGEST_OFF(ENERGEST_TYPE_IRQ);
81 for(i = 0; i < 8; i++) {
86 ADC12CTL0 = REF2_5V | SHT0_10 | SHT1_10 | MSC;
90 ADC12CTL1 = SHP | CONSEQ_3 | ADC12DIV_7;
94 irq_port1_activate(
unsigned char irqno,
int (* irq)(
void))
97 port1_irq[irqno] = irq;
102 irq_port1_deactivate(
unsigned char irqno)
105 port1_irq[irqno] =
NULL;
117 ADC12CTL1 &= ~(CSTARTADD_15);
120 for(c = 0; c < 8; c++) {
121 if(adcflags & (1 << c)) {
122 ADC12CTL1 |= (c * CSTARTADD_1);
129 for(c = 0; c < 8; c++) {
130 ADC12MCTL_NO(c) &= ~EOS;
135 for(c = 0; c < 8; c++) {
136 if(adcflags & (128 >> c)) {
138 ADC12MCTL_NO(7 - c) |= EOS;
145 irq_adc12_activate(
unsigned char adcno,
unsigned char config,
154 while(ADC12CTL0 & ADC12BUSY);
155 ADC12CTL0 &= ~(ADC12ON | REFON);
161 adcflags |= (1 << adcno);
163 ADC12MCTL_NO(adcno) = config;
167 ADC12CTL0 |= ADC12ON | REFON;
169 adc12_irq[adcno] = irq;
174 ADC12CTL0 |= ENC | ADC12SC;
178 irq_adc12_deactivate(
unsigned char adcno)
186 while(ADC12CTL0 & ADC12BUSY);
187 ADC12CTL0 &= ~(ADC12ON | REFON);
193 adcflags &= ~(1 << adcno);
195 ADC12MCTL_NO(adcno) = 0;
199 adc12_irq[adcno] =
NULL;
203 ADC12CTL0 |= (ADC12ON | REFON);
209 ADC12CTL0 |= ENC | ADC12SC;
214 irq_adc12_active(
unsigned char adcno)
216 return adcflags & (1 << adcno) ? 1 : 0;