diff options
Diffstat (limited to 'firmware/target')
-rw-r--r-- | firmware/target/arm/tcc780x/adc-tcc780x.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/firmware/target/arm/tcc780x/adc-tcc780x.c b/firmware/target/arm/tcc780x/adc-tcc780x.c index 62bc53e6c1..8c438e2689 100644 --- a/firmware/target/arm/tcc780x/adc-tcc780x.c +++ b/firmware/target/arm/tcc780x/adc-tcc780x.c | |||
@@ -63,7 +63,7 @@ unsigned short adc_read(int channel) | |||
63 | { | 63 | { |
64 | #ifdef BOOTLOADER | 64 | #ifdef BOOTLOADER |
65 | /* IRQs aren't enabled in the bootloader - just do the read directly */ | 65 | /* IRQs aren't enabled in the bootloader - just do the read directly */ |
66 | int i,num; | 66 | int i; |
67 | uint32_t adc_status; | 67 | uint32_t adc_status; |
68 | 68 | ||
69 | PCLK_ADC |= PCK_EN; /* Enable ADC clock */ | 69 | PCLK_ADC |= PCK_EN; /* Enable ADC clock */ |
@@ -72,15 +72,15 @@ unsigned short adc_read(int channel) | |||
72 | for (i = 0; i < 4; i++) | 72 | for (i = 0; i < 4; i++) |
73 | ADCCON = i; | 73 | ADCCON = i; |
74 | 74 | ||
75 | /* Wait for data to become stable */ | 75 | /* Now read the values back */ |
76 | while ((ADCDATA & 0x1) == 0); | 76 | for (i=0; i < 4; i++) |
77 | |||
78 | do | ||
79 | { | 77 | { |
78 | /* Wait for data to become stable */ | ||
79 | while ((ADCDATA & 0x1) == 0); | ||
80 | |||
80 | adc_status = ADCSTATUS; | 81 | adc_status = ADCSTATUS; |
81 | num = (adc_status>>24) & 7; | 82 | adcdata[(adc_status >> 16) & 0x7] = adc_status & 0x3ff; |
82 | if (num) adcdata[(adc_status >> 16) & 0x7] = adc_status & 0x3ff; | 83 | } |
83 | } while (num); | ||
84 | 84 | ||
85 | PCLK_ADC &= ~PCK_EN; /* Disable ADC clock */ | 85 | PCLK_ADC &= ~PCK_EN; /* Disable ADC clock */ |
86 | #endif | 86 | #endif |
@@ -93,10 +93,11 @@ void adc_init(void) | |||
93 | /* consider configuring PCK_ADC source here */ | 93 | /* consider configuring PCK_ADC source here */ |
94 | 94 | ||
95 | ADCCON = (1<<4); /* Enter standby mode */ | 95 | ADCCON = (1<<4); /* Enter standby mode */ |
96 | ADCCFG |= 0x0000000B; /* Single-mode, auto power-down, IRQ enable */ | 96 | ADCCFG |= 0x00000003; /* Single-mode, auto power-down */ |
97 | 97 | ||
98 | #ifndef BOOTLOADER | 98 | #ifndef BOOTLOADER |
99 | IEN |= ADC_IRQ_MASK; /* Enable ADC IRQs */ | 99 | ADCCFG |= (1<<3); /* Request IRQ on ADC completion */ |
100 | IEN |= ADC_IRQ_MASK; /* Unmask ADC IRQs */ | ||
100 | 101 | ||
101 | tick_add_task(adc_tick); | 102 | tick_add_task(adc_tick); |
102 | 103 | ||