[Firebug-cvs] mts400/sensors/i2c wbswitch_debug.h,NONE,1.1 MicaWbSwitchM.nc,1.1,1.2
Brought to you by:
doolin
From: <do...@us...> - 2003-11-15 00:44:54
|
Update of /cvsroot/firebug/mts400/sensors/i2c In directory sc8-pr-cvs1:/tmp/cvs-serv24882/i2c Modified Files: MicaWbSwitchM.nc Added Files: wbswitch_debug.h Log Message: Added a debugging header specifically for the switch component. --- NEW FILE: wbswitch_debug.h --- #include <stdarg.h> //#include <stdio.h> //#define SCRATCH 16 #define SCRATCH 64 #define BUF_LEN 256 char debugbuf[BUF_LEN]; //init comm port (56K baud, mica2 only, use 19K baud for mica2dot, mica....) for debug // call this from startup routine void init_debug(){ outp(0,UBRR0H); outp(15, UBRR0L); //set baud rate outp((1<<U2X),UCSR0A); // Set UART double speed outp(((1 << UCSZ1) | (1 << UCSZ0)) , UCSR0C); // Set frame format: 8 data-bits, 1 stop-bit inp(UDR0); outp((1 << TXEN) ,UCSR0B); // Enable uart reciever and transmitter } //init comm port (19K baud) for mica2dot for debug // call this from startup routine void init_debug_mica2dot(){ outp(0,UBRR0H); // Set baudrate to 19.2 KBps outp(12, UBRR0L); outp(0,UCSR0A); // Disable U2X and MPCM outp(((1 << UCSZ1) | (1 << UCSZ0)) , UCSR0C); inp(UDR0); outp((1 << TXEN) ,UCSR0B); } // output a char to the uart void UARTPutChar(char c) { if (c == '\n') UARTPutChar('\r'); loop_until_bit_is_set(UCSR0A, UDRE); outb(UDR0,c); } void writedebug() { int i = 0; UARTPutChar('\n'); //write a carriage return 1st while (debugbuf[i] != '\n') UARTPutChar(debugbuf[i++]); // UARTPutChar('\n'); } #define SPRINTF //use this sprintf function #ifdef SPRINTF int sprintf(uint8_t *buf, const uint8_t *format, ...) /* simplified sprintf */ { uint8_t scratch[SCRATCH]; uint8_t format_flag; uint16_t u_val=0, base; uint8_t *ptr; va_list ap; bool b_ChkForNegInt = FALSE; va_start (ap, format); for (;;){ while ((format_flag = *format++) != '%'){ /* Until '%' or '\0' */ if (!format_flag){va_end (ap); return (0);} *buf = format_flag; buf++; *buf=0; } b_ChkForNegInt = FALSE; switch (format_flag = *format++){ case 'c': format_flag = va_arg(ap,int); default: *buf = format_flag; buf++; *buf=0; continue; case 'S': case 's': ptr = va_arg(ap,char *); strcat(buf, ptr); continue; case 'o': base = 8; *buf = '0'; buf++; *buf=0; goto CONVERSION_LOOP; case 'i': b_ChkForNegInt = TRUE; // if (((int)u_val) < 0){ // u_val = - u_val; // *buf = '-'; buf++; *buf=0; // } /* no break -> run into next case */ case 'u': base = 10; goto CONVERSION_LOOP; case 'x': base = 16; CONVERSION_LOOP: u_val = va_arg(ap,int); if (b_ChkForNegInt){ if (((int)u_val) < 0){ u_val = - u_val; *buf = '-'; buf++; *buf=0; } } ptr = scratch + SCRATCH; *--ptr = 0; do { char ch = u_val % base + '0'; if (ch > '9') ch += 'a' - '9' - 1; *--ptr = ch; u_val /= base; } while (u_val); strcat(buf, ptr); buf += strlen(ptr); } } } #endif #define SO_NO_DEBUG 0 #if WB_DEBUG #define WBDbg(__x,__args...) { \ char bStatus; \ if(__x != SO_NO_DEBUG){ \ bStatus=bit_is_set(SREG,7); \ cli(); \ sprintf(debugbuf,__args); \ writedebug(); \ if (bStatus) sei(); \ } \ } #else #define WBDbg(__x,__args...) #endif Index: MicaWbSwitchM.nc =================================================================== RCS file: /cvsroot/firebug/mts400/sensors/i2c/MicaWbSwitchM.nc,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MicaWbSwitchM.nc 12 Nov 2003 23:52:42 -0000 1.1 --- MicaWbSwitchM.nc 15 Nov 2003 00:44:51 -0000 1.2 *************** *** 68,77 **** */ ! module MicaWbSwitchM ! { provides { interface StdControl; interface Switch[uint8_t id]; } uses { interface StdControl as I2CPacketControl; --- 68,81 ---- */ ! ! ! ! module MicaWbSwitchM { ! provides { interface StdControl; interface Switch[uint8_t id]; } + uses { interface StdControl as I2CPacketControl; *************** *** 80,88 **** } } - implementation - { ! enum { GET_SWITCH, SET_SWITCH, SET_SWITCH_ALL, ! SET_SWITCH_GET, IDLE}; char sw_state; /* current state of the switch */ --- 84,99 ---- } } ! ! implementation { ! ! #define WB_DEBUG 0 ! #include "wbswitch_debug.h" ! ! enum { GET_SWITCH = 0, ! SET_SWITCH, ! SET_SWITCH_ALL, ! SET_SWITCH_GET, ! IDLE}; char sw_state; /* current state of the switch */ *************** *** 93,112 **** 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); --- 104,138 ---- command result_t StdControl.init() { ! ! state = IDLE; ! WBDbg(DBG_USR2, "MicaWBSwitch.StdControl.init() state: %i\n,",state); return call I2CPacketControl.init(); } command result_t StdControl.start() { + + WBDbg(DBG_USR2, "MicaWBSwitch.StdControl.start() state: %i\n",state); + return call I2CPacketControl.start(); } command result_t StdControl.stop() { + + WBDbg(DBG_USR2, "MicaWBSwitch.StdControl.stop() state: %i\n",state); + return call I2CPacketControl.stop(); } + command 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 call I2CSwitch0.readPacket(1, 0x01); *************** *** 118,122 **** --- 144,152 ---- } + command 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) { *************** *** 134,137 **** --- 164,170 ---- command result_t Switch.setAll[uint8_t id](char l_value) { + + WBDbg(DBG_USR2, "MicaWBSwitch.Switch.setAll() state: %i\n",state); + if (state == IDLE) { *************** *** 148,151 **** --- 181,188 ---- event result_t I2CSwitch0.writePacketDone(bool result) { + + + WBDbg(DBG_USR2, "MicaWBSwitch.I2CSwitch0.writePacketDone() state: %i\n",state); + if (state == SET_SWITCH) { *************** *** 161,164 **** --- 198,204 ---- event result_t I2CSwitch1.writePacketDone(bool result) { + + WBDbg(DBG_USR2, "MicaWBSwitch.I2CSwitch1.writePacketDone() state: %i\n",state); + if (state == SET_SWITCH) { *************** *** 174,179 **** event result_t I2CSwitch0.readPacketDone(char length, char* data) { ! if (state == GET_SWITCH) ! { if (length != 1) { --- 214,223 ---- event 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) { *************** *** 188,191 **** --- 232,236 ---- } } + if (state == SET_SWITCH_GET) { *************** *** 240,243 **** --- 285,292 ---- event result_t I2CSwitch1.readPacketDone(char length, char* data) { + + + WBDbg(DBG_USR2, "MicaWBSwitch.I2CSwitch1.readPacketDone() state: %i\n",state); + if (state == GET_SWITCH) { *************** *** 307,310 **** --- 356,361 ---- default event result_t Switch.setDone[uint8_t id](bool result) { + WBDbg(DBG_USR2, "MicaWBSwitch.Switch.setDone() id: %i\n",id); + return SUCCESS; } *************** *** 312,315 **** --- 363,367 ---- default event result_t Switch.setAllDone[uint8_t id](bool result) { + WBDbg(DBG_USR2, "MicaWBSwitch.Switch.setAllDone() id: %i\n",id); return SUCCESS; } *************** *** 317,320 **** --- 369,373 ---- default event result_t Switch.getDone[uint8_t id](char l_value) { + WBDbg(DBG_USR2, "MicaWBSwitch.Switch.getDone() id: %i\n",id); return SUCCESS; } |