generated from TDD-Templates/cmake_cpputest_template_avr
Added code to pass the ADC timeout feature
This commit is contained in:
parent
58ab3c12eb
commit
c07fc415bf
|
@ -85,25 +85,29 @@ void ADC_Disable() {
|
||||||
RegEdit_ClearBit((void *)&ADCSRA, ADEN);
|
RegEdit_ClearBit((void *)&ADCSRA, ADEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint16_t ADC_ReadValue_Impl(uint8_t adc_chan) {
|
uint16_t ADC_ReadValue_Impl(uint8_t adc_chan) {
|
||||||
// RegEdit_SetNum((void *)&ADC0.COMMAND, ADC_STCONV_bm);
|
if (IsInvalidChannel(adc_chan)) {
|
||||||
|
return UINT16_MAX;
|
||||||
|
}
|
||||||
|
|
||||||
/* Wait until ADC conversion done */
|
// start conversion.
|
||||||
|
RegEdit_SetBit((void *)&ADCSRA, ADSC);
|
||||||
|
|
||||||
/*
|
/* Wait until ADC conversion done or it times out. */
|
||||||
while (!(ADC0.INTFLAGS & ADC_RESRDY_bm)) {
|
uint8_t cycles = 1;
|
||||||
;
|
while (1) {
|
||||||
}
|
if (!RegEdit_IsBitSet((void *)&ADCSRA, ADSC)) {
|
||||||
*/
|
break;
|
||||||
|
}
|
||||||
|
// if It times out return an invalid value for a 12bit ADC.
|
||||||
|
else if (cycles >= ADC_WAIT_TIMEOUT) {
|
||||||
|
return UINT16_MAX;
|
||||||
|
}
|
||||||
|
cycles++;
|
||||||
|
}
|
||||||
|
|
||||||
/* Clear the interrupt flag by writing 1: */
|
uint8_t val = ADC;
|
||||||
// ADC0.INTFLAGS = ADC_RESRDY_bm;
|
return val;
|
||||||
|
|
||||||
// uint16_t adc_val = (uint16_t)ADC0.RES;
|
|
||||||
uint16_t adc_val = 0;
|
|
||||||
adc_val = adc_val >> 5;
|
|
||||||
return adc_val;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the default for the function pointer.
|
// Set the default for the function pointer.
|
||||||
|
|
|
@ -13,6 +13,12 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The number of loop cycles it waits for ADC conversion before
|
||||||
|
* timing out.
|
||||||
|
*/
|
||||||
|
#define ADC_WAIT_TIMEOUT 16
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initializes the AVR hardware in order to accept
|
* @brief Initializes the AVR hardware in order to accept
|
||||||
* Input for ADC usage.
|
* Input for ADC usage.
|
||||||
|
@ -27,7 +33,6 @@
|
||||||
*/
|
*/
|
||||||
void ADC_Init(uint8_t adc_chan);
|
void ADC_Init(uint8_t adc_chan);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the pin number for the adc channel or 255 on an error.
|
* @brief Returns the pin number for the adc channel or 255 on an error.
|
||||||
* @param The ADC channel.
|
* @param The ADC channel.
|
||||||
|
@ -65,5 +70,4 @@ extern uint16_t (*ADC_ReadValue)(uint8_t adc_chan);
|
||||||
*/
|
*/
|
||||||
void ADC_Setup(void);
|
void ADC_Setup(void);
|
||||||
|
|
||||||
|
|
||||||
#endif // ADC_H
|
#endif // ADC_H
|
||||||
|
|
Loading…
Reference in New Issue