////////////////////////////////////////////////////////////////////////////// /// /// Convert FIFO to UART /// ////////////////////////////////////////////////////////////////////////////// void output_writer::thread(void) { while(1) { send2UART(readFIFO()); } }
BOOL processSidNetCommand (void) { if(SIDNetCmd.incomplete) { if(SIDNetCmd.dataLength > FIFORemaining(SIDNetCmd.cmdFifo)) { SIDNetCmd.incomplete = TRUE; return; } } else { if(FIFOCount(SIDNetCmd.cmdFifo) < 4) return; SIDNetCmd.cmd = readFIFO(SIDNetCmd.cmdFifo) & 0xFF; SIDNetCmd.sid = readFIFO(SIDNetCmd.cmdFifo) & 0xFF; SIDNetCmd.dataLength = ((readFIFO(SIDNetCmd.cmdFifo) & 0xFF) << 8) | (readFIFO(SIDNetCmd.cmdFifo) &0xFF); #ifdef DEBUG char buf[100]; sprintf(buf,"Cmd %d Sid %d DataLen %d\r\n\0",SIDNetCmd.cmd,SIDNetCmd.sid,SIDNetCmd.dataLength); writeStringUART(buf,strlen(buf)); #endif if(SIDNetCmd.dataLength > MAX_DATA) { #ifdef DEBUG char buf[100]; sprintf(buf,"Max data length %d exceeded %d \r\n\0",MAX_DATA,SIDNetCmd.dataLength); writeStringUART(buf,strlen(buf)); #endif while(1); } if(SIDNetCmd.dataLength > FIFORemaining(SIDNetCmd.cmdFifo)) { SIDNetCmd.incomplete = TRUE; return; } } SIDNetCmd.incomplete = FALSE; _copyCmdData(); _processSidNetCommand(); }
void SCKServer::json_update(uint16_t updates, long *value, char *time, boolean isMultipart) { #if debugServer Serial.print(F("[")); #endif Serial1.print(F("[")); for (int i = 0; i< updates;i++) { readFIFO(); if ((i< (updates - 1)) || (isMultipart)) { Serial1.print(F(",")); #if debugServer Serial.print(F(",")); #endif } } if (isMultipart) { byte i; for (i = 0; i<9; i++) { Serial1.print(SERVER[i]); Serial1.print(value[i]); } Serial1.print(SERVER[i]); Serial1.print(time); Serial1.print(SERVER[i+1]); Serial1.println(F("]")); Serial1.println(); #if debugServer for (i = 0; i<9; i++) { Serial.print(SERVER[i]); Serial.print(value[i]); } Serial.print(SERVER[i]); Serial.print(time); Serial.print(SERVER[i+1]); #endif } Serial1.println(F("]")); Serial1.println(); #if debugServer Serial.println(F("]")); #endif }
ssize_t readMessage(int nPipe, char* pBuffer, ssize_t nSize) { struct pollfd aPoll; aPoll.fd = nPipe; aPoll.events = POLLIN; aPoll.revents = 0; const int nPoll = poll(&aPoll, 1, CHILD_TIMEOUT_SECS * 1000); if ( nPoll < 0 ) return -1; if ( nPoll == 0 ) errno = ETIME; if( (aPoll.revents & POLLIN) != 0 ) return readFIFO(nPipe, pBuffer, nSize); return -1; }
ssize_t readMessage(int pipe, char* buffer, ssize_t size) { struct pollfd pollPipe; pollPipe.fd = pipe; pollPipe.events = POLLIN; pollPipe.revents = 0; const int nPoll = poll(&pollPipe, 1, CHILD_TIMEOUT_SECS * 1000); if ( nPoll < 0 ) return -1; if ( nPoll == 0 ) errno = ETIME; if( (pollPipe.revents & POLLIN) != 0 ) return readFIFO(pipe, buffer, size); return -1; }
ssize_t readMessage(int nPipe, char* pBuffer, ssize_t nSize) { ssize_t nBytes = -1; struct pollfd aPoll; aPoll.fd = nPipe; aPoll.events = POLLIN; aPoll.revents = 0; int nPoll = poll(&aPoll, 1, 3000); if ( nPoll < 0 ) goto ErrorPoll; if ( nPoll == 0 ) errno = ETIME; if( (aPoll.revents & POLLIN) != 0 ) nBytes = readFIFO(nPipe, pBuffer, nSize); ErrorPoll: return nBytes; }
void __ISR(_I2C_2_VECTOR, ipl3) _SlaveI2CHandler(void) { int temp; // check for MASTER and Bus events and respond accordingly if (IFS1bits.I2C2MIF == 1) { IFS1CLR = 0x02000000; return; } if (IFS1bits.I2C2BIF == 1) { IFS1CLR = 0x02000000; return; } // handle the incoming message if ((I2C2STATbits.R_W == 0) && (I2C2STATbits.D_A == 0)) { // R/W bit = 0 --> indicates data transfer is input to slave // D/A bit = 0 --> indicates last byte was address temp = I2C2RCV; I2C2CONbits.SCLREL = 1; // release the clock } else if ((I2C2STATbits.R_W == 0) && (I2C2STATbits.D_A == 1)) { // R/W bit = 0 --> indicates data transfer is input to slave // D/A bit = 1 --> indicates last byte was data // mLED_3_On(); // mLED_2_On(); // writing data to our module, just store it in adcSample //dataRead = SlaveReadI2C2(); if (writeFIFO(g_i2c_receiveBuffer, I2C2RCV) > 0) { // release the clock to restart I2C I2C2CONbits.SCLREL = 1; // release clock stretch bit g_receiveBufferFull = FALSE; } else { temp = I2C2RCV; g_receiveBufferFull = TRUE; I2C2CONbits.SCLREL = 1; } } else if ((I2C2STATbits.R_W == 1) && (I2C2STATbits.D_A == 0)) { temp = I2C2RCV; temp = readFIFO(g_i2c_transmitBuffer); if (temp > 0) { I2C2TRN = temp & 0xFF; } else { I2C2TRN = 0; } I2C2CONbits.SCLREL = 1; } else if ((I2C2STATbits.R_W == 1) && (I2C2STATbits.D_A == 1)) { // R/W bit = 1 --> indicates data transfer is output from slave // D/A bit = 1 --> indicates last byte was data // output the data until the MASTER terminates the // transfer with a NACK, continuing reads return 0 temp = readFIFO(g_i2c_transmitBuffer); if (temp > 0) { I2C2TRN = temp & 0xFF; } else { I2C2TRN = 0; } I2C2CONbits.SCLREL = 1; } // finally clear the slave interrupt flag IFS1CLR = 0x02000000; }
void _copyCmdData() { int i; for(i=0;i<SIDNetCmd.dataLength;i++) { SIDNetCmd.data[i] = readFIFO(SIDNetCmd.cmdFifo) & 0xFF; } }