X-Git-Url: https://git.gag.com/?a=blobdiff_plain;ds=sidebyside;f=src%2Fstm%2Fao_adc_stm.c;h=af2968d6ea9df830933c63e92e775859968c2e10;hb=78423f3fc5164ea9fd428606419784c1700ad5c5;hp=1722a9ecdf0698e555969891867f468ea8bf5451;hpb=5e41d1e03680af9806c599aad80b9b64dd719f9b;p=fw%2Faltos diff --git a/src/stm/ao_adc_stm.c b/src/stm/ao_adc_stm.c index 1722a9ec..af2968d6 100644 --- a/src/stm/ao_adc_stm.c +++ b/src/stm/ao_adc_stm.c @@ -16,10 +16,17 @@ */ #include +#include +#if HAS_MPU6000 +#include +#endif +#if HAS_MS5607 +#include +#endif +volatile __xdata struct ao_data ao_data_ring[AO_DATA_RING]; +volatile __data uint8_t ao_data_head; -volatile __xdata struct ao_adc ao_adc_ring[AO_ADC_RING]; -volatile __data uint8_t ao_adc_head; static uint8_t ao_adc_ready; #define AO_ADC_CR2_VAL ((0 << STM_ADC_CR2_SWSTART) | \ @@ -28,11 +35,11 @@ static uint8_t ao_adc_ready; (0 << STM_ADC_CR2_JWSTART) | \ (STM_ADC_CR2_JEXTEN_DISABLE << STM_ADC_CR2_JEXTEN) | \ (0 << STM_ADC_CR2_JEXTSEL) | \ - (1 << STM_ADC_CR2_ALIGN) | \ + (0 << STM_ADC_CR2_ALIGN) | \ (0 << STM_ADC_CR2_EOCS) | \ (1 << STM_ADC_CR2_DDS) | \ (1 << STM_ADC_CR2_DMA) | \ - (STM_ADC_CR2_DELS_NONE << STM_ADC_CR2_DELS) | \ + (STM_ADC_CR2_DELS_UNTIL_READ << STM_ADC_CR2_DELS) | \ (0 << STM_ADC_CR2_CONT) | \ (1 << STM_ADC_CR2_ADON)) @@ -41,11 +48,17 @@ static uint8_t ao_adc_ready; * * Mark time in ring, shut down DMA engine */ -static void ao_adc_done(void) +static void ao_adc_done(int index) { - ao_adc_ring[ao_adc_head].tick = ao_time(); - ao_adc_head = ao_adc_ring_next(ao_adc_head); - ao_wakeup((void *) &ao_adc_head); + ao_data_ring[ao_data_head].adc.tick = ao_time(); +#if HAS_MPU6000 + ao_data_ring[ao_data_head].mpu6000 = ao_mpu6000_current; +#endif +#if HAS_MS5607 + ao_data_ring[ao_data_head].ms5607 = ao_ms5607_current; +#endif + ao_data_head = ao_data_ring_next(ao_data_head); + ao_wakeup((void *) &ao_data_head); ao_dma_done_transfer(STM_DMA_INDEX(STM_DMA_CHANNEL_ADC1)); ao_adc_ready = 1; } @@ -62,7 +75,7 @@ ao_adc_poll(void) stm_adc.sr = 0; ao_dma_set_transfer(STM_DMA_INDEX(STM_DMA_CHANNEL_ADC1), &stm_adc.dr, - (void *) (&ao_adc_ring[ao_adc_head].tick + 1), + (void *) (&ao_data_ring[ao_data_head].tick + 1), AO_NUM_ADC, (0 << STM_DMA_CCR_MEM2MEM) | (STM_DMA_CCR_PL_HIGH << STM_DMA_CCR_PL) | @@ -84,20 +97,27 @@ ao_adc_poll(void) void ao_adc_get(__xdata struct ao_adc *packet) { - uint8_t i = ao_adc_ring_prev(ao_adc_head); - memcpy(packet, (void *) &ao_adc_ring[i], sizeof (struct ao_adc)); + uint8_t i = ao_data_ring_prev(ao_data_head); + memcpy(packet, (void *) &ao_data_ring[i].adc, sizeof (struct ao_adc)); +} + +void +ao_data_get(__xdata struct ao_data *packet) +{ + uint8_t i = ao_data_ring_prev(ao_data_head); + memcpy(packet, (void *) &ao_data_ring[i], sizeof (struct ao_data)); } static void ao_adc_dump(void) __reentrant { - struct ao_adc packet; + struct ao_data packet; int16_t *d; uint8_t i; - ao_adc_get(&packet); + ao_data_get(&packet); printf("tick: %5u", packet.tick); - d = (int16_t *) (&packet.tick + 1); + d = (int16_t *) (&packet.adc); for (i = 0; i < AO_NUM_ADC; i++) printf (" %2d: %5d", i, d[i]); printf("\n"); @@ -168,10 +188,10 @@ ao_adc_init(void) (0 << STM_ADC_CR1_EOCIE ) | (0 << STM_ADC_CR1_AWDCH )); - /* 4 cycle sample time for everyone */ - stm_adc.smpr1 = 0; - stm_adc.smpr2 = 0; - stm_adc.smpr3 = 0; + /* 384 cycle sample time for everyone */ + stm_adc.smpr1 = 0x3ffff; + stm_adc.smpr2 = 0x3fffffff; + stm_adc.smpr3 = 0x3fffffff; stm_adc.sqr1 = ((AO_NUM_ADC - 1) << 20); stm_adc.sqr2 = 0; @@ -221,5 +241,7 @@ ao_adc_init(void) /* Clear any stale status bits */ stm_adc.sr = 0; ao_adc_ready = 1; + + ao_dma_alloc(STM_DMA_INDEX(STM_DMA_CHANNEL_ADC1)); ao_cmd_register(&ao_adc_cmds[0]); }