[Firebug-cvs] fireboard/beta/tos/sensorboards/mts400 MicaWbSwitchM.nc,1.2,1.3
Brought to you by:
doolin
From: Michael N. <mne...@us...> - 2005-09-08 23:39:13
|
Update of /cvsroot/firebug/fireboard/beta/tos/sensorboards/mts400 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19492 Modified Files: MicaWbSwitchM.nc Log Message: Add debugging printouts Index: MicaWbSwitchM.nc =================================================================== RCS file: /cvsroot/firebug/fireboard/beta/tos/sensorboards/mts400/MicaWbSwitchM.nc,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** MicaWbSwitchM.nc 24 May 2005 21:57:34 -0000 1.2 --- MicaWbSwitchM.nc 8 Sep 2005 23:39:05 -0000 1.3 *************** *** 68,320 **** module MicaWbSwitchM { ! provides { ! interface StdControl; ! interface Switch[uint8_t id]; ! } ! uses { ! interface StdControl as I2CPacketControl; ! interface I2CPacket as I2CSwitch0; ! interface I2CPacket as I2CSwitch1; ! } } implementation { ! enum { GET_SWITCH, SET_SWITCH, SET_SWITCH_ALL, ! SET_SWITCH_GET, IDLE}; ! char sw_state; /* current state of the switch */ ! char state; /* current state of the i2c request */ ! char addr; /* destination address */ ! char position; ! char value; ! command result_t StdControl.init() { ! state = IDLE; ! return call I2CPacketControl.init(); ! } ! command result_t StdControl.start() { ! return call I2CPacketControl.start(); ! } ! command result_t StdControl.stop() { ! return call I2CPacketControl.stop(); ! } ! command result_t Switch.get[uint8_t id]() { ! if (state == IDLE) ! { ! state = GET_SWITCH; ! if (id == 0) ! return call I2CSwitch0.readPacket(1, 0x01); ! else if (id == 1) ! return call I2CSwitch1.readPacket(1, 0x01); ! } ! state = IDLE; ! return FAIL; ! } ! command result_t Switch.set[uint8_t id](char l_position, char l_value) { ! if (state == IDLE) ! { ! state = SET_SWITCH_GET; ! value = l_value; ! position = l_position; ! if (id == 0) ! return call I2CSwitch0.readPacket(1,0x01); ! else if (id == 1) ! return call I2CSwitch1.readPacket(1,0x01); ! } ! state = IDLE; ! return FAIL; ! } ! command result_t Switch.setAll[uint8_t id](char l_value) { ! if (state == IDLE) ! { ! state = SET_SWITCH_ALL; ! sw_state = l_value; ! if (id == 0) ! return call I2CSwitch0.writePacket(1, (char*)(&sw_state), 0x01); ! else if (id == 1) ! return call I2CSwitch1.writePacket(1, (char*)(&sw_state), 0x01); ! } ! state = IDLE; ! return FAIL; ! } ! event result_t I2CSwitch0.writePacketDone(bool result) { ! if (state == SET_SWITCH) ! { ! state = IDLE; ! signal Switch.setDone[0](result); ! } ! else if (state == SET_SWITCH_ALL) { ! state = IDLE; ! signal Switch.setAllDone[0](result); ! } ! return SUCCESS; ! } ! event result_t I2CSwitch1.writePacketDone(bool result) { ! if (state == SET_SWITCH) ! { ! state = IDLE; ! signal Switch.setDone[1](result); ! } ! else if (state == SET_SWITCH_ALL) { ! state = IDLE; ! signal Switch.setAllDone[1](result); ! } ! return SUCCESS; ! } ! event result_t I2CSwitch0.readPacketDone(char length, char* data) { ! if (state == GET_SWITCH) ! { ! if (length != 1) { ! state = IDLE; ! signal Switch.getDone[0](0); ! return SUCCESS; ! } ! else { ! state = IDLE; ! signal Switch.getDone[0](data[0]); ! return SUCCESS; } ! } ! if (state == SET_SWITCH_GET) ! { ! if (length != 1) { ! state = IDLE; ! signal Switch.getDone[0](0); ! return SUCCESS; ! } ! sw_state = data[0]; ! if (position == 1) { ! sw_state = sw_state & 0xFE; ! sw_state = sw_state | value; ! } ! if (position == 2) { ! sw_state = sw_state & 0xFD; ! sw_state = sw_state | (value << 1); ! } ! if (position == 3) { ! sw_state = sw_state & 0xFB; ! sw_state = sw_state | (value << 2); ! } ! if (position == 4) { ! sw_state = sw_state & 0xF7; ! sw_state = sw_state | (value << 3); ! } ! if (position == 5) { ! sw_state = sw_state & 0xEF; ! sw_state = sw_state | (value << 4); ! } ! if (position == 6) { ! sw_state = sw_state & 0xDF; ! sw_state = sw_state | (value << 5); ! } ! if (position == 7) { ! sw_state = sw_state & 0xBF; ! sw_state = sw_state | (value << 6); ! } ! if (position == 8) { ! sw_state = sw_state & 0x7F; ! sw_state = sw_state | (value << 7); ! } ! data[0] = sw_state; ! state = SET_SWITCH; ! call I2CSwitch0.writePacket(1, (char*)&sw_state, 0x01); return SUCCESS; ! } ! return SUCCESS; ! } ! event result_t I2CSwitch1.readPacketDone(char length, char* data) { ! if (state == GET_SWITCH) ! { ! if (length != 1) { ! state = IDLE; ! signal Switch.getDone[1](0); ! return SUCCESS; ! } ! else { ! state = IDLE; ! signal Switch.getDone[1](data[0]); ! return SUCCESS; } ! } ! if (state == SET_SWITCH_GET) ! { ! if (length != 1) { ! state = IDLE; ! signal Switch.getDone[1](0); ! return SUCCESS; ! } ! sw_state = data[0]; ! if (position == 1) { ! sw_state = sw_state & 0xFE; ! sw_state = sw_state | value; ! } ! if (position == 2) { ! sw_state = sw_state & 0xFD; ! sw_state = sw_state | (value << 1); ! } ! if (position == 3) { ! sw_state = sw_state & 0xFB; ! sw_state = sw_state | (value << 2); ! } ! if (position == 4) { ! sw_state = sw_state & 0xF7; ! sw_state = sw_state | (value << 3); ! } ! if (position == 5) { ! sw_state = sw_state & 0xEF; ! sw_state = sw_state | (value << 4); ! } ! if (position == 6) { ! sw_state = sw_state & 0xDF; ! sw_state = sw_state | (value << 5); ! } ! if (position == 7) { ! sw_state = sw_state & 0xBF; ! sw_state = sw_state | (value << 6); ! } ! if (position == 8) { ! sw_state = sw_state & 0x7F; ! sw_state = sw_state | (value << 7); ! } ! data[0] = sw_state; ! state = SET_SWITCH; ! call I2CSwitch1.writePacket(1, (char*)&sw_state, 0x01); return SUCCESS; ! } ! return SUCCESS; ! } ! default event result_t Switch.setDone[uint8_t id](bool result) ! { ! return SUCCESS; ! } ! default event result_t Switch.setAllDone[uint8_t id](bool result) ! { ! return SUCCESS; ! } ! default event result_t Switch.getDone[uint8_t id](char l_value) ! { ! return SUCCESS; ! } } --- 68,371 ---- module MicaWbSwitchM { ! provides { ! interface StdControl; ! interface Switch[uint8_t id]; ! } ! uses { ! interface StdControl as I2CPacketControl; ! interface I2CPacket as I2CSwitch0; ! interface I2CPacket as I2CSwitch1; ! } } implementation { ! #include "SODebug.h" ! enum { ! GET_SWITCH, ! SET_SWITCH, ! SET_SWITCH_ALL, ! SET_SWITCH_GET, ! IDLE ! } I2Cstate; /* current state of the i2c request */ ! char sw_state; /* current state of the switch */ ! char position; ! char value; ! command result_t StdControl.init() { ! I2Cstate = IDLE; ! // SODbg(DBG_USR2,"I2C switch.init\n"); ! return call I2CPacketControl.init(); ! } ! command result_t StdControl.start() { ! // SODbg(DBG_USR2,"I2C switch.start\n"); ! return call I2CPacketControl.start(); ! } ! command result_t StdControl.stop() { ! // SODbg(DBG_USR2,"I2C switch.stop\n"); ! return call I2CPacketControl.stop(); ! } ! command result_t Switch.get[uint8_t id]() { ! if (I2Cstate == IDLE) ! { ! I2Cstate = GET_SWITCH; ! if (id == 0) ! return call I2CSwitch0.readPacket(1, 0x01); ! else if (id == 1) ! return call I2CSwitch1.readPacket(1, 0x01); ! } ! SODbg(DBG_USR2,"I2C switch.get %d FAIL\n",id); ! I2Cstate = IDLE; ! return FAIL; ! } ! command result_t Switch.set[uint8_t id](char l_position, char l_value) { ! if (I2Cstate == IDLE) { ! int count = 0; ! I2Cstate = SET_SWITCH_GET; ! // SODbg(DBG_USR2,"I2C switch.set[%d] Position:%d Value:%d\n",(int)id,(int)l_position,(int)l_value); ! value = l_value; ! position = l_position; ! while (1) { ! result_t result; ! switch (id) { ! case 0: ! result = call I2CSwitch0.readPacket(1,0x01); ! break; ! case 1: ! result = call I2CSwitch1.readPacket(1,0x01); ! break; ! default: ! return FAIL; ! }; ! if (result == SUCCESS) break; ! count += 1; ! if (count > 30000) { ! SODbg(DBG_USR2,"I2C switch.set[%d] forcing I2C init\n",(int)id); ! call I2CPacketControl.init(); ! count = 0; ! }; ! }; ! return SUCCESS; ! }; ! SODbg(DBG_USR2,"I2cSwitch.set[%d] FAIL P:%d V:%d\n",id,l_position,l_value); ! I2Cstate = IDLE; ! return FAIL; ! } ! command result_t Switch.setAll[uint8_t id](char l_value) { ! if (I2Cstate == IDLE) { ! int count = 0; ! I2Cstate = SET_SWITCH_ALL; ! sw_state = l_value; ! while (1) { ! result_t result; ! switch (id) { ! case 0: ! result = call I2CSwitch0.writePacket(1, (char*)(&sw_state), 0x01); ! break; ! case 1: ! result = call I2CSwitch1.writePacket(1, (char*)(&sw_state), 0x01); ! break; ! default: ! return FAIL; ! }; ! if (result == SUCCESS) break; ! count += 1; ! if (count > 30000) { ! SODbg(DBG_USR2,"I2C switch.setAll[%d] forcing I2C init\n",(int)id); ! call I2CPacketControl.init(); ! count = 0; ! }; ! }; ! return SUCCESS; ! }; ! SODbg(DBG_USR2,"I2cSwitch.setAll %d FAIL Value: %d\n",id,l_value); ! I2Cstate = IDLE; ! return FAIL; ! } ! event result_t I2CSwitch0.writePacketDone(bool result) { ! if (I2Cstate == SET_SWITCH) { ! I2Cstate = IDLE; ! signal Switch.setDone[0](result); ! } else if (I2Cstate == SET_SWITCH_ALL) { ! I2Cstate = IDLE; ! signal Switch.setAllDone[0](result); ! } else { ! SODbg(DBG_USR2,"Unusual I2C 0 writePacketDone: %d state: %d\n",(int)result,(int)I2Cstate); ! }; ! return SUCCESS; ! } ! event result_t I2CSwitch1.writePacketDone(bool result) { ! if (I2Cstate == SET_SWITCH) { ! I2Cstate = IDLE; ! signal Switch.setDone[1](result); ! } else if (I2Cstate == SET_SWITCH_ALL) { ! I2Cstate = IDLE; ! signal Switch.setAllDone[1](result); ! } else { ! SODbg(DBG_USR2,"Unusual I2C 1 writePacketDone: %d state: %d\n",(int)result,(int)I2Cstate); ! }; ! return SUCCESS; ! } ! ! event result_t I2CSwitch0.readPacketDone(char length, char* data) { ! // SODbg(DBG_USR2,"I2C 0 readPacketDone: length %d state: %d\n",(int)length,(int)I2Cstate); ! if (I2Cstate == GET_SWITCH) { ! if (length != 1) ! { ! I2Cstate = IDLE; ! signal Switch.getDone[0](0); ! return SUCCESS; ! } ! else { ! I2Cstate = IDLE; ! signal Switch.getDone[0](data[0]); ! return SUCCESS; ! } } ! if (I2Cstate == SET_SWITCH_GET) { ! if (length != 1) ! { ! I2Cstate = IDLE; ! signal Switch.getDone[0](0); ! return SUCCESS; ! } ! sw_state = data[0]; ! if (position == 1) { ! sw_state = sw_state & 0xFE; ! sw_state = sw_state | value; ! } ! if (position == 2) { ! sw_state = sw_state & 0xFD; ! sw_state = sw_state | (value << 1); ! } ! if (position == 3) { ! sw_state = sw_state & 0xFB; ! sw_state = sw_state | (value << 2); ! } ! if (position == 4) { ! sw_state = sw_state & 0xF7; ! sw_state = sw_state | (value << 3); ! } ! if (position == 5) { ! sw_state = sw_state & 0xEF; ! sw_state = sw_state | (value << 4); ! } ! if (position == 6) { ! sw_state = sw_state & 0xDF; ! sw_state = sw_state | (value << 5); ! } ! if (position == 7) { ! sw_state = sw_state & 0xBF; ! sw_state = sw_state | (value << 6); ! } ! if (position == 8) { ! sw_state = sw_state & 0x7F; ! sw_state = sw_state | (value << 7); ! } ! data[0] = sw_state; ! I2Cstate = SET_SWITCH; ! call I2CSwitch0.writePacket(1, (char*)&sw_state, 0x01); ! return SUCCESS; ! } return SUCCESS; ! } ! event result_t I2CSwitch1.readPacketDone(char length, char* data) { ! // SODbg(DBG_USR2,"I2C 1 readPacketDone: length %d state: %d\n",(int)length,(int)I2Cstate); ! if (I2Cstate == GET_SWITCH) { ! if (length != 1) ! { ! I2Cstate = IDLE; ! signal Switch.getDone[1](0); ! return SUCCESS; ! } ! else { ! I2Cstate = IDLE; ! signal Switch.getDone[1](data[0]); ! return SUCCESS; ! } } ! if (I2Cstate == SET_SWITCH_GET) { ! if (length != 1) ! { ! I2Cstate = IDLE; ! signal Switch.getDone[1](0); ! return SUCCESS; ! } ! sw_state = data[0]; ! if (position == 1) { ! sw_state = sw_state & 0xFE; ! sw_state = sw_state | value; ! } ! if (position == 2) { ! sw_state = sw_state & 0xFD; ! sw_state = sw_state | (value << 1); ! } ! if (position == 3) { ! sw_state = sw_state & 0xFB; ! sw_state = sw_state | (value << 2); ! } ! if (position == 4) { ! sw_state = sw_state & 0xF7; ! sw_state = sw_state | (value << 3); ! } ! if (position == 5) { ! sw_state = sw_state & 0xEF; ! sw_state = sw_state | (value << 4); ! } ! if (position == 6) { ! sw_state = sw_state & 0xDF; ! sw_state = sw_state | (value << 5); ! } ! if (position == 7) { ! sw_state = sw_state & 0xBF; ! sw_state = sw_state | (value << 6); ! } ! if (position == 8) { ! sw_state = sw_state & 0x7F; ! sw_state = sw_state | (value << 7); ! } ! data[0] = sw_state; ! I2Cstate = SET_SWITCH; ! call I2CSwitch1.writePacket(1, (char*)&sw_state, 0x01); ! return SUCCESS; ! } return SUCCESS; ! } ! default event result_t Switch.setDone[uint8_t id](bool result) ! { ! // SODbg(DBG_USR2,"I2C default SetDone %d\n",id); ! return SUCCESS; ! } ! default event result_t Switch.setAllDone[uint8_t id](bool result) ! { ! // SODbg(DBG_USR2,"I2C default setAllDone %d\n",id); ! return SUCCESS; ! } ! default event result_t Switch.getDone[uint8_t id](char l_value) ! { ! // SODbg(DBG_USR2,"I2C default setDone %d\n",id); ! return SUCCESS; ! } } |