[Firebug-cvs] fireboard/beta/tos/sensorboards/mts400 TempHumM.nc,1.2,1.3
Brought to you by:
doolin
From: Michael N. <mne...@us...> - 2005-07-03 11:50:41
|
Update of /cvsroot/firebug/fireboard/beta/tos/sensorboards/mts400 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29830 Modified Files: TempHumM.nc Log Message: processCommand now syncronous, comments added about issues Index: TempHumM.nc =================================================================== RCS file: /cvsroot/firebug/fireboard/beta/tos/sensorboards/mts400/TempHumM.nc,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TempHumM.nc 24 May 2005 21:57:34 -0000 1.2 --- TempHumM.nc 3 Jul 2005 11:50:29 -0000 1.3 *************** *** 61,65 **** /* * ! * Authors: Mohammad Rahmim, Joe Polastre * * $Id$ --- 61,65 ---- /* * ! * Authors: Mohammad Rahmim, Joe Polastre, Michael Newman * * $Id$ *************** *** 166,173 **** * -Enable SDA as interrupt, this line goes low when Sensirion completes measurement ******************************************************************************/ ! static inline char processCommand(int cmd) { int i; ! int CMD = cmd; cmd &= 0x1f; HUMIDITY_INT_DISABLE(); --- 166,195 ---- * -Enable SDA as interrupt, this line goes low when Sensirion completes measurement ******************************************************************************/ ! task void processCommand() { + int currentState; + int cmd; + int currentCMD; int i; ! ! atomic { ! currentState = state; ! } ! switch (currentState) { ! case TEMP_MEASUREMENT: ! cmd = TOSH_HUMIDTEMP_ADDR; ! break; ! case READY: ! cmd = TOSH_HUMIDITY_RESET; ! break; ! case HUM_MEASUREMENT: ! cmd = TOSH_HUMIDITY_ADDR; ! break; ! default: ! case POWER_OFF: ! return; ! ! }; ! currentCMD = cmd; cmd &= 0x1f; HUMIDITY_INT_DISABLE(); *************** *** 194,212 **** reset(); atomic errornum = 2; ! if ((CMD == TOSH_HUMIDITY_ADDR) && (humerror == TRUE)) post signalHumError(); ! else if ((CMD == TOSH_HUMIDTEMP_ADDR) && (temperror == TRUE)) post signalTempError(); ! return 0; } TOSH_wait_250ns(); HUMIDITY_CLEAR_CLOCK(); ! if((CMD == TOSH_HUMIDITY_ADDR) || (CMD == TOSH_HUMIDTEMP_ADDR) ){ ! if ((CMD == TOSH_HUMIDITY_ADDR) && (humerror == TRUE)) { SODbg(DBG_USR2, "TempHumM.processCommand: cmd complete, starting timer for measurement \n"); atomic timeout = 0; call Timer.start(TIMER_REPEAT, HUMIDITY_TIMEOUT_MS); } ! else if ((CMD == TOSH_HUMIDTEMP_ADDR) && (temperror == TRUE)) { atomic timeout = 0; call Timer.start(TIMER_REPEAT, HUMIDITY_TIMEOUT_MS); --- 216,234 ---- reset(); atomic errornum = 2; ! if ((currentCMD == TOSH_HUMIDITY_ADDR) && (humerror == TRUE)) post signalHumError(); ! else if ((currentCMD == TOSH_HUMIDTEMP_ADDR) && (temperror == TRUE)) post signalTempError(); ! return; } TOSH_wait_250ns(); HUMIDITY_CLEAR_CLOCK(); ! if((currentCMD == TOSH_HUMIDITY_ADDR) || (currentCMD == TOSH_HUMIDTEMP_ADDR) ){ ! if ((currentCMD == TOSH_HUMIDITY_ADDR) && (humerror == TRUE)) { SODbg(DBG_USR2, "TempHumM.processCommand: cmd complete, starting timer for measurement \n"); atomic timeout = 0; call Timer.start(TIMER_REPEAT, HUMIDITY_TIMEOUT_MS); } ! else if ((currentCMD == TOSH_HUMIDTEMP_ADDR) && (temperror == TRUE)) { atomic timeout = 0; call Timer.start(TIMER_REPEAT, HUMIDITY_TIMEOUT_MS); *************** *** 215,219 **** HumidityIntEnable(); } ! return 1; } --- 237,241 ---- HumidityIntEnable(); } ! return; } *************** *** 237,241 **** sbi(EICRA, ISC31); reset(); ! processCommand(TOSH_HUMIDITY_RESET); return SUCCESS; } --- 259,263 ---- sbi(EICRA, ISC31); reset(); ! post processCommand(); return SUCCESS; } *************** *** 356,364 **** async command result_t TempSensor.getData() { ! atomic{ ! if(state!= READY ) reset(); ! state=TEMP_MEASUREMENT; ! processCommand(TOSH_HUMIDTEMP_ADDR); ! } return SUCCESS; } --- 378,401 ---- async command result_t TempSensor.getData() { ! char oldState; ! atomic { ! oldState = state; ! if (state == READY) { ! state = TEMP_MEASUREMENT; ! }; ! }; ! if (oldState != READY) { ! // ??? the original code would call reset() at this point and ! // go forward. Now that processCommand() is a task and called ! // synchronously doing a reset at this point has the risk ! // that the processCommand task will be invoked many times ! // possibly inducing a stack or task queue overflow. This ! // code has the potential issue that it never does a reset ! // and locks up internally. ! SODbg(DBG_USR2, "TempHumM.getData: busy when trying to get temperature data \n"); ! return FAIL; ! }; ! SODbg(DBG_USR2, "TempHumM.getData: starting to get temperature data \n"); ! post processCommand(); return SUCCESS; } *************** *** 366,376 **** async command result_t HumSensor.getData() { ! atomic{ ! if(state!= READY ) reset(); ! SODbg(DBG_USR2, "TempHumM.getData: starting to get humidity data \n"); ! state=HUM_MEASUREMENT; ! processCommand(TOSH_HUMIDITY_ADDR); ! } ! return SUCCESS; } --- 403,427 ---- async command result_t HumSensor.getData() { ! char oldState; ! atomic { ! oldState = state; ! if (state == READY) { ! state = HUM_MEASUREMENT; ! }; ! }; ! if (oldState != READY) { ! // ??? the original code would call reset() at this point and ! // go forward. Now that processCommand() is a task and called ! // synchronously doing a reset at this point has the risk ! // that the processCommand task will be invoked many times ! // possibly inducing a stack or task queue overflow. This ! // code has the potential issue that it never does a reset ! // and locks up internally. ! SODbg(DBG_USR2, "TempHumM.getData: busy when trying to get humidity data \n"); ! return FAIL; ! }; ! SODbg(DBG_USR2, "TempHumM.getData: starting to get humidity data \n"); ! post processCommand(); ! return SUCCESS; } |