summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Fiore <mfiore@multitech.com>2015-12-11 11:49:03 -0600
committerMike Fiore <mfiore@multitech.com>2015-12-11 11:49:03 -0600
commit0a4f3de5040de014ec5d7d442b803e39d7328fd5 (patch)
tree05ee768e26baa0e55b3045cbcecd97c3d6478400
parent4d25ea49c23dcfa0bbbe8c42eee37686e764997b (diff)
downloadmtdot-box-evb-factory-firmware-0a4f3de5040de014ec5d7d442b803e39d7328fd5.tar.gz
mtdot-box-evb-factory-firmware-0a4f3de5040de014ec5d7d442b803e39d7328fd5.tar.bz2
mtdot-box-evb-factory-firmware-0a4f3de5040de014ec5d7d442b803e39d7328fd5.zip
disable interrupts around critical sections in SensorHandler
-rw-r--r--SensorHandler/SensorHandler.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/SensorHandler/SensorHandler.cpp b/SensorHandler/SensorHandler.cpp
index 18f9ddc..207cb20 100644
--- a/SensorHandler/SensorHandler.cpp
+++ b/SensorHandler/SensorHandler.cpp
@@ -28,24 +28,34 @@ SensorHandler::~SensorHandler(void)
void SensorHandler::initSensors(){
// Setup the Accelerometer for 8g range, 14 bit resolution, Noise reduction off, sample rate 1.56 Hz
// normal oversample mode, High pass filter off
+ __disable_irq();
_accelerometer.setCommonParameters(MMA845x::RANGE_8g,MMA845x::RES_MAX,MMA845x::LN_OFF,
MMA845x::DR_6_25,MMA845x::OS_NORMAL,MMA845x::HPF_OFF );
+ __enable_irq();
// Setup the Barometric sensor for post processed Ambient pressure, 4 samples per data acquisition.
//and a sample taken every second when in active mode
+ __disable_irq();
_barometricSensor.setParameters(MPL3115A2::DATA_NORMAL, MPL3115A2::DM_BAROMETER, MPL3115A2::OR_16,
MPL3115A2::AT_1);
+ __enable_irq();
// Setup the Ambient Light Sensor for continuous Ambient Light Sensing, 16 bit resolution,
// and 16000 lux range
+ __disable_irq();
_lightSensor.setMode(ISL29011::ALS_CONT);
_lightSensor.setResolution(ISL29011::ADC_16BIT);
_lightSensor.setRange(ISL29011::RNG_16000);
+ __enable_irq();
// Set the accelerometer for active mode
+ __disable_irq();
_accelerometer.activeMode();
+ __enable_irq();
// Clear the min-max registers in the Barometric Sensor
+ __disable_irq();
_barometricSensor.clearMinMaxRegs();
+ __enable_irq();
}
void SensorHandler::startSensorThread(void const *p)
@@ -66,11 +76,15 @@ void SensorHandler::readSensors()
timer.reset();
do {
osDelay(20); // allows other threads to process
+ __disable_irq();
result = _accelerometer.getStatus();
+ __enable_irq();
if((result & MMA845x::XYZDR) != 0 ){
// Retrieve accelerometer data
_mutex.lock();
+ __disable_irq();
_accelerometerData = _accelerometer.getXYZ();
+ __enable_irq();
_mutex.unlock();
}
} while (((result & MMA845x::XYZDR) == 0 ) && (timer.read_ms() < 1000));
@@ -85,11 +99,15 @@ void SensorHandler::readSensors()
timer.reset();
do {
osDelay(20); // allows other threads to process
+ __disable_irq();
result = _barometricSensor.getStatus();
+ __enable_irq();
if((result & MPL3115A2::PTDR) != 0){
// Retrieve barometric pressure
_mutex.lock();
+ __disable_irq();
_pressure = _barometricSensor.getBaroData() >> 12; // convert 32 bit signed to 20 bit unsigned value
+ __enable_irq();
_mutex.unlock();
}
} while (((result & MPL3115A2::PTDR) == 0) && (timer.read_ms() < 100));
@@ -104,18 +122,24 @@ void SensorHandler::readSensors()
timer.reset();
do {
osDelay(20); // allows other threads to process
+ __disable_irq();
result = _barometricSensor.getStatus();
+ __enable_irq();
if((result & MPL3115A2::PTDR) != 0 ){
// Retrieve temperature and altitude.
_mutex.lock();
+ __disable_irq();
_barometerData = _barometricSensor.getAllData(false);
+ __enable_irq();
_mutex.unlock();
}
} while (((result & MPL3115A2::PTDR) == 0 ) && (timer.read_ms() < 100));
// Retrieve light level
_mutex.lock();
+ __disable_irq();
_light = _lightSensor.getData();
+ __enable_irq();
_mutex.unlock();
osDelay(100); // allows other threads to process
}