summaryrefslogtreecommitdiff
path: root/firmware/target/arm
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm')
-rw-r--r--firmware/target/arm/s3c2440/gigabeat-fx/adc-meg-fx.c84
1 files changed, 38 insertions, 46 deletions
diff --git a/firmware/target/arm/s3c2440/gigabeat-fx/adc-meg-fx.c b/firmware/target/arm/s3c2440/gigabeat-fx/adc-meg-fx.c
index 9a934c2487..266555fe3b 100644
--- a/firmware/target/arm/s3c2440/gigabeat-fx/adc-meg-fx.c
+++ b/firmware/target/arm/s3c2440/gigabeat-fx/adc-meg-fx.c
@@ -21,16 +21,12 @@
21#include "adc-target.h" 21#include "adc-target.h"
22#include "kernel.h" 22#include "kernel.h"
23 23
24
25
26static unsigned short adc_readings[NUM_ADC_CHANNELS]; 24static unsigned short adc_readings[NUM_ADC_CHANNELS];
27 25
28/* prototypes */ 26/* prototypes */
29static unsigned short __adc_read(int channel); 27static unsigned short __adc_read(int channel);
30static void adc_tick(void); 28static void adc_tick(void);
31 29
32
33
34void adc_init(void) 30void adc_init(void)
35{ 31{
36 int i; 32 int i;
@@ -59,20 +55,14 @@ void adc_init(void)
59 55
60 /* attach the adc reading to the tick */ 56 /* attach the adc reading to the tick */
61 tick_add_task(adc_tick); 57 tick_add_task(adc_tick);
62
63
64} 58}
65 59
66
67
68/* Called to get the recent ADC reading */ 60/* Called to get the recent ADC reading */
69inline unsigned short adc_read(int channel) 61inline unsigned short adc_read(int channel)
70{ 62{
71 return adc_readings[channel]; 63 return adc_readings[channel];
72} 64}
73 65
74
75
76/** 66/**
77 * Read the ADC by polling 67 * Read the ADC by polling
78 * @param channel The ADC channel to read 68 * @param channel The ADC channel to read
@@ -80,47 +70,52 @@ inline unsigned short adc_read(int channel)
80 */ 70 */
81static unsigned short __adc_read(int channel) 71static unsigned short __adc_read(int channel)
82{ 72{
83 int i; 73 int i;
84 74
85 /* Set the channel */ 75 /* Set the channel */
86 ADCCON = (ADCCON & ~(0x7<<3)) | (channel<<3); 76 ADCCON = (ADCCON & ~(0x7<<3)) | (channel<<3);
87 77
88 /* Start the conversion process */ 78 /* Start the conversion process */
89 ADCCON |= 0x1; 79 ADCCON |= 0x1;
90 80
91 /* Wait for a low Enable_start */ 81 /* Wait for a low Enable_start */
92 for (i = 20000;;) { 82 for (i = 20000;;)
93 if(0 == (ADCCON & 0x1)) { 83 {
94 break; 84 if(0 == (ADCCON & 0x1))
95 } 85 {
96 else { 86 break;
97 i--; 87 }
98 if (0 == i) { 88 else
99 /* Ran out of time */ 89 {
100 return ADC_READ_ERROR; 90 i--;
101 } 91 if (0 == i)
92 {
93 /* Ran out of time */
94 return ADC_READ_ERROR;
95 }
96 }
102 } 97 }
103 }
104 98
105 /* Wait for high End_of_Conversion */ 99 /* Wait for high End_of_Conversion */
106 for(i = 20000;;) { 100 for(i = 20000;;)
107 if(ADCCON & (1<<15)) { 101 {
108 break; 102 if(ADCCON & (1<<15))
109 } 103 {
110 else { 104 break;
111 i--; 105 }
112 if(0 == i) { 106 else
113 /* Ran out of time */ 107 {
114 return ADC_READ_ERROR; 108 i--;
115 } 109 if(0 == i)
110 {
111 /* Ran out of time */
112 return ADC_READ_ERROR;
113 }
114 }
116 } 115 }
117 } 116 return (ADCDAT0 & 0x3ff);
118
119 return (ADCDAT0 & 0x3ff);
120} 117}
121 118
122
123
124/* add this to the tick so that the ADC converts are done in the background */ 119/* add this to the tick so that the ADC converts are done in the background */
125static void adc_tick(void) 120static void adc_tick(void)
126{ 121{
@@ -140,6 +135,3 @@ static void adc_tick(void)
140 } 135 }
141} 136}
142 137
143
144
145