tc520.c
Go to the documentation of this file.00001
00041 #include "hw/hw_tc520.h"
00042
00043 #include <cfg/macros.h>
00044 #include <cfg/compiler.h>
00045
00046 #include <drv/tc520.h>
00047 #include <drv/timer.h>
00048
00049 #warning FIXME:This implementation is obsolete. Refactor with KFile interface.
00050
00051 #if 0
00052
00053 #include <drv/ser.h>
00054
00055 static Serial *spi_ser;
00056
00057 #define TC520_CONVERSION_TIMEOUT ms_to_ticks(1000)
00058 #define INIT_LOAD_VALUE 0x00
00059
00091 tc520_data_t tc520_read(void)
00092 {
00093
00094 CE_LOW();
00095 ticks_t start = timer_clock();
00096 do
00097 {
00098
00099 if (timer_clock() - start >= TC520_CONVERSION_TIMEOUT)
00100 {
00101 ASSERT(0);
00102 CE_HIGH();
00103 return TC520_MAX_VALUE;
00104 }
00105 }
00106 while(DV_LOW());
00107
00108 start = timer_clock();
00109 do
00110 {
00111
00112 if (timer_clock() - start >= TC520_CONVERSION_TIMEOUT)
00113 {
00114 ASSERT(0);
00115 CE_HIGH();
00116 return TC520_MAX_VALUE;
00117 }
00118 }
00119 while(DV_HIGH());
00120
00121
00122 CE_HIGH();
00123 READ_LOW();
00124
00125
00126 ser_purge(spi_ser);
00127
00128
00129 uint8_t buf[3] = "\x0\x0\x0";
00130
00131
00132 ser_write(spi_ser, buf, sizeof(buf));
00133 ser_drain(spi_ser);
00134 READ_HIGH();
00135
00136
00137 ASSERT(ser_read(spi_ser, buf, sizeof(buf)) == sizeof(buf));
00138
00139 tc520_data_t res;
00140
00141
00142 res = (((tc520_data_t)(buf[0] & 0x3F)) << 10) | (((tc520_data_t)buf[1]) << 2) | (((tc520_data_t)buf[2]) >> 6);
00143
00144 #define OVERRANGE_BIT BV(7)
00145
00146 if (buf[0] & OVERRANGE_BIT)
00147 res |= BV32(16);
00148
00149 return res;
00150 }
00151
00152
00156 void tc520_init(Serial *spi_port)
00157 {
00158 spi_ser = spi_port;
00159
00160 TC520_HW_INIT;
00161
00162 LOAD_LOW();
00163 ser_putchar(INIT_LOAD_VALUE, spi_ser);
00164 ser_drain(spi_ser);
00165 LOAD_HIGH();
00166 }
00167
00168 #endif