added adc mutex
This commit is contained in:
parent
78f3f25937
commit
0fbdd071ab
|
@ -67,6 +67,7 @@
|
||||||
|
|
||||||
static bool _adcInitialised = false;
|
static bool _adcInitialised = false;
|
||||||
static uint8_t _adcLastChannel = 0;
|
static uint8_t _adcLastChannel = 0;
|
||||||
|
uint8_t adcMutex = 0;
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
/*!
|
/*!
|
||||||
|
@ -89,6 +90,7 @@ static uint8_t _adcLastChannel = 0;
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
uint32_t adcRead (uint8_t channelNum)
|
uint32_t adcRead (uint8_t channelNum)
|
||||||
{
|
{
|
||||||
|
adcMutex = 1;
|
||||||
if (!_adcInitialised) adcInit();
|
if (!_adcInitialised) adcInit();
|
||||||
|
|
||||||
uint32_t regVal, adcData;
|
uint32_t regVal, adcData;
|
||||||
|
@ -154,11 +156,13 @@ uint32_t adcRead (uint8_t channelNum)
|
||||||
/* return 0 if an overrun occurred */
|
/* return 0 if an overrun occurred */
|
||||||
if ( regVal & ADC_DR_OVERRUN )
|
if ( regVal & ADC_DR_OVERRUN )
|
||||||
{
|
{
|
||||||
|
adcMutex = 0;
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* return conversion results */
|
/* return conversion results */
|
||||||
adcData = (regVal >> 6) & 0x3FF;
|
adcData = (regVal >> 6) & 0x3FF;
|
||||||
|
adcMutex = 0;
|
||||||
return (adcData);
|
return (adcData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
|
|
||||||
#include "projectconfig.h"
|
#include "projectconfig.h"
|
||||||
|
|
||||||
|
extern uint8_t adcMutex;
|
||||||
uint32_t adcRead (uint8_t channelNum);
|
uint32_t adcRead (uint8_t channelNum);
|
||||||
void adcInit (void);
|
void adcInit (void);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue