From c9862370894e308212d83fcd27437e867d9e1592 Mon Sep 17 00:00:00 2001 From: Thomas Watteyne Date: Mon, 29 Aug 2016 15:56:31 +0200 Subject: [PATCH 01/99] FW-540. Working openserial with serialTesterCli app. Integration in state machine missing. --- .gitignore | 1 + bsp/boards/telosb/board_info.h | 7 +- bsp/boards/telosb/debugpins.c | 28 +- bsp/boards/telosb/uart.c | 105 ++-- bsp/boards/uart.h | 9 + drivers/common/openserial.c | 502 +++++++++--------- drivers/common/openserial.h | 57 +- .../02drv_openserial/02drv_openserial.c | 30 +- 8 files changed, 404 insertions(+), 335 deletions(-) diff --git a/.gitignore b/.gitignore index 5896565bb5..030e729914 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ settings /projects/telosb/00std_xon_xoff/path.txt /projects/telosb/03oos_openwsn/path.txt /projects/telosb/02drv_openserial/path.txt +/projects/telosb/01bsp_uart/path.txt diff --git a/bsp/boards/telosb/board_info.h b/bsp/boards/telosb/board_info.h index 58374b0cf0..7d17fd7f86 100644 --- a/bsp/boards/telosb/board_info.h +++ b/bsp/boards/telosb/board_info.h @@ -28,8 +28,11 @@ to this board. // other #define INTERRUPT_DECLARATION() __istate_t s; #define DISABLE_INTERRUPTS() s = __get_interrupt_state(); \ - __disable_interrupt(); - #define ENABLE_INTERRUPTS() __set_interrupt_state(s); + __disable_interrupt(); \ + debugpins_intdisabled_set(); + #define ENABLE_INTERRUPTS() debugpins_intdisabled_clr(); \ + __set_interrupt_state(s); + #endif //===== timer diff --git a/bsp/boards/telosb/debugpins.c b/bsp/boards/telosb/debugpins.c index 7a5eec0a07..fdba135322 100644 --- a/bsp/boards/telosb/debugpins.c +++ b/bsp/boards/telosb/debugpins.c @@ -16,14 +16,15 @@ //=========================== public ========================================== void debugpins_init() { - P6DIR |= 0x40; // frame [P6.6] - P6DIR |= 0x80; // slot [P6.7] - P2DIR |= 0x08; // fsm [P2.3] - P2DIR |= 0x40; // task [P2.6] - P6DIR |= 0x01; // isr [P6.0] - P3DIR |= 0x20; // isruarttx [P3.5] - P3DIR |= 0x10; // isruartrx [P3.4] - P6DIR |= 0x02; // radio [P6.1] + P6DIR |= 0x40; // frame [P6.6] + P6DIR |= 0x80; // slot [P6.7] + P2DIR |= 0x08; // fsm [P2.3] + P2DIR |= 0x40; // task [P2.6] + P6DIR |= 0x01; // isr [P6.0] + P3DIR |= 0x20; // isruarttx [P3.5] + P3DIR |= 0x10; // isruartrx [P3.4] + P6DIR |= 0x02; // radio [P6.1] + P6DIR |= 0x08; // intdisabled [P6.3] } // P6.6 @@ -114,4 +115,15 @@ void debugpins_radio_set() { P6OUT |= 0x02; } +// P6.3 +void debugpins_intdisabled_toggle() { + P6OUT ^= 0x08; +} +void debugpins_intdisabled_clr() { + P6OUT &= ~0x08; +} +void debugpins_intdisabled_set() { + P6OUT |= 0x08; +} + //=========================== private ========================================= diff --git a/bsp/boards/telosb/uart.c b/bsp/boards/telosb/uart.c index 62d610b3c2..a39a844b8d 100644 --- a/bsp/boards/telosb/uart.c +++ b/bsp/boards/telosb/uart.c @@ -13,8 +13,10 @@ //=========================== variables ======================================= typedef struct { - uart_tx_cbt txCb; - uart_rx_cbt rxCb; + uart_tx_cbt txCb; + uart_rx_cbt rxCb; + bool fXonXoffEscaping; + uint8_t xonXoffEscapedByte; } uart_vars_t; uart_vars_t uart_vars; @@ -24,57 +26,73 @@ uart_vars_t uart_vars; //=========================== public ========================================== void uart_init() { - P3SEL |= 0xc0; // P3.6,7 = UART1TX/RX - - UCTL1 = SWRST; // hold UART1 module in reset - UCTL1 |= CHAR; // 8-bit character - - /* - // 9600 baud, clocked from 32kHz ACLK - UTCTL1 |= SSEL0; // clocking from ACLK - UBR01 = 0x03; // 32768/9600 = 3.41 - UBR11 = 0x00; // - UMCTL1 = 0x4A; // modulation - */ - - // 115200 baud, clocked from 4.8MHz SMCLK - UTCTL1 |= SSEL1; // clocking from SMCLK - UBR01 = 41; // 4.8MHz/115200 - 41.66 - UBR11 = 0x00; // - UMCTL1 = 0x4A; // modulation - - - ME2 |= UTXE1 + URXE1; // enable UART1 TX/RX - UCTL1 &= ~SWRST; // clear UART1 reset bit + + memset(&uart_vars,0,sizeof(uart_vars_t)); + + P3SEL |= 0xc0; // P3.6,7 = UART1TX/RX + + UCTL1 = SWRST; // hold UART1 module in reset + UCTL1 |= CHAR; // 8-bit character + + /* + // 9600 baud, clocked from 32kHz ACLK + UTCTL1 |= SSEL0; // clocking from ACLK + UBR01 = 0x03; // 32768/9600 = 3.41 + UBR11 = 0x00; // + UMCTL1 = 0x4A; // modulation + */ + + // 115200 baud, clocked from 4.8MHz SMCLK + UTCTL1 |= SSEL1; // clocking from SMCLK + UBR01 = 41; // 4.8MHz/115200 - 41.66 + UBR11 = 0x00; // + UMCTL1 = 0x4A; // modulation + + ME2 |= UTXE1 + URXE1; // enable UART1 TX/RX + UCTL1 &= ~SWRST; // clear UART1 reset bit } void uart_setCallbacks(uart_tx_cbt txCb, uart_rx_cbt rxCb) { - uart_vars.txCb = txCb; - uart_vars.rxCb = rxCb; + uart_vars.txCb = txCb; + uart_vars.rxCb = rxCb; } -void uart_enableInterrupts(){ - IE2 |= (URXIE1 | UTXIE1); +void uart_enableInterrupts(){ + IE2 |= (URXIE1 | UTXIE1); } -void uart_disableInterrupts(){ - IE2 &= ~(URXIE1 | UTXIE1); +void uart_disableInterrupts(){ + IE2 &= ~(URXIE1 | UTXIE1); } -void uart_clearRxInterrupts(){ - IFG2 &= ~URXIFG1; +void uart_clearRxInterrupts(){ + IFG2 &= ~URXIFG1; } -void uart_clearTxInterrupts(){ - IFG2 &= ~UTXIFG1; +void uart_clearTxInterrupts(){ + IFG2 &= ~UTXIFG1; } -void uart_writeByte(uint8_t byteToWrite){ - U1TXBUF = byteToWrite; +void uart_setCTS(bool state) { + if (state==0x01) { + U1TXBUF = XON; + } else { + U1TXBUF = XOFF; + } +} + +void uart_writeByte(uint8_t byteToWrite){ + if (byteToWrite==XON || byteToWrite==XOFF || byteToWrite==XONXOFF_ESCAPE) { + uart_vars.fXonXoffEscaping = 0x01; + uart_vars.xonXoffEscapedByte = byteToWrite; + U1TXBUF = XONXOFF_ESCAPE; + } else { + U1TXBUF = byteToWrite; + } } uint8_t uart_readByte(){ - return U1RXBUF; + return U1RXBUF; } //=========================== private ========================================= @@ -82,13 +100,18 @@ uint8_t uart_readByte(){ //=========================== interrupt handlers ============================== kick_scheduler_t uart_tx_isr() { - uart_clearTxInterrupts(); // TODO: do not clear, but disable when done - uart_vars.txCb(); - return DO_NOT_KICK_SCHEDULER; + uart_clearTxInterrupts(); // TODO: do not clear, but disable when done + if (uart_vars.fXonXoffEscaping==0x01) { + uart_vars.fXonXoffEscaping = 0x00; + U1TXBUF = uart_vars.xonXoffEscapedByte^XONXOFF_MASK; + } else { + uart_vars.txCb(); + } + return DO_NOT_KICK_SCHEDULER; } kick_scheduler_t uart_rx_isr() { uart_clearRxInterrupts(); // TODO: do not clear, but disable when done uart_vars.rxCb(); return DO_NOT_KICK_SCHEDULER; -} \ No newline at end of file +} diff --git a/bsp/boards/uart.h b/bsp/boards/uart.h index acf868e5aa..6bec0f91ad 100644 --- a/bsp/boards/uart.h +++ b/bsp/boards/uart.h @@ -17,6 +17,14 @@ //=========================== define ========================================== +#define XOFF 0x13 +#define XON 0x11 +#define XONXOFF_ESCAPE 0x12 +#define XONXOFF_MASK 0x10 +// XOFF is transmitted as [XONXOFF_ESCAPE, XOFF^XONXOFF_MASK]==[0x12,0x13^0x10]==[0x12,0x03] +// XON is transmitted as [XONXOFF_ESCAPE, XON^XONXOFF_MASK]==[0x12,0x11^0x10]==[0x12,0x01] +// XONXOFF_ESCAPE is transmitted as [XONXOFF_ESCAPE, XONXOFF_ESCAPE^XONXOFF_MASK]==[0x12,0x12^0x10]==[0x12,0x02] + //=========================== typedef ========================================= typedef enum { @@ -37,6 +45,7 @@ void uart_enableInterrupts(void); void uart_disableInterrupts(void); void uart_clearRxInterrupts(void); void uart_clearTxInterrupts(void); +void uart_setCTS(bool state); void uart_writeByte(uint8_t byteToWrite); #ifdef FASTSIM void uart_writeCircularBuffer_FASTSIM(uint8_t* buffer, uint8_t* outputBufIdxR, uint8_t* outputBufIdxW); diff --git a/drivers/common/openserial.c b/drivers/common/openserial.c index 775fe18f9f..6162b9b99d 100644 --- a/drivers/common/openserial.c +++ b/drivers/common/openserial.c @@ -22,6 +22,7 @@ #include "schedule.h" #include "icmpv6rpl.h" #include "sf0.h" +#include "debugpins.h" //=========================== variables ======================================= @@ -39,6 +40,7 @@ owerror_t openserial_printInfoErrorCritical( ); // command handlers +void openserial_handleRxFrame(); void openserial_handleEcho(uint8_t* but, uint8_t bufLen); void openserial_handleCommands(void); @@ -62,40 +64,31 @@ void inputHdlcClose(void); //===== admin void openserial_init() { - uint16_t crc; - // reset variable memset(&openserial_vars,0,sizeof(openserial_vars_t)); // admin - openserial_vars.mode = MODE_OFF; + openserial_vars.fInhibited = FALSE; + openserial_vars.ctsStateChanged = FALSE; openserial_vars.debugPrintCounter = 0; // input - openserial_vars.reqFrame[0] = HDLC_FLAG; - openserial_vars.reqFrame[1] = SERFRAME_MOTE2PC_REQUEST; - crc = HDLC_CRCINIT; - crc = crcIteration(crc,openserial_vars.reqFrame[1]); - crc = ~crc; - openserial_vars.reqFrame[2] = (crc>>0)&0xff; - openserial_vars.reqFrame[3] = (crc>>8)&0xff; - openserial_vars.reqFrame[4] = HDLC_FLAG; - openserial_vars.reqFrameIdx = 0; - openserial_vars.lastRxByte = HDLC_FLAG; - openserial_vars.busyReceiving = FALSE; - openserial_vars.inputEscaping = FALSE; - openserial_vars.inputBufFill = 0; + openserial_vars.hdlcLastRxByte = HDLC_FLAG; + openserial_vars.hdlcBusyReceiving = FALSE; + openserial_vars.hdlcInputEscaping = FALSE; + openserial_vars.inputBufFillLevel = 0; // ouput - openserial_vars.outputBufFilled = FALSE; openserial_vars.outputBufIdxR = 0; openserial_vars.outputBufIdxW = 0; + openserial_vars.fBusyFlushing = FALSE; - // set callbacks + // UART uart_setCallbacks( isr_openserial_tx, isr_openserial_rx ); + uart_enableInterrupts(); } void openserial_register(openserial_rsvpt* rsvp) { @@ -103,7 +96,7 @@ void openserial_register(openserial_rsvpt* rsvp) { openserial_vars.registeredCmd = rsvp; } -//===== printing +//===== transmitting owerror_t openserial_printStatus( uint8_t statusElement, @@ -111,10 +104,7 @@ owerror_t openserial_printStatus( uint8_t length ) { uint8_t i; - INTERRUPT_DECLARATION(); - DISABLE_INTERRUPTS(); - openserial_vars.outputBufFilled = TRUE; outputHdlcOpen(); outputHdlcWrite(SERFRAME_MOTE2PC_STATUS); outputHdlcWrite(idmanager_getMyID(ADDR_16B)->addr_16b[0]); @@ -124,7 +114,9 @@ owerror_t openserial_printStatus( outputHdlcWrite(buffer[i]); } outputHdlcClose(); - ENABLE_INTERRUPTS(); + + // start TX'ing + openserial_flush(); return E_SUCCESS; } @@ -142,6 +134,8 @@ owerror_t openserial_printInfo( arg1, arg2 ); + + // openserial_flush called by openserial_printInfoErrorCritical() } owerror_t openserial_printError( @@ -152,6 +146,7 @@ owerror_t openserial_printError( ) { // toggle error LED leds_error_toggle(); + debugpins_frame_toggle();//poipoipoi return openserial_printInfoErrorCritical( SERFRAME_MOTE2PC_ERROR, @@ -160,6 +155,8 @@ owerror_t openserial_printError( arg1, arg2 ); + + // openserial_flush called by openserial_printInfoErrorCritical() } owerror_t openserial_printCritical( @@ -186,18 +183,17 @@ owerror_t openserial_printCritical( arg1, arg2 ); + + // openserial_flush called by openserial_printInfoErrorCritical() } owerror_t openserial_printData(uint8_t* buffer, uint8_t length) { uint8_t i; uint8_t asn[5]; - INTERRUPT_DECLARATION(); // retrieve ASN ieee154e_getAsn(asn); - DISABLE_INTERRUPTS(); - openserial_vars.outputBufFilled = TRUE; outputHdlcOpen(); outputHdlcWrite(SERFRAME_MOTE2PC_DATA); outputHdlcWrite(idmanager_getMyID(ADDR_16B)->addr_16b[1]); @@ -211,17 +207,16 @@ owerror_t openserial_printData(uint8_t* buffer, uint8_t length) { outputHdlcWrite(buffer[i]); } outputHdlcClose(); - ENABLE_INTERRUPTS(); + + // start TX'ing + openserial_flush(); return E_SUCCESS; } owerror_t openserial_printSniffedPacket(uint8_t* buffer, uint8_t length, uint8_t channel) { uint8_t i; - INTERRUPT_DECLARATION(); - DISABLE_INTERRUPTS(); - openserial_vars.outputBufFilled = TRUE; outputHdlcOpen(); outputHdlcWrite(SERFRAME_MOTE2PC_SNIFFED_PACKET); outputHdlcWrite(idmanager_getMyID(ADDR_16B)->addr_16b[1]); @@ -232,96 +227,26 @@ owerror_t openserial_printSniffedPacket(uint8_t* buffer, uint8_t length, uint8_t outputHdlcWrite(channel); outputHdlcClose(); - ENABLE_INTERRUPTS(); + // start TX'ing + openserial_flush(); return E_SUCCESS; } -//===== retrieving inputBuffer - -uint8_t openserial_getInputBufferFilllevel() { - uint8_t inputBufFill; - INTERRUPT_DECLARATION(); - - DISABLE_INTERRUPTS(); - inputBufFill = openserial_vars.inputBufFill; - ENABLE_INTERRUPTS(); - - return inputBufFill-1; // removing the command byte -} - -uint8_t openserial_getInputBuffer(uint8_t* bufferToWrite, uint8_t maxNumBytes) { - uint8_t numBytesWritten; - uint8_t inputBufFill; - INTERRUPT_DECLARATION(); - - DISABLE_INTERRUPTS(); - inputBufFill = openserial_vars.inputBufFill; - ENABLE_INTERRUPTS(); - - if (maxNumBytes0) { - openserial_printError( - COMPONENT_OPENSERIAL, - ERR_INPUTBUFFER_LENGTH, - (errorparameter_t)openserial_vars.inputBufFill, - (errorparameter_t)0 - ); - DISABLE_INTERRUPTS(); - openserial_vars.inputBufFill=0; - ENABLE_INTERRUPTS(); - } - - uart_clearTxInterrupts(); - uart_clearRxInterrupts(); // clear possible pending interrupts - uart_enableInterrupts(); // Enable USCI_A1 TX & RX interrupt - - DISABLE_INTERRUPTS(); - openserial_vars.busyReceiving = FALSE; - openserial_vars.mode = MODE_INPUT; - openserial_vars.reqFrameIdx = 0; -#ifdef FASTSIM - uart_writeBufferByLen_FASTSIM( - openserial_vars.reqFrame, - sizeof(openserial_vars.reqFrame) - ); - openserial_vars.reqFrameIdx = sizeof(openserial_vars.reqFrame); -#else - uart_writeByte(openserial_vars.reqFrame[openserial_vars.reqFrameIdx]); -#endif - ENABLE_INTERRUPTS(); -} - -void openserial_startOutput() { +void openserial_triggerDebugprint() { uint8_t debugPrintCounter; INTERRUPT_DECLARATION(); - //=== made modules print debug information - + //<<<<<<<<<<<<<<<<<<<<<<< DISABLE_INTERRUPTS(); - openserial_vars.debugPrintCounter = (openserial_vars.debugPrintCounter+1)%STATUS_MAX; debugPrintCounter = openserial_vars.debugPrintCounter; ENABLE_INTERRUPTS(); + //>>>>>>>>>>>>>>>>>>>>>>> + + debugPrintCounter++; + if (debugPrintCounter==STATUS_MAX) { + debugPrintCounter = 0; + } switch (debugPrintCounter) { case STATUS_ISSYNC: @@ -369,98 +294,131 @@ void openserial_startOutput() { break; } default: - DISABLE_INTERRUPTS(); - openserial_vars.debugPrintCounter=0; - ENABLE_INTERRUPTS(); + debugPrintCounter=0; } - //=== flush TX buffer - - uart_clearTxInterrupts(); - uart_clearRxInterrupts(); // clear possible pending interrupts - uart_enableInterrupts(); // Enable USCI_A1 TX & RX interrupt - + //<<<<<<<<<<<<<<<<<<<<<<< DISABLE_INTERRUPTS(); - openserial_vars.mode=MODE_OUTPUT; - if (openserial_vars.outputBufFilled) { -#ifdef FASTSIM - uart_writeCircularBuffer_FASTSIM( - openserial_vars.outputBuf, - &openserial_vars.outputBufIdxR, - &openserial_vars.outputBufIdxW - ); -#else - uart_writeByte(openserial_vars.outputBuf[openserial_vars.outputBufIdxR++]); -#endif - } else { - openserial_stop(); - } + openserial_vars.debugPrintCounter = debugPrintCounter; ENABLE_INTERRUPTS(); + //>>>>>>>>>>>>>>>>>>>>>>> } -void openserial_stop() { - uint8_t inputBufFill; - uint8_t cmdByte; - bool busyReceiving; - INTERRUPT_DECLARATION(); +//===== receiving +uint8_t openserial_getInputBufferFillLevel() { + uint8_t inputBufFillLevel; + INTERRUPT_DECLARATION(); + + //<<<<<<<<<<<<<<<<<<<<<<< DISABLE_INTERRUPTS(); - busyReceiving = openserial_vars.busyReceiving; - inputBufFill = openserial_vars.inputBufFill; + inputBufFillLevel = openserial_vars.inputBufFillLevel; ENABLE_INTERRUPTS(); + //>>>>>>>>>>>>>>>>>>>>>>> + + return inputBufFillLevel-1; // removing the command byte +} - // disable UART interrupts - uart_disableInterrupts(); - +uint8_t openserial_getInputBuffer(uint8_t* bufferToWrite, uint8_t maxNumBytes) { + uint8_t numBytesWritten; + uint8_t inputBufFillLevel; + INTERRUPT_DECLARATION(); + + //<<<<<<<<<<<<<<<<<<<<<<< DISABLE_INTERRUPTS(); - openserial_vars.mode=MODE_OFF; + inputBufFillLevel = openserial_vars.inputBufFillLevel; ENABLE_INTERRUPTS(); - - // the inputBuffer has to be reset if it is not reset where the data is read. - // or the function openserial_getInputBuffer is called (which resets the buffer) - if (busyReceiving==TRUE) { + //>>>>>>>>>>>>>>>>>>>>>>> + + if (maxNumBytes0) { + numBytesWritten = 0; + } else { + numBytesWritten = inputBufFillLevel-1; + //<<<<<<<<<<<<<<<<<<<<<<< DISABLE_INTERRUPTS(); - cmdByte = openserial_vars.inputBuf[0]; + memcpy(bufferToWrite,&(openserial_vars.inputBuf[1]),numBytesWritten); ENABLE_INTERRUPTS(); - // call hard-coded commands - // FIXME: needs to be replaced by registered commands only - switch (cmdByte) { - case SERFRAME_PC2MOTE_SETROOT: - idmanager_triggerAboutRoot(); - break; - case SERFRAME_PC2MOTE_RESET: - board_reset(); - break; - case SERFRAME_PC2MOTE_DATA: - openbridge_triggerData(); - break; - case SERFRAME_PC2MOTE_TRIGGERSERIALECHO: - openserial_handleEcho(&openserial_vars.inputBuf[1],inputBufFill-1); - break; - case SERFRAME_PC2MOTE_COMMAND: - openserial_handleCommands(); - break; - } - // call registered commands - if (openserial_vars.registeredCmd!=NULL && openserial_vars.registeredCmd->cmdId==cmdByte) { + //>>>>>>>>>>>>>>>>>>>>>>> + } + + return numBytesWritten; +} + +//===== scheduling + +void openserial_flush(void) { + INTERRUPT_DECLARATION(); + + //<<<<<<<<<<<<<<<<<<<<<<< + DISABLE_INTERRUPTS(); + if (openserial_vars.fBusyFlushing==FALSE) { + if (openserial_vars.ctsStateChanged==TRUE) { + // send CTS + + if (openserial_vars.fInhibited==TRUE) { + uart_setCTS(FALSE); + } else { + uart_setCTS(TRUE); + } + openserial_vars.ctsStateChanged = FALSE; + } else if (openserial_vars.fInhibited==TRUE) { + // currently inhibited + + } else { + // not inhibited - openserial_vars.registeredCmd->cb(); + if (openserial_vars.outputBufIdxW!=openserial_vars.outputBufIdxR) { + // I have some bytes to transmit + +#ifdef FASTSIM + uart_writeCircularBuffer_FASTSIM( + openserial_vars.outputBuf, + &openserial_vars.outputBufIdxR, + &openserial_vars.outputBufIdxW + ); +#else + uart_writeByte(openserial_vars.outputBuf[openserial_vars.outputBufIdxR++]); + openserial_vars.fBusyFlushing = TRUE; +#endif + } } } + ENABLE_INTERRUPTS(); + //>>>>>>>>>>>>>>>>>>>>>>> +} + +void openserial_inhibitStart(void) { + INTERRUPT_DECLARATION(); + //<<<<<<<<<<<<<<<<<<<<<<< DISABLE_INTERRUPTS(); - openserial_vars.inputBufFill = 0; - openserial_vars.busyReceiving = FALSE; + openserial_vars.fInhibited = TRUE; + openserial_vars.ctsStateChanged = TRUE; ENABLE_INTERRUPTS(); + //>>>>>>>>>>>>>>>>>>>>>>> + + // it's openserial_flush() which will set CTS + openserial_flush(); +} + +void openserial_inhibitStop(void) { + INTERRUPT_DECLARATION(); + + //<<<<<<<<<<<<<<<<<<<<<<< + DISABLE_INTERRUPTS(); + openserial_vars.fInhibited = FALSE; + openserial_vars.ctsStateChanged = TRUE; + ENABLE_INTERRUPTS(); + //>>>>>>>>>>>>>>>>>>>>>>> + + // it's openserial_flush() which will set CTS + openserial_flush(); } //===== debugprint @@ -477,10 +435,12 @@ bool debugPrint_outBufferIndexes() { uint16_t temp_buffer[2]; INTERRUPT_DECLARATION(); + //<<<<<<<<<<<<<<<<<<<<<<< DISABLE_INTERRUPTS(); temp_buffer[0] = openserial_vars.outputBufIdxW; temp_buffer[1] = openserial_vars.outputBufIdxR; ENABLE_INTERRUPTS(); + //>>>>>>>>>>>>>>>>>>>>>>> openserial_printStatus( STATUS_OUTBUFFERINDEXES, @@ -502,10 +462,7 @@ owerror_t openserial_printInfoErrorCritical( errorparameter_t arg1, errorparameter_t arg2 ) { - INTERRUPT_DECLARATION(); - DISABLE_INTERRUPTS(); - openserial_vars.outputBufFilled = TRUE; outputHdlcOpen(); outputHdlcWrite(severity); outputHdlcWrite(idmanager_getMyID(ADDR_16B)->addr_16b[0]); @@ -517,13 +474,48 @@ owerror_t openserial_printInfoErrorCritical( outputHdlcWrite((uint8_t)((arg2 & 0xff00)>>8)); outputHdlcWrite((uint8_t) (arg2 & 0x00ff)); outputHdlcClose(); - ENABLE_INTERRUPTS(); + + // start TX'ing + openserial_flush(); return E_SUCCESS; } //===== command handlers +// executed in ISR +void openserial_handleRxFrame() { + uint8_t cmdByte; + + cmdByte = openserial_vars.inputBuf[0]; + // call hard-coded commands + // FIXME: needs to be replaced by registered commands only + switch (cmdByte) { + case SERFRAME_PC2MOTE_SETROOT: + idmanager_triggerAboutRoot(); + break; + case SERFRAME_PC2MOTE_RESET: + board_reset(); + break; + case SERFRAME_PC2MOTE_DATA: + openbridge_triggerData(); + break; + case SERFRAME_PC2MOTE_TRIGGERSERIALECHO: + openserial_handleEcho( + &openserial_vars.inputBuf[1], + openserial_vars.inputBufFillLevel-1 + ); + break; + case SERFRAME_PC2MOTE_COMMAND: + openserial_handleCommands(); + break; + } + // call registered commands + if (openserial_vars.registeredCmd!=NULL && openserial_vars.registeredCmd->cmdId==cmdByte) { + openserial_vars.registeredCmd->cb(); + } +} + void openserial_handleEcho(uint8_t* buf, uint8_t bufLen){ // echo back what you received @@ -548,7 +540,7 @@ void openserial_handleCommands(void){ memset(cellList,0,sizeof(cellList)); - numDataBytes = openserial_getInputBufferFilllevel(); + numDataBytes = openserial_getInputBufferFillLevel(); //copying the buffer openserial_getInputBuffer(&(input_buffer[0]),numDataBytes); commandId = openserial_vars.inputBuf[1]; @@ -688,19 +680,32 @@ void openserial_board_reset_cb(opentimer_id_t id) { \brief Start an HDLC frame in the output buffer. */ port_INLINE void outputHdlcOpen() { + INTERRUPT_DECLARATION(); + + //<<<<<<<<<<<<<<<<<<<<<<< + DISABLE_INTERRUPTS(); + // initialize the value of the CRC - openserial_vars.outputCrc = HDLC_CRCINIT; - + + openserial_vars.hdlcOutputCrc = HDLC_CRCINIT; + // write the opening HDLC flag openserial_vars.outputBuf[openserial_vars.outputBufIdxW++] = HDLC_FLAG; + + ENABLE_INTERRUPTS(); + //>>>>>>>>>>>>>>>>>>>>>>> } /** \brief Add a byte to the outgoing HDLC frame being built. */ port_INLINE void outputHdlcWrite(uint8_t b) { + INTERRUPT_DECLARATION(); + + //<<<<<<<<<<<<<<<<<<<<<<< + DISABLE_INTERRUPTS(); // iterate through CRC calculator - openserial_vars.outputCrc = crcIteration(openserial_vars.outputCrc,b); + openserial_vars.hdlcOutputCrc = crcIteration(openserial_vars.hdlcOutputCrc,b); // add byte to buffer if (b==HDLC_FLAG || b==HDLC_ESCAPE) { @@ -708,15 +713,22 @@ port_INLINE void outputHdlcWrite(uint8_t b) { b = b^HDLC_ESCAPE_MASK; } openserial_vars.outputBuf[openserial_vars.outputBufIdxW++] = b; + + ENABLE_INTERRUPTS(); + //>>>>>>>>>>>>>>>>>>>>>>> } /** \brief Finalize the outgoing HDLC frame. */ port_INLINE void outputHdlcClose() { uint16_t finalCrc; - + INTERRUPT_DECLARATION(); + + //<<<<<<<<<<<<<<<<<<<<<<< + DISABLE_INTERRUPTS(); + // finalize the calculation of the CRC - finalCrc = ~openserial_vars.outputCrc; + finalCrc = ~openserial_vars.hdlcOutputCrc; // write the CRC value outputHdlcWrite((finalCrc>>0)&0xff); @@ -724,6 +736,9 @@ port_INLINE void outputHdlcClose() { // write the closing HDLC flag openserial_vars.outputBuf[openserial_vars.outputBufIdxW++] = HDLC_FLAG; + + ENABLE_INTERRUPTS(); + //>>>>>>>>>>>>>>>>>>>>>>> } //===== hdlc (input) @@ -733,29 +748,29 @@ port_INLINE void outputHdlcClose() { */ port_INLINE void inputHdlcOpen() { // reset the input buffer index - openserial_vars.inputBufFill = 0; + openserial_vars.inputBufFillLevel = 0; // initialize the value of the CRC - openserial_vars.inputCrc = HDLC_CRCINIT; + openserial_vars.hdlcInputCrc = HDLC_CRCINIT; } /** \brief Add a byte to the incoming HDLC frame. */ port_INLINE void inputHdlcWrite(uint8_t b) { if (b==HDLC_ESCAPE) { - openserial_vars.inputEscaping = TRUE; + openserial_vars.hdlcInputEscaping = TRUE; } else { - if (openserial_vars.inputEscaping==TRUE) { + if (openserial_vars.hdlcInputEscaping==TRUE) { b = b^HDLC_ESCAPE_MASK; - openserial_vars.inputEscaping = FALSE; + openserial_vars.hdlcInputEscaping = FALSE; } // add byte to input buffer - openserial_vars.inputBuf[openserial_vars.inputBufFill] = b; - openserial_vars.inputBufFill++; + openserial_vars.inputBuf[openserial_vars.inputBufFillLevel] = b; + openserial_vars.inputBufFillLevel++; // iterate through CRC calculator - openserial_vars.inputCrc = crcIteration(openserial_vars.inputCrc,b); + openserial_vars.hdlcInputCrc = crcIteration(openserial_vars.hdlcInputCrc,b); } } /** @@ -764,16 +779,16 @@ port_INLINE void inputHdlcWrite(uint8_t b) { port_INLINE void inputHdlcClose() { // verify the validity of the frame - if (openserial_vars.inputCrc==HDLC_CRCGOOD) { + if (openserial_vars.hdlcInputCrc==HDLC_CRCGOOD) { // the CRC is correct // remove the CRC from the input buffer - openserial_vars.inputBufFill -= 2; + openserial_vars.inputBufFillLevel -= 2; } else { // the CRC is incorrect - // drop the incoming fram - openserial_vars.inputBufFill = 0; + // drop the incoming frame + openserial_vars.inputBufFillLevel = 0; } } @@ -781,51 +796,52 @@ port_INLINE void inputHdlcClose() { // executed in ISR, called from scheduler.c void isr_openserial_tx() { - switch (openserial_vars.mode) { - case MODE_INPUT: - openserial_vars.reqFrameIdx++; - if (openserial_vars.reqFrameIdxSERIAL_INPUT_BUFFER_SIZE){ + if (openserial_vars.inputBufFillLevel+1>SERIAL_INPUT_BUFFER_SIZE){ // input buffer overflow openserial_printError( COMPONENT_OPENSERIAL, @@ -848,32 +864,32 @@ void isr_openserial_rx() { (errorparameter_t)0, (errorparameter_t)0 ); - openserial_vars.inputBufFill = 0; - openserial_vars.busyReceiving = FALSE; - openserial_stop(); + openserial_vars.inputBufFillLevel = 0; + openserial_vars.hdlcBusyReceiving = FALSE; } } else if ( - openserial_vars.busyReceiving==TRUE && + openserial_vars.hdlcBusyReceiving==TRUE && rxbyte==HDLC_FLAG ) { // end of frame // finalize the HDLC frame inputHdlcClose(); + openserial_vars.hdlcBusyReceiving = FALSE; - if (openserial_vars.inputBufFill==0){ + if (openserial_vars.inputBufFillLevel==0){ // invalid HDLC frame openserial_printError( COMPONENT_OPENSERIAL, ERR_WRONG_CRC_INPUT, - (errorparameter_t)inputBufFill, + (errorparameter_t)openserial_vars.inputBufFillLevel, (errorparameter_t)0 ); + } else { + openserial_handleRxFrame(); + openserial_vars.inputBufFillLevel = 0; } - - openserial_vars.busyReceiving = FALSE; - openserial_stop(); } - openserial_vars.lastRxByte = rxbyte; + openserial_vars.hdlcLastRxByte = rxbyte; } diff --git a/drivers/common/openserial.h b/drivers/common/openserial.h index 097feda196..7fe43c8f4f 100644 --- a/drivers/common/openserial.h +++ b/drivers/common/openserial.h @@ -35,20 +35,12 @@ */ #define SERIAL_INPUT_BUFFER_SIZE 200 -/// Modes of the openserial module. -enum { - MODE_OFF = 0, ///< The module is off, no serial activity. - MODE_INPUT = 1, ///< The serial is listening or receiving bytes. - MODE_OUTPUT = 2 ///< The serial is transmitting bytes. -}; - // frames sent mote->PC #define SERFRAME_MOTE2PC_DATA ((uint8_t)'D') #define SERFRAME_MOTE2PC_STATUS ((uint8_t)'S') #define SERFRAME_MOTE2PC_INFO ((uint8_t)'I') #define SERFRAME_MOTE2PC_ERROR ((uint8_t)'E') #define SERFRAME_MOTE2PC_CRITICAL ((uint8_t)'C') -#define SERFRAME_MOTE2PC_REQUEST ((uint8_t)'R') #define SERFRAME_MOTE2PC_SNIFFED_PACKET ((uint8_t)'P') // frames sent PC->mote @@ -96,31 +88,30 @@ typedef struct _openserial_rsvpt { typedef struct { // admin - uint8_t mode; + uint8_t fInhibited; + uint8_t ctsStateChanged; uint8_t debugPrintCounter; openserial_rsvpt* registeredCmd; // input - uint8_t reqFrame[1+1+2+1]; // flag (1B), command (2B), CRC (2B), flag (1B) - uint8_t reqFrameIdx; - uint8_t lastRxByte; - bool busyReceiving; - bool inputEscaping; - uint16_t inputCrc; - uint8_t inputBufFill; uint8_t inputBuf[SERIAL_INPUT_BUFFER_SIZE]; + uint8_t inputBufFillLevel; + uint8_t hdlcLastRxByte; + bool hdlcBusyReceiving; + uint16_t hdlcInputCrc; + bool hdlcInputEscaping; // output - bool outputBufFilled; - uint16_t outputCrc; + uint8_t outputBuf[SERIAL_OUTPUT_BUFFER_SIZE]; uint8_t outputBufIdxW; uint8_t outputBufIdxR; - uint8_t outputBuf[SERIAL_OUTPUT_BUFFER_SIZE]; + bool fBusyFlushing; + uint16_t hdlcOutputCrc; } openserial_vars_t; // admin -void openserial_init(void); -void openserial_register(openserial_rsvpt* rsvp); +void openserial_init(void); +void openserial_register(openserial_rsvpt* rsvp); -// printing +// transmitting owerror_t openserial_printStatus( uint8_t statusElement, uint8_t* buffer, @@ -144,17 +135,25 @@ owerror_t openserial_printCritical( errorparameter_t arg1, errorparameter_t arg2 ); -owerror_t openserial_printData(uint8_t* buffer, uint8_t length); -owerror_t openserial_printSniffedPacket(uint8_t* buffer, uint8_t length, uint8_t channel); +owerror_t openserial_printData( + uint8_t* buffer, + uint8_t length +); +owerror_t openserial_printSniffedPacket( + uint8_t* buffer, + uint8_t length, + uint8_t channel +); +void openserial_triggerDebugprint(); -// retrieving inputBuffer -uint8_t openserial_getInputBufferFilllevel(void); +// receiving +uint8_t openserial_getInputBufferFillLevel(void); uint8_t openserial_getInputBuffer(uint8_t* bufferToWrite, uint8_t maxNumBytes); // scheduling -void openserial_startInput(void); -void openserial_startOutput(void); -void openserial_stop(void); +void openserial_flush(void); +void openserial_inhibitStart(void); +void openserial_inhibitStop(void); // debugprint bool debugPrint_outBufferIndexes(void); diff --git a/projects/common/02drv_openserial/02drv_openserial.c b/projects/common/02drv_openserial/02drv_openserial.c index 2a2c2d8ba1..ed75f7dd3f 100644 --- a/projects/common/02drv_openserial/02drv_openserial.c +++ b/projects/common/02drv_openserial/02drv_openserial.c @@ -27,13 +27,13 @@ sure all is well. //=========================== defines ========================================= -#define BSP_TIMER_PERIOD 328 // 328@32kHz ~ 10ms +#define BSP_TIMER_PERIOD 328 // 328@32kHz ~ 10ms //=========================== variables ======================================= typedef struct { - uint8_t timerFired; - uint8_t outputting; + bool timerFired; + bool fInhibit; open_addr_t addr; } app_vars_t; @@ -52,6 +52,8 @@ openserial takes different actions according to the initial character of the str */ int mote_main(void) { + memset(&app_vars,0,sizeof(app_vars_t)); + board_init(); openserial_init(); @@ -60,24 +62,28 @@ int mote_main(void) { while(1) { board_sleep(); - debugpins_slot_toggle(); - if (app_vars.timerFired==1) { - app_vars.timerFired = 0; - if (app_vars.outputting==1) { - openserial_startInput(); - app_vars.outputting = 0; + debugpins_task_set(); + if (app_vars.timerFired==TRUE) { + app_vars.timerFired = FALSE; + //poipoipoi openserial_triggerDebugprint(); + if (app_vars.fInhibit==TRUE) { + debugpins_slot_clr(); + openserial_inhibitStart(); + app_vars.fInhibit = FALSE; } else { - openserial_startOutput(); - app_vars.outputting = 1; + debugpins_slot_set(); + openserial_inhibitStop(); + app_vars.fInhibit = TRUE; } } + debugpins_task_clr(); } } //=========================== callbacks ======================================= void cb_compare(void) { - app_vars.timerFired = 1; + app_vars.timerFired = TRUE; bsp_timer_scheduleIn(BSP_TIMER_PERIOD); } From 4b18219d110c2e7054fc4d5c9af3893058077c72 Mon Sep 17 00:00:00 2001 From: Thomas Watteyne Date: Mon, 29 Aug 2016 15:59:29 +0200 Subject: [PATCH 02/99] FW-540. Removing temporary comment. Oops. --- drivers/common/openserial.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/common/openserial.c b/drivers/common/openserial.c index 6162b9b99d..660d1afb59 100644 --- a/drivers/common/openserial.c +++ b/drivers/common/openserial.c @@ -146,7 +146,6 @@ owerror_t openserial_printError( ) { // toggle error LED leds_error_toggle(); - debugpins_frame_toggle();//poipoipoi return openserial_printInfoErrorCritical( SERFRAME_MOTE2PC_ERROR, From ef795675d4d2e037dce00b98a859160d9e7771e1 Mon Sep 17 00:00:00 2001 From: Thomas Watteyne Date: Mon, 29 Aug 2016 16:07:35 +0200 Subject: [PATCH 03/99] FW-540. Enabling debug printing in test app. --- projects/common/02drv_openserial/02drv_openserial.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/common/02drv_openserial/02drv_openserial.c b/projects/common/02drv_openserial/02drv_openserial.c index ed75f7dd3f..ef37135973 100644 --- a/projects/common/02drv_openserial/02drv_openserial.c +++ b/projects/common/02drv_openserial/02drv_openserial.c @@ -65,7 +65,7 @@ int mote_main(void) { debugpins_task_set(); if (app_vars.timerFired==TRUE) { app_vars.timerFired = FALSE; - //poipoipoi openserial_triggerDebugprint(); + openserial_triggerDebugprint(); if (app_vars.fInhibit==TRUE) { debugpins_slot_clr(); openserial_inhibitStart(); From c648b9fef5a461ff8cff4bc201670f05bdbd240e Mon Sep 17 00:00:00 2001 From: Thomas Watteyne Date: Mon, 29 Aug 2016 16:32:27 +0200 Subject: [PATCH 04/99] FW-540. First stake at merging serial optimization into state machine. --- bsp/boards/debugpins.h | 12 +++++ bsp/boards/telosb/board.c | 9 ---- drivers/common/openserial.c | 4 +- openstack/02a-MAClow/IEEE802154E.c | 54 ++++++++++------------ openstack/02a-MAClow/IEEE802154_security.c | 1 + openstack/02b-MAChigh/schedule.c | 1 + openstack/03a-IPHC/openbridge.c | 3 +- openstack/cross-layers/idmanager.c | 1 + openstack/cross-layers/openqueue.c | 1 + 9 files changed, 46 insertions(+), 40 deletions(-) diff --git a/bsp/boards/debugpins.h b/bsp/boards/debugpins.h index 8641665015..4a6fca39fe 100644 --- a/bsp/boards/debugpins.h +++ b/bsp/boards/debugpins.h @@ -42,10 +42,22 @@ void debugpins_isr_toggle(void); void debugpins_isr_clr(void); void debugpins_isr_set(void); +void debugpins_isruarttx_toggle(void); +void debugpins_isruarttx_clr(void); +void debugpins_isruarttx_set(void); + +void debugpins_isruartrx_toggle(void); +void debugpins_isruartrx_clr(void); +void debugpins_isruartrx_set(void); + void debugpins_radio_toggle(void); void debugpins_radio_clr(void); void debugpins_radio_set(void); +void debugpins_intdisabled_toggle(void); +void debugpins_intdisabled_clr(void); +void debugpins_intdisabled_set(void); + #ifdef OPENSIM void debugpins_ka_clr(void); void debugpins_ka_set(void); diff --git a/bsp/boards/telosb/board.c b/bsp/boards/telosb/board.c index ac19aade59..47f2b1c632 100644 --- a/bsp/boards/telosb/board.c +++ b/bsp/boards/telosb/board.c @@ -19,15 +19,6 @@ //=========================== prototypes ====================================== -// these are part of the TelosB port only, so not present in debugpins.h, only -// in debugpins.c. We therefore need to extern them. -extern void debugpins_isruarttx_toggle(); -extern void debugpins_isruarttx_clr(); -extern void debugpins_isruarttx_set(); -extern void debugpins_isruartrx_toggle(); -extern void debugpins_isruartrx_clr(); -extern void debugpins_isruartrx_set(); - //=========================== main ============================================ extern int mote_main(void); diff --git a/drivers/common/openserial.c b/drivers/common/openserial.c index 660d1afb59..318085567b 100644 --- a/drivers/common/openserial.c +++ b/drivers/common/openserial.c @@ -30,6 +30,8 @@ openserial_vars_t openserial_vars; //=========================== prototypes ====================================== +extern void sniffer_setListeningChannel(uint8_t channel); + // printing owerror_t openserial_printInfoErrorCritical( char severity, @@ -565,7 +567,7 @@ void openserial_handleCommands(void){ case COMMAND_SET_CHANNEL: // set communication channel for protocol stack ieee154e_setSingleChannel(comandParam_8); // one byte - // set listenning channel for sniffer + // set listening channel for sniffer sniffer_setListeningChannel(comandParam_8); // one byte break; case COMMAND_SET_KAPERIOD: // two bytes, in slots diff --git a/openstack/02a-MAClow/IEEE802154E.c b/openstack/02a-MAClow/IEEE802154E.c index a15deb88c1..3ea5e7bf43 100644 --- a/openstack/02a-MAClow/IEEE802154E.c +++ b/openstack/02a-MAClow/IEEE802154E.c @@ -475,14 +475,9 @@ port_INLINE void activity_synchronize_newSlot() { // increment ASN (used only to schedule serial activity) incrementAsnOffset(); - // to be able to receive and transmist serial even when not synchronized - // take turns every 8 slots sending and receiving + // trigger to debug stuff to be printed every 16 slots if ((ieee154e_vars.asn.bytes0and1&0x000f)==0x0000) { - openserial_stop(); - openserial_startOutput(); - } else if ((ieee154e_vars.asn.bytes0and1&0x000f)==0x0008) { - openserial_stop(); - openserial_startInput(); + openserial_triggerDebugprint(); } } @@ -496,8 +491,8 @@ port_INLINE void activity_synchronize_startOfFrame(PORT_RADIOTIMER_WIDTH capture // change state changeState(S_SYNCRX); - // stop the serial - openserial_stop(); + // inihibit serial activity + openserial_inhibitStart(); // record the captured time ieee154e_vars.lastCapturedTime = capturedTime; @@ -908,12 +903,13 @@ port_INLINE void activity_ti1ORri1() { } } else { // this is NOT the next active slot, abort - // stop using serial - openserial_stop(); - // abort the slot + + // abort the slot endSlot(); - //start outputing serial - openserial_startOutput(); + + // trigger debug prints + openserial_triggerDebugprint(); + return; } @@ -922,8 +918,8 @@ port_INLINE void activity_ti1ORri1() { switch (cellType) { case CELLTYPE_TXRX: case CELLTYPE_TX: - // stop using serial - openserial_stop(); + // inhibit serial activity + openserial_inhibitStart(); // assuming that there is nothing to send ieee154e_vars.dataToSend = NULL; // check whether we can send @@ -964,8 +960,8 @@ port_INLINE void activity_ti1ORri1() { } case CELLTYPE_RX: if (changeToRX==FALSE) { - // stop using serial - openserial_stop(); + // inhibit serial activity + openserial_inhibitStart(); } // change state changeState(S_RXDATAOFFSET); @@ -973,15 +969,14 @@ port_INLINE void activity_ti1ORri1() { radiotimer_schedule(DURATION_rt1); break; case CELLTYPE_SERIALRX: - // stop using serial - openserial_stop(); // abort the slot endSlot(); - //start inputting serial data - openserial_startInput(); + // enable serial + openserial_inhibitStop(); + //this is to emulate a set of serial input slots without having the slotted structure. - //skip the serial rx slots + // skip the serial rx slots ieee154e_vars.numOfSleepSlots = NUMSERIALRX; //increase ASN by NUMSERIALRX-1 slots as at this slot is already incremented by 1 @@ -1017,8 +1012,8 @@ port_INLINE void activity_ti1ORri1() { // do nothing (not even endSlot()) break; default: - // stop using serial - openserial_stop(); + // inhibit serial activity + openserial_inhibitStart(); // log the error openserial_printCritical(COMPONENT_IEEE802154E,ERR_WRONG_CELLTYPE, (errorparameter_t)cellType, @@ -2235,10 +2230,12 @@ void endSlot() { // turn off the radio radio_rfOff(); + // compute the duty cycle if radio has been turned on if (ieee154e_vars.radioOnThisSlot==TRUE){ ieee154e_vars.radioOnTics+=(radio_getTimerValue()-ieee154e_vars.radioOnInit); } + // clear any pending timer radiotimer_cancel(); @@ -2246,7 +2243,7 @@ void endSlot() { ieee154e_vars.lastCapturedTime = 0; ieee154e_vars.syncCapturedTime = 0; - //computing duty cycle. + // computing duty cycle. ieee154e_stats.numTicsOn+=ieee154e_vars.radioOnTics;//accumulate and tics the radio is on for that window ieee154e_stats.numTicsTotal+=radio_getTimerPeriod();//increment total tics by timer period. @@ -2254,8 +2251,8 @@ void endSlot() { ieee154e_stats.numTicsTotal = ieee154e_stats.numTicsTotal>>1; ieee154e_stats.numTicsOn = ieee154e_stats.numTicsOn>>1; } - - //clear vars for duty cycle on this slot + + // clear vars for duty cycle on this slot ieee154e_vars.radioOnTics=0; ieee154e_vars.radioOnThisSlot=FALSE; @@ -2308,7 +2305,6 @@ void endSlot() { ieee154e_vars.ackReceived = NULL; } - // change state changeState(S_SLEEP); } diff --git a/openstack/02a-MAClow/IEEE802154_security.c b/openstack/02a-MAClow/IEEE802154_security.c index 20f9b7c579..ab5b52d75c 100755 --- a/openstack/02a-MAClow/IEEE802154_security.c +++ b/openstack/02a-MAClow/IEEE802154_security.c @@ -15,6 +15,7 @@ #include "idmanager.h" #include "openserial.h" #include "IEEE802154_security.h" +#include "debugpins.h" //=============================define========================================== diff --git a/openstack/02b-MAChigh/schedule.c b/openstack/02b-MAChigh/schedule.c index e5ca0ea8be..2cb0b1ba40 100644 --- a/openstack/02b-MAChigh/schedule.c +++ b/openstack/02b-MAChigh/schedule.c @@ -6,6 +6,7 @@ #include "sixtop.h" #include "idmanager.h" #include "sf0.h" +#include "debugpins.h" //=========================== variables ======================================= diff --git a/openstack/03a-IPHC/openbridge.c b/openstack/03a-IPHC/openbridge.c index d7a7a47576..99da641cf9 100644 --- a/openstack/03a-IPHC/openbridge.c +++ b/openstack/03a-IPHC/openbridge.c @@ -9,6 +9,7 @@ //=========================== variables ======================================= //=========================== prototypes ====================================== + //=========================== public ========================================== void openbridge_init() { @@ -19,7 +20,7 @@ void openbridge_triggerData() { OpenQueueEntry_t* pkt; uint8_t numDataBytes; - numDataBytes = openserial_getInputBufferFilllevel(); + numDataBytes = openserial_getInputBufferFillLevel(); //poipoi xv //this is a temporal workaround as we are never supposed to get chunks of data diff --git a/openstack/cross-layers/idmanager.c b/openstack/cross-layers/idmanager.c index e3d68966ab..2e146bbbda 100644 --- a/openstack/cross-layers/idmanager.c +++ b/openstack/cross-layers/idmanager.c @@ -5,6 +5,7 @@ #include "openserial.h" #include "neighbors.h" #include "schedule.h" +#include "debugpins.h" //=========================== variables ======================================= diff --git a/openstack/cross-layers/openqueue.c b/openstack/cross-layers/openqueue.c index d901da0e43..d656f69b3b 100644 --- a/openstack/cross-layers/openqueue.c +++ b/openstack/cross-layers/openqueue.c @@ -4,6 +4,7 @@ #include "packetfunctions.h" #include "IEEE802154E.h" #include "ieee802154_security_driver.h" +#include "debugpins.h" //=========================== variables ======================================= From d4b20a4354187221f23b7db7bf041cb7e91a94ee Mon Sep 17 00:00:00 2001 From: Thomas Watteyne Date: Mon, 29 Aug 2016 17:46:23 +0200 Subject: [PATCH 05/99] FW-540. new openserial works ~50% of the time. Wrong CRC problems. --- .gitignore | 1 + bsp/boards/telosb/board.c | 14 +++++++++++ bsp/boards/telosb/board_info.h | 1 - drivers/common/openserial.c | 5 +++- drivers/common/openserial.h | 2 +- openapps/SConscript | 4 ++-- openapps/openapps.c | 4 ++-- openstack/02a-MAClow/IEEE802154E.c | 16 +++++++++---- openstack/03b-IPv6/forwarding.c | 6 ++--- openstack/SConscript | 4 ++-- openstack/openstack.c | 4 ++-- projects/common/03oos_openwsn/03oos_openwsn.c | 2 ++ projects/python/SConscript.env | 4 ++-- .../telosb/03oos_openwsn/03oos_openwsn.ewp | 23 +++++++++++-------- 14 files changed, 59 insertions(+), 31 deletions(-) diff --git a/.gitignore b/.gitignore index 030e729914..051bd9af16 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ settings /projects/telosb/03oos_openwsn/path.txt /projects/telosb/02drv_openserial/path.txt /projects/telosb/01bsp_uart/path.txt +/projects/telosb/03oos_macpong/path.txt diff --git a/bsp/boards/telosb/board.c b/bsp/boards/telosb/board.c index 47f2b1c632..2f3c007e97 100644 --- a/bsp/boards/telosb/board.c +++ b/bsp/boards/telosb/board.c @@ -19,6 +19,20 @@ //=========================== prototypes ====================================== + +//=========================== low-level init ================================== + +#if defined(__GNUC__) && (__GNUC__==4) && (__GNUC_MINOR__<=5) && defined(__MSP430__) + +#else + // tell IAR NOT to intialize all variables + // see https://www.iar.com/support/tech-notes/general/my-msp430-does-not-start-up/ +int __low_level_init(void) { + WDTCTL = WDTPW + WDTHOLD; + return 1; +} +#endif + //=========================== main ============================================ extern int mote_main(void); diff --git a/bsp/boards/telosb/board_info.h b/bsp/boards/telosb/board_info.h index 7d17fd7f86..308089452e 100644 --- a/bsp/boards/telosb/board_info.h +++ b/bsp/boards/telosb/board_info.h @@ -32,7 +32,6 @@ to this board. debugpins_intdisabled_set(); #define ENABLE_INTERRUPTS() debugpins_intdisabled_clr(); \ __set_interrupt_state(s); - #endif //===== timer diff --git a/drivers/common/openserial.c b/drivers/common/openserial.c index 318085567b..7ba1fbe99e 100644 --- a/drivers/common/openserial.c +++ b/drivers/common/openserial.c @@ -42,7 +42,7 @@ owerror_t openserial_printInfoErrorCritical( ); // command handlers -void openserial_handleRxFrame(); +void openserial_handleRxFrame(void); void openserial_handleEcho(uint8_t* but, uint8_t bufLen); void openserial_handleCommands(void); @@ -527,6 +527,8 @@ void openserial_handleEcho(uint8_t* buf, uint8_t bufLen){ } void openserial_handleCommands(void){ + return; + /* uint8_t input_buffer[10]; uint8_t numDataBytes; uint8_t commandId; @@ -667,6 +669,7 @@ void openserial_handleCommands(void){ // wrong command ID break; } + */ } //===== misc diff --git a/drivers/common/openserial.h b/drivers/common/openserial.h index 7fe43c8f4f..7df6c3883f 100644 --- a/drivers/common/openserial.h +++ b/drivers/common/openserial.h @@ -144,7 +144,7 @@ owerror_t openserial_printSniffedPacket( uint8_t length, uint8_t channel ); -void openserial_triggerDebugprint(); +void openserial_triggerDebugprint(void); // receiving uint8_t openserial_getInputBufferFillLevel(void); diff --git a/openapps/SConscript b/openapps/SConscript index 36175885b0..6d9eb503c2 100644 --- a/openapps/SConscript +++ b/openapps/SConscript @@ -12,7 +12,7 @@ defaultApps = [ 'cinfo', 'cleds', 'cwellknown', - 'techo', + #'techo', 'uecho', 'uinject', 'userialbridge', @@ -30,7 +30,7 @@ defaultAppsInit = [ 'cinfo', 'cleds', 'cwellknown', - 'techo', + #'techo', 'uecho', 'rrt', 'uinject', diff --git a/openapps/openapps.c b/openapps/openapps.c index b1553b3327..c89b967500 100644 --- a/openapps/openapps.c +++ b/openapps/openapps.c @@ -38,7 +38,7 @@ void openapps_init(void) { cwellknown_init(); rrt_init(); // TCP - techo_init(); + //techo_init(); // UDP -// uecho_init(); + // uecho_init(); } \ No newline at end of file diff --git a/openstack/02a-MAClow/IEEE802154E.c b/openstack/02a-MAClow/IEEE802154E.c index 3ea5e7bf43..3f9387966e 100644 --- a/openstack/02a-MAClow/IEEE802154E.c +++ b/openstack/02a-MAClow/IEEE802154E.c @@ -475,8 +475,8 @@ port_INLINE void activity_synchronize_newSlot() { // increment ASN (used only to schedule serial activity) incrementAsnOffset(); - // trigger to debug stuff to be printed every 16 slots - if ((ieee154e_vars.asn.bytes0and1&0x000f)==0x0000) { + // trigger to debug stuff to be printed every 2 slots + if ((ieee154e_vars.asn.bytes0and1&0x0001)==0x0000) { openserial_triggerDebugprint(); } } @@ -488,12 +488,12 @@ port_INLINE void activity_synchronize_startOfFrame(PORT_RADIOTIMER_WIDTH capture return; } - // change state - changeState(S_SYNCRX); - // inihibit serial activity openserial_inhibitStart(); + // change state + changeState(S_SYNCRX); + // record the captured time ieee154e_vars.lastCapturedTime = capturedTime; @@ -662,6 +662,9 @@ port_INLINE void activity_synchronize_endOfFrame(PORT_RADIOTIMER_WIDTH capturedT // return to listening state changeState(S_SYNCLISTEN); + + // enable serial + openserial_inhibitStop(); } port_INLINE bool ieee154e_processIEs(OpenQueueEntry_t* pkt, uint16_t* lenIE) { @@ -2307,6 +2310,9 @@ void endSlot() { // change state changeState(S_SLEEP); + + // resume serial activity + openserial_inhibitStop(); } bool ieee154e_isSynch(){ diff --git a/openstack/03b-IPv6/forwarding.c b/openstack/03b-IPv6/forwarding.c index 53897055d3..883e6bc21f 100644 --- a/openstack/03b-IPv6/forwarding.c +++ b/openstack/03b-IPv6/forwarding.c @@ -9,7 +9,7 @@ #include "icmpv6.h" #include "icmpv6rpl.h" #include "openudp.h" -#include "opentcp.h" +//#include "opentcp.h" #include "debugpins.h" #include "scheduler.h" @@ -190,7 +190,7 @@ void forwarding_sendDone(OpenQueueEntry_t* msg, owerror_t error) { // indicate sendDone to upper layer switch(msg->l4_protocol) { case IANA_TCP: - opentcp_sendDone(msg,error); + //opentcp_sendDone(msg,error); break; case IANA_UDP: openudp_sendDone(msg,error); @@ -260,7 +260,7 @@ void forwarding_receive( // indicate received packet to upper layer switch(msg->l4_protocol) { case IANA_TCP: - opentcp_receive(msg); + //opentcp_receive(msg); break; case IANA_UDP: openudp_receive(msg); diff --git a/openstack/SConscript b/openstack/SConscript index 7296c2920b..5ed9e217a5 100644 --- a/openstack/SConscript +++ b/openstack/SConscript @@ -30,7 +30,7 @@ sources_c = [ os.path.join('03b-IPv6','icmpv6rpl.c'), #=== 04-TRAN os.path.join('04-TRAN','opencoap.c'), - os.path.join('04-TRAN','opentcp.c'), + #os.path.join('04-TRAN','opentcp.c'), os.path.join('04-TRAN','openudp.c'), #=== cross-layers os.path.join('cross-layers','idmanager.c'), @@ -117,7 +117,7 @@ else: os.path.join('#','openapps','cstorm'), os.path.join('#','openapps','cwellknown'), os.path.join('#','openapps','rrt'), - os.path.join('#','openapps','techo'), + #os.path.join('#','openapps','techo'), os.path.join('#','openapps','tohlone'), os.path.join('#','openapps','uecho'), os.path.join('#','openapps','uinject'), diff --git a/openstack/openstack.c b/openstack/openstack.c index 9ec1018aa2..09fcbaccd2 100644 --- a/openstack/openstack.c +++ b/openstack/openstack.c @@ -32,7 +32,7 @@ #include "icmpv6echo.h" #include "icmpv6rpl.h" //-- 04-TRAN -#include "opentcp.h" +//#include "opentcp.h" #include "openudp.h" #include "opencoap.h" //===== applications @@ -75,7 +75,7 @@ void openstack_init(void) { icmpv6echo_init(); icmpv6rpl_init(); //-- 04-TRAN - opentcp_init(); + //opentcp_init(); openudp_init(); opencoap_init(); // initialize before any of the CoAP applications diff --git a/projects/common/03oos_openwsn/03oos_openwsn.c b/projects/common/03oos_openwsn/03oos_openwsn.c index f8dcaec94b..41b18cb352 100644 --- a/projects/common/03oos_openwsn/03oos_openwsn.c +++ b/projects/common/03oos_openwsn/03oos_openwsn.c @@ -26,3 +26,5 @@ int mote_main(void) { } void sniffer_setListeningChannel(uint8_t channel){return;} + + diff --git a/projects/python/SConscript.env b/projects/python/SConscript.env index 42d0cb4236..f46c58f6fc 100644 --- a/projects/python/SConscript.env +++ b/projects/python/SConscript.env @@ -81,7 +81,7 @@ buildEnv.Append( os.path.join('#','build','python_gcc','openapps','cleds'), os.path.join('#','build','python_gcc','openapps','cstorm'), os.path.join('#','build','python_gcc','openapps','cwellknown'), - os.path.join('#','build','python_gcc','openapps','techo'), + #os.path.join('#','build','python_gcc','openapps','techo'), os.path.join('#','build','python_gcc','openapps','tohlone'), os.path.join('#','build','python_gcc','openapps','uecho'), os.path.join('#','build','python_gcc','openapps','uinject'), @@ -897,7 +897,7 @@ headerFiles = [ 'cleds', 'cstorm', 'cwellknown', - 'techo', + #'techo', 'tohlone', 'uecho', 'uinject', diff --git a/projects/telosb/03oos_openwsn/03oos_openwsn.ewp b/projects/telosb/03oos_openwsn/03oos_openwsn.ewp index e7a597f8da..27517a84d5 100644 --- a/projects/telosb/03oos_openwsn/03oos_openwsn.ewp +++ b/projects/telosb/03oos_openwsn/03oos_openwsn.ewp @@ -67,20 +67,20 @@