// C++ level interrupt handler for this instance // RH_RF69 is unusual in Mthat it has several interrupt lines, and not a single, combined one. // On Moteino, only one of the several interrupt lines (DI0) from the RH_RF69 is connnected to the processor. // We use this to get PACKETSDENT and PAYLOADRADY interrupts. void RH_RF69::handleInterrupt() { // Get the interrupt cause uint8_t irqflags2 = spiRead(RH_RF69_REG_28_IRQFLAGS2); if (_mode == RHModeTx && (irqflags2 & RH_RF69_IRQFLAGS2_PACKETSENT)) { // A transmitter message has been fully sent setModeIdle(); // Clears FIFO // Serial.println("PACKETSENT"); } // Must look for PAYLOADREADY, not CRCOK, since only PAYLOADREADY occurs _after_ AES decryption // has been done if (_mode == RHModeRx && (irqflags2 & RH_RF69_IRQFLAGS2_PAYLOADREADY)) { // A complete message has been received with good CRC _lastRssi = -((int8_t)(spiRead(RH_RF69_REG_24_RSSIVALUE) >> 1)); _lastPreambleTime = millis(); setModeIdle(); // Save it in our buffer readFifo(); // Serial.println("PAYLOADREADY"); }
int devRead(myDev * dev, char * data, size_t dataSize) { int taskId; fifo * i; msg * buff = (msg*)data; int buffSize = dataSize/sizeof(msg); //I can't see any reason why sizeof(msg) //should change, but let's not take any chances int msgsRead = 0; printf("1\n"); taskId = taskIdSelf(); printf("2\n"); if (dev==NULL) { errnoSet(NOT_OPEN); return -1; } //we'll only send whole messages, thus if dataSize<sizeof(msg), //we can't send anything : if (dataSize<sizeof(msg)) { errnoSet(SHORT_BUFF); return -1; } printf("3\n"); if(semTake(dev->semMData,WAIT_FOREVER)==-1) { errnoSet(SEM_ERR); return -1; } printf("4\n"); //find out wich fifo is our own: for (i=dev->firstFifo; i!=NULL && i->taskId!=taskId; i=i->nextFifo); if (i==NULL) { errnoSet(NOT_OPEN); return -1; } printf("5\n"); semGive(dev->semMData); printf("6\n"); if (i==NULL) { //We have nothing to write on? This shouldn't happen either... errnoSet(NOT_REGISTERED); return -1; } printf("7\n"); readFifo(i,&(buff[0]), WAIT_FOREVER); //First call block if fifo empty, cf specs. printf("8\n"); msgsRead++; printf("9, bufferSize=%d, msgsRead=%d\n",buffSize,msgsRead); while (msgsRead<buffSize && readFifo(i,&(buff[msgsRead]),NO_WAIT)==0) { //Let's read messages until fifo is empty or until the data buffer is //to full to take whole messages msgsRead++; printf("9.1\n"); } printf("10\n"); return msgsRead*sizeof(msg); }