internal function - interrupt gets called when a packet is received
| 426 | |
| 427 | // internal function - interrupt gets called when a packet is received |
| 428 | void RFM69::interruptHandler() { |
| 429 | if (_mode == RF69_MODE_RX && (readReg(REG_IRQFLAGS2) & RF_IRQFLAGS2_PAYLOADREADY)) { |
| 430 | setMode(RF69_MODE_STANDBY); |
| 431 | select(); |
| 432 | _spi->transfer(REG_FIFO & 0x7F); |
| 433 | PAYLOADLEN = _spi->transfer(0); |
| 434 | PAYLOADLEN = PAYLOADLEN > 66 ? 66 : PAYLOADLEN; // precaution |
| 435 | TARGETID = _spi->transfer(0); |
| 436 | SENDERID = _spi->transfer(0); |
| 437 | uint8_t CTLbyte = _spi->transfer(0); |
| 438 | TARGETID |= (uint16_t(CTLbyte) & 0x0C) << 6; // 10 bit address (most significant 2 bits stored in bits(2,3) of CTL byte |
| 439 | SENDERID |= (uint16_t(CTLbyte) & 0x03) << 8; // 10 bit address (most sifnigicant 2 bits stored in bits(0,1) of CTL byte |
| 440 | |
| 441 | if(!(_spyMode || TARGETID == _address || TARGETID == RF69_BROADCAST_ADDR) // match this node's address, or broadcast address or anything in spy mode |
| 442 | || PAYLOADLEN < 3) // address situation could receive packets that are malformed and don't fit this libraries extra fields |
| 443 | { |
| 444 | PAYLOADLEN = 0; |
| 445 | unselect(); |
| 446 | receiveBegin(); |
| 447 | return; |
| 448 | } |
| 449 | |
| 450 | DATALEN = PAYLOADLEN - 3; |
| 451 | ACK_RECEIVED = CTLbyte & RFM69_CTL_SENDACK; // extract ACK-received flag |
| 452 | ACK_REQUESTED = CTLbyte & RFM69_CTL_REQACK; // extract ACK-requested flag |
| 453 | uint8_t _pl = _powerLevel; // interruptHook() can change _powerLevel so remember it |
| 454 | interruptHook(CTLbyte); // TWS: hook to derived class interrupt function |
| 455 | |
| 456 | for (uint8_t i = 0; i < DATALEN; i++) DATA[i] = _spi->transfer(0); |
| 457 | |
| 458 | DATA[DATALEN] = 0; // add null at end of string // add null at end of string |
| 459 | unselect(); |
| 460 | setMode(RF69_MODE_RX); |
| 461 | if (_pl != _powerLevel) setPowerLevel(_powerLevel); // set new _powerLevel if changed |
| 462 | } |
| 463 | RSSI = readRSSI(); |
| 464 | } |
| 465 | |
| 466 | // internal function |
| 467 | ISR_PREFIX void RFM69::isr0() { |
nothing calls this directly
no outgoing calls
no test coverage detected