X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Flpc%2Fao_adc_lpc.c;h=1fbf13660a5969739cf496d602acf699e4abb371;hb=e8b0ac5a17d2fb5a0d99ea86c3a2e1c780d3adf3;hp=b24163eeb9daa3b91bdfad259879f8de81c249a7;hpb=0a3312e725d914bbba6355e07d2f1d2833d2d6c2;p=fw%2Faltos diff --git a/src/lpc/ao_adc_lpc.c b/src/lpc/ao_adc_lpc.c index b24163ee..1fbf1366 100644 --- a/src/lpc/ao_adc_lpc.c +++ b/src/lpc/ao_adc_lpc.c @@ -3,7 +3,8 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of @@ -56,7 +57,10 @@ /* ADC clock is divided by this value + 1, which ensures that * the ADC clock will be strictly less than 4.5MHz as required */ -#define AO_ADC_CLKDIV (AO_LPC_SYSCLK / 450000) +#ifndef AO_LPC_ADC_CLOCK +#define AO_LPC_ADC_CLOCK 4500000 +#endif +#define AO_ADC_CLKDIV (AO_LPC_SYSCLK / AO_LPC_ADC_CLOCK) static uint8_t ao_adc_ready; static uint8_t ao_adc_sequence; @@ -78,7 +82,7 @@ static const uint8_t ao_adc_mask_seq[AO_ADC_NUM] = { 1 << 4, #endif #if AO_ADC_5 - 1 << 6, + 1 << 5, #endif #if AO_ADC_6 1 << 6, @@ -91,7 +95,7 @@ static const uint8_t ao_adc_mask_seq[AO_ADC_NUM] = { #define sample(id) (*out++ = (uint16_t) lpc_adc.dr[id] >> 1) static inline void lpc_adc_start(void) { - lpc_adc.cr = ((ao_adc_mask_seq[ao_adc_sequence] << LPC_ADC_CR_SEL) | + lpc_adc.cr = (((uint32_t) ao_adc_mask_seq[ao_adc_sequence] << LPC_ADC_CR_SEL) | (AO_ADC_CLKDIV << LPC_ADC_CR_CLKDIV) | (0 << LPC_ADC_CR_BURST) | (LPC_ADC_CR_CLKS_11 << LPC_ADC_CR_CLKS) | @@ -111,23 +115,7 @@ void lpc_adc_isr(void) } AO_DATA_PRESENT(AO_DATA_ADC); - if (ao_data_present == AO_DATA_ALL) { -#if HAS_MS5607 - ao_data_ring[ao_data_head].ms5607_raw = ao_ms5607_current; -#endif -#if HAS_MMA655X - ao_data_ring[ao_data_head].mma655x = ao_mma655x_current; -#endif -#if HAS_HMC5883 - ao_data_ring[ao_data_head].hmc5883 = ao_hmc5883_current; -#endif -#if HAS_MPU6000 - ao_data_ring[ao_data_head].mpu6000 = ao_mpu6000_current; -#endif - ao_data_ring[ao_data_head].tick = ao_tick_count; - ao_data_head = ao_data_ring_next(ao_data_head); - ao_wakeup((void *) &ao_data_head); - } + ao_data_fill(ao_data_head); ao_adc_ready = 1; } @@ -146,7 +134,7 @@ ao_adc_poll(void) } static void -ao_adc_dump(void) __reentrant +ao_adc_dump(void) { struct ao_data packet; #ifndef AO_ADC_DUMP @@ -166,7 +154,7 @@ ao_adc_dump(void) __reentrant #endif } -__code struct ao_cmds ao_adc_cmds[] = { +const struct ao_cmds ao_adc_cmds[] = { { ao_adc_dump, "a\0Display current ADC values" }, { 0, NULL }, }; @@ -175,7 +163,7 @@ void ao_adc_init(void) { lpc_scb.sysahbclkctrl |= (1 << LPC_SCB_SYSAHBCLKCTRL_ADC); - lpc_scb.pdruncfg &= ~(1 << LPC_SCB_PDRUNCFG_ADC_PD); + lpc_scb.pdruncfg &= ~(1UL << LPC_SCB_PDRUNCFG_ADC_PD); /* Enable interrupt when channel is complete */ lpc_adc.inten = (1 << LPC_ADC_INTEN_ADGINTEN);