[Firebug-cvs] dave .cvsignore,NONE,1.1 bus.c,NONE,1.1 switch.c,NONE,1.1
Brought to you by:
doolin
From: <do...@us...> - 2003-11-15 22:28:39
|
Update of /cvsroot/firebug/dave In directory sc8-pr-cvs1:/tmp/cvs-serv20546 Added Files: .cvsignore bus.c switch.c Log Message: Ported some nesc code to c for doing control of flow experiments. --- NEW FILE: .cvsignore --- *.o *.exe --- NEW FILE: bus.c --- // uint8_t state; // uint8_t busid; unsigned char state; unsigned char busid; typedef unsigned char uint8_t; typedef unsigned int result_t; #define SUCCESS 1 #define FAIL 0 #define FALSE 0 #define TRUE !FALSE typedef unsigned int bool; enum { IDLE = 0, BUSY, OFF }; int uniqueCount(char *interfaces) { return 0; } void busReleased() { uint8_t i; // tell everyone the bus has been released for (i = 0; i < uniqueCount("BusArbitration"); i++) { if (state == IDLE) { // BusArbitration_busFree[i](); } } } result_t StdControl_init() { state = OFF; return SUCCESS; } result_t StdControl_start() { if (state == OFF) { state = IDLE; return SUCCESS; } return FAIL; } result_t StdControl_stop() { if (state == IDLE) { state = OFF; return SUCCESS; } return FAIL; } result_t BusArbitration_getBus(uint8_t id) { bool gotbus = FALSE; // atomic { if (state == IDLE) { state = BUSY; gotbus = TRUE; busid = id; } // } if (gotbus) return SUCCESS; return FAIL; } result_t BusArbitration_releaseBus(uint8_t id) { if ((state == BUSY) && (busid == id)) { state = IDLE; } busReleased(); return SUCCESS; } result_t BusArbitration_busFree(uint8_t id) { return SUCCESS; } int main(int argc, char **argv) { return 0; } --- NEW FILE: switch.c --- /* * -*- Mode: C; c-basic-indent: 3; indent-tabs-mode: nil -*- */ #include <stdio.h> #define SUCCESS 1 enum { GET_SWITCH = 0, 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; typedef int result_t; #define DBG_USR2 stdout #define WBDbg fprintf #if 0 result_t StdControl_init() { state = IDLE; WBDbg(DBG_USR2, "MicaWBSwitch.StdControl.init() state: %i\n,", state); return I2CPacketControl_init(); } result_t StdControl_start() { WBDbg(DBG_USR2, "MicaWBSwitch.StdControl.start() state: %i\n", state); return I2CPacketControl_start(); } result_t StdControl_stop() { WBDbg(DBG_USR2, "MicaWBSwitch.StdControl.stop() state: %i\n", state); return I2CPacketControl_stop(); } result_t Switch_get(uint8_t id) { WBDbg(DBG_USR2, "MicaWBSwitch.Switch.get() state: %i\n", state); if (state == IDLE) { state = GET_SWITCH; WBDbg(DBG_USR2, "MicaWBSwitch.Switch.get() state: %i\n", state); if (id == 0) return I2CSwitch0.readPacket(1, 0x01); else if (id == 1) return I2CSwitch1.readPacket(1, 0x01); } state = IDLE; return FAIL; } result_t Switch_set (uint8_t id, char l_position, char l_value) { WBDbg(DBG_USR2, "MicaWBSwitch.Switch.set() state: %i\n", state); if (state == IDLE) { state = SET_SWITCH_GET; value = l_value; position = l_position; if (id == 0) return I2CSwitch0_readPacket(1, 0x01); else if (id == 1) return I2CSwitch1_readPacket(1, 0x01); } state = IDLE; return FAIL; } result_t Switch_setAll[uint8_t id] (char l_value) { WBDbg(DBG_USR2, "MicaWBSwitch.Switch.setAll() state: %i\n", state); if (state == IDLE) { state = SET_SWITCH_ALL; sw_state = l_value; if (id == 0) return I2CSwitch0.writePacket(1, (char *) (&sw_state), 0x01); else if (id == 1) return I2CSwitch1.writePacket(1, (char *) (&sw_state), 0x01); } state = IDLE; return FAIL; } result_t I2CSwitch0_writePacketDone(bool result) { WBDbg(DBG_USR2, "MicaWBSwitch.I2CSwitch0.writePacketDone() state: %i\n", state); 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; } result_t I2CSwitch1_writePacketDone(bool result) { WBDbg(DBG_USR2, "MicaWBSwitch.I2CSwitch1.writePacketDone() state: %i\n", state); 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; } result_t I2CSwitch0_readPacketDone(char length, char *data) { WBDbg(DBG_USR2, "MicaWBSwitch.I2CSwitch0.readPacketDone() state: %i\n", state); 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; I2CSwitch0_writePacket(1, (char *) &sw_state, 0x01); return SUCCESS; } return SUCCESS; } #endif result_t I2CSwitch1_readPacketDone(char length, char *data) { WBDbg(DBG_USR2, "MicaWBSwitch.I2CSwitch1.readPacketDone() state: %i\n", state); 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; //I2CSwitch1.writePacket(1, (char *) &sw_state, 0x01); return SUCCESS; } return SUCCESS; } #if 0 result_t Switch_setDone[uint8_t id] (bool result) { WBDbg(DBG_USR2, "MicaWBSwitch.Switch.setDone() id: %i\n", id); return SUCCESS; } result_t Switch_setAllDone[uint8_t id] (bool result) { WBDbg(DBG_USR2, "MicaWBSwitch.Switch.setAllDone() id: %i\n", id); return SUCCESS; } result_t Switch_getDone[uint8_t id] (char l_value) { WBDbg(DBG_USR2, "MicaWBSwitch.Switch.getDone() id: %i\n", id); return SUCCESS; } #endif int main(int argc, char **argv) { int length = 0; /** Garbage value to get it to compile. */ char data[] = {"asdfsg"}; I2CSwitch1_readPacketDone(length, data); return 0; } |