work on ADC sampling, not tested, missing commands

This commit is contained in:
2018-02-04 17:43:59 +01:00
parent 300a6a6e90
commit 02f69b0e37
10 changed files with 416 additions and 82 deletions
+3
View File
@@ -349,6 +349,9 @@ bool solve_timer(uint32_t base_freq, uint32_t required_freq, bool is16bit,
uint16_t *presc, uint32_t *count, float *real_freq)
{
if (required_freq == 0) return false;
// XXX consider using the LL macros __LL_TIM_CALC_PSC and __LL_TIM_CALC_ARR
const float fPresc = base_freq / required_freq;
uint32_t wCount = (uint32_t) lrintf(fPresc);
+12
View File
@@ -183,4 +183,16 @@ void hw_periph_clock_disable(void *periph);
bool solve_timer(uint32_t base_freq, uint32_t required_freq, bool is16bit,
uint16_t *presc, uint32_t *count, float *real_freq);
#define hw_wait_while(call, timeout) \
do { \
uint32_t _ts = HAL_GetTick(); \
while (1 == (call)) { \
if (HAL_GetTick() - _ts > (timeout)) { \
trap("Timeout"); \
} \
} \
} while (0)
#define hw_wait_until(call, timeout) hw_wait_while(!(call), (timeout))
#endif //GEX_PIN_UTILS_H
+12 -1
View File
@@ -65,6 +65,8 @@ static struct callbacks_ {
struct cbslot tim7;
struct cbslot tim15;
struct cbslot adc1;
// XXX add more callbacks here when needed
} callbacks;
@@ -96,7 +98,9 @@ void irqd_init(void)
HAL_NVIC_SetPriority(DMA1_Channel2_3_IRQn, 2, 0);
HAL_NVIC_SetPriority(DMA1_Channel4_5_6_7_IRQn, 2, 0);
// NVIC_EnableIRQ(ADC1_COMP_IRQn); /*!< ADC1 and COMP interrupts (ADC interrupt combined with EXTI Lines 21 and 22 */
NVIC_EnableIRQ(ADC1_COMP_IRQn); /*!< ADC1 and COMP interrupts (ADC interrupt combined with EXTI Lines 21 and 22 */
HAL_NVIC_SetPriority(ADC1_COMP_IRQn, 1, 0); // ADC group completion - higher prio than DMA to let it handle the last halfword first
// NVIC_EnableIRQ(TIM1_IRQn); /*!< TIM1 global Interrupt */
// NVIC_EnableIRQ(TIM2_IRQn); /*!< TIM2 global Interrupt */
// NVIC_EnableIRQ(TIM3_IRQn); /*!< TIM3 global Interrupt */
@@ -159,6 +163,8 @@ static struct cbslot *get_slot_for_periph(void *periph)
else if (periph == TIM7) slot = &callbacks.tim7;
else if (periph == TIM15) slot = &callbacks.tim15;
else if (periph == ADC1) slot = &callbacks.adc1;
else if (periph >= EXTIS[0] && periph <= EXTIS[15]) {
slot = &callbacks.exti[periph - EXTIS[0]];
}
@@ -313,6 +319,11 @@ void TIM15_IRQHandler(void)
CALL_IRQ_HANDLER(callbacks.tim15);
}
void ADC1_COMP_IRQHandler(void)
{
CALL_IRQ_HANDLER(callbacks.adc1);
}
// other ISRs...
+4 -1
View File
@@ -18,6 +18,8 @@
void plat_init(void)
{
// GPIO clocks are enabled earlier in the GEX start-up hook
// Load system defaults
systemsettings_init();
@@ -27,8 +29,9 @@ void plat_init(void)
LockJumper_Init();
Indicator_Init();
DebugUart_Init(); // resource claim
DebugUart_Init(); // resource claim (was inited earlier to allow debug outputs)
// Enable interrupts and set priorities
irqd_init();
dbg("Loading settings ...");