adc.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <stdio.h>
00012 #include "banked.h"
00013 #include "contiki.h"
00014 #include "sys/clock.h"
00015
00016 #include "cc2430_sfr.h"
00017 #include "dev/adc.h"
00018 #include "dev/dma.h"
00019
00020 #ifdef HAVE_DMA
00021 xDMAHandle adc_dma=0xff;
00022 unsigned int *adc_dma_dest;
00023 #endif
00024
00025
00026 void adc_init(void) __banked
00027 {
00028 unsigned char jj;
00029 while (!SLEEP&(HFRC_STB)) {}
00030
00031 SLEEP &= ~(OSC_PD);
00032
00033
00034 while (!SLEEP&(XOSC_STB)) {}
00035
00036
00037 clock_delay(150);
00038
00039
00040 CLKCON &= ~(OSC);
00041
00042
00043 SLEEP |= OSC_PD;
00044
00045 #ifdef HAVE_DMA
00046
00047 if (adc_dma==0xff) {
00048 dma_init();
00049
00050 adc_dma=dma_config2(ADC_DMA_CONFIG_CHANNEL, &ADC_SHADOW, DMA_NOINC, adc_dma_dest, DMA_NOINC, 1, 1, DMA_VLEN_LEN, DMA_RPT, DMA_T_ADC_CHALL, 0);
00051 }
00052 #endif
00053 }
00054
00055 void adc_single_shot(void) __banked
00056 {
00057 ADCCON1 |= 0x73;
00058 }
00059
00060 int16_t adc_convert_result(int16_t data) __banked {
00061 data = (0xfffc&data)>>2;
00062 return data;
00063 }
00064
00065 int16_t adc_get_last_conv() __banked {
00066 int16_t result;
00067 result = (ADCH<<8)|(ADCL);
00068 result = (0xfffc&result)>>2;
00069 return result;
00070 }