/* Save the state of IRQ mask of LoRa as well as disable all IRQ. */
byIrqMask = SX1278Read(REG_LR_IRQFLAGSMASK);
SX1278Write(REG_LR_IRQFLAGSMASK, 0xFF); /* Bit=1 to masks IRQ */
/* Set radio in continuous reception. */
SX1278SetOpMode(RF_OPMODE_RECEIVER);
ulRandVal = 0;
for (chCnt = 0; chCnt < (8 * sizeof(ulRandVal)); ++chCnt)
{
DelayMs(1); /* Disperse sampled time. */
/* Unfiltered RSSI value reading. Only takes the LSB value */
ulRandVal |= ((uint32_t)SX1278Read(REG_LR_RSSIWIDEBAND) & 0x01) << chCnt;
}
SX1278SetOpMode(RF_OPMODE_SLEEP);
/* Restore the state of IRQ mask of LoRa */
SX1278Write(REG_LR_IRQFLAGSMASK, byIrqMask);