From: asterix Date: Tue, 28 Sep 2010 10:58:58 +0000 (+0000) Subject: Complete adc support for lm3s family. X-Git-Tag: 2.6.0~74 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=10cfb24580ac9720265e3a43448ccfd0b81ec49b;p=bertos.git Complete adc support for lm3s family. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4327 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/cpu/cortex-m3/drv/adc_lm3s.c b/bertos/cpu/cortex-m3/drv/adc_lm3s.c index 144b95d6..a59400e0 100644 --- a/bertos/cpu/cortex-m3/drv/adc_lm3s.c +++ b/bertos/cpu/cortex-m3/drv/adc_lm3s.c @@ -62,11 +62,20 @@ #include #include -#include -#include +#include +#include #include +/* Select witch ADC use */ +#if CPU_CM3_LM3S1968 || CPU_CM3_LM3S8962 + #define ADC_BASE ADC0_BASE + #define SYSCTL_RCGC_R SYSCTL_RCGC0_R + #define SYSCTL_RCGC_ADC SYSCTL_RCGC0_ADC0 +#else + #error Unknow ADC register for select cpu core +#endif + #if CONFIG_KERN #include @@ -96,12 +105,19 @@ sig_post(adc_process, SIG_ADC_COMPLETE); /* Clear the status bit */ + HWREG(ADC_BASE + ADC_O_ISC) |= ADC_ISC_IN3; + } static void adc_enable_irq(void) { + /* Clear all pending irq */ + HWREG(ADC_BASE + ADC_O_ISC) = 0; /* Register the IRQ handler */ - //sysirq_setHandler(ADC_IRQHANDLER, adc_conversion_end_irq); + sysirq_setHandler(INT_ADC3, adc_conversion_end_irq); + /* Enable IRQ */ + HWREG(ADC_BASE + ADC_O_SSCTL3) |= ADC_SSCTL3_IE0; + HWREG(ADC_BASE + ADC_O_IM) |= ADC_IM_MASK3; } #endif /* CONFIG_KERN */ @@ -115,7 +131,12 @@ */ void adc_hw_select_ch(uint8_t ch) { - /* We sample only from one channel */ + /* Select channel that we want read */ + HWREG(ADC_BASE + ADC_O_SSMUX3) = ch; + /* Make single acquisition */ + HWREG(ADC_BASE + ADC_O_SSCTL3) |= ADC_SSCTL3_END0; + /* Enable sequence S03 (single sample on select channel) */ + HWREG(ADC_BASE + ADC_O_ACTSS) |= ADC_ACTSS_ASEN3; } /** @@ -132,7 +153,7 @@ uint16_t adc_hw_read(void) #endif /* Start convertion */ - adc->CR2 |= CR2_EXTTRIG_SWSTRT_SET; + HWREG(ADC0_BASE + ADC_O_PSSI) |= ADC_PSSI_SS3; #if CONFIG_KERN /* Ensure IRQs enabled. */ @@ -140,16 +161,16 @@ uint16_t adc_hw_read(void) sig_wait(SIG_ADC_COMPLETE); /* Prevent race condition in case of preemptive kernel */ - + uint16_t ret = (uint16_t)HWREG(ADC_BASE + ADC_O_SSFIFO3); MEMORY_BARRIER; adc_process = NULL; return ret; #else /* Wait in polling until conversion is done */ - //while (!(adc->SR & BV(SR_EOC))); + while (!(HWREG(ADC_BASE + ADC_O_SSFSTAT3) & ADC_SSFSTAT3_FULL)); /* Return the last converted data */ - return 0; + return (uint16_t)HWREG(ADC_BASE + ADC_O_SSFIFO3); #endif } @@ -158,9 +179,19 @@ uint16_t adc_hw_read(void) */ void adc_hw_init(void) { + /* Enable ADC0 clock */ + SYSCTL_RCGC_R |= SYSCTL_RCGC_ADC; + /* + * We wait some time because the clock is istable + * and that could cause system hardfault + */ + lm3s_busyWait(10); - + /* Disable all sequence */ + HWREG(ADC_BASE + ADC_O_ACTSS) = 0; + /* Set trigger event to programmed (for all sequence) */ + HWREG(ADC_BASE + ADC_O_EMUX) = 0; #if CONFIG_KERN adc_enable_irq(); diff --git a/bertos/cpu/cortex-m3/drv/adc_lm3s.h b/bertos/cpu/cortex-m3/drv/adc_lm3s.h index ae677c54..1ffe33f4 100644 --- a/bertos/cpu/cortex-m3/drv/adc_lm3s.h +++ b/bertos/cpu/cortex-m3/drv/adc_lm3s.h @@ -45,15 +45,13 @@ /** * ADC config define. */ -#define ADC_MUX_MAXCH 17 //Max number of channel for ADC. -#define ADC_BITS 10 //Bit resolution for ADC converter. - -/** - * Define PIO controller for enable ADC function. - * \{ - */ - -/*\}*/ +#if CPU_CM3_LM3S1968 + #define ADC_MUX_MAXCH 8 //Max number of channel for ADC. + #define ADC_BITS 10 //Bit resolution for ADC converter. +#elif CPU_CM3_LM3S8962 + #define ADC_MUX_MAXCH 4 //Max number of channel for ADC. + #define ADC_BITS 10 //Bit resolution for ADC convert +#endif /** * Init the ADC pins.