// File: /workspace/github_c_makefile_star2_O2/lupyuen[P]lora-sx1262/src/radio.c
// Function: RadioIrqProcess
void RadioIrqProcess( void )
{
    printf("RadioIrqProcess\r\n");
    CRITICAL_SECTION_BEGIN( );
    // Clear IRQ flag
    const bool isIrqFired = IrqFired;
    IrqFired = false;
    CRITICAL_SECTION_END( );

    if( isIrqFired == true )
    {
        uint16_t irqRegs = SX126xGetIrqStatus( );
        SX126xClearIrqStatus( irqRegs );

        // Check if DIO1 pin is High. If it is the case revert IrqFired to true
        CRITICAL_SECTION_BEGIN( );
        if( SX126xGetDio1PinState( ) == 1 )
        {
            IrqFired = true;
        }
        CRITICAL_SECTION_END( );

        if( ( irqRegs & IRQ_TX_DONE ) == IRQ_TX_DONE )
        {
            printf("IRQ_TX_DONE\r\n");
            TimerStop( &TxTimeoutTimer );
            //!< Update operating mode state to a value lower than \ref MODE_STDBY_XOSC
            SX126xSetOperatingMode( MODE_STDBY_RC );
            if( ( RadioEvents.TxDone != NULL ) )
            {
                RadioEvents.TxDone( );
            }
        }

        if( ( irqRegs & IRQ_RX_DONE ) == IRQ_RX_DONE )
        {
            printf("IRQ_RX_DONE\r\n");
            TimerStop( &RxTimeoutTimer );

            if( ( irqRegs & IRQ_CRC_ERROR ) == IRQ_CRC_ERROR )
            {
                if( RxContinuous == false )
                {
                    //!< Update operating mode state to a value lower than \ref MODE_STDBY_XOSC
                    SX126xSetOperatingMode( MODE_STDBY_RC );
                }
                if( ( RadioEvents.RxError ) )
                {
                    RadioEvents.RxError( );
                }
            }
            else
            {
                uint8_t size;

                if( RxContinuous == false )
                {
                    //!< Update operating mode state to a value lower than \ref MODE_STDBY_XOSC
                    SX126xSetOperatingMode( MODE_STDBY_RC );

                    // WORKAROUND - Implicit Header Mode Timeout Behavior, see DS_SX1261-2_V1.2 datasheet chapter 15.3
                    SX126xWriteRegister( REG_RTC_CTRL, 0x00 );
                    SX126xWriteRegister( REG_EVT_CLR, SX126xReadRegister( REG_EVT_CLR ) | ( 1 << 1 ) );
                    // WORKAROUND END
                }
                SX126xGetPayload( RadioRxPayload, &size , 255 );
                SX126xGetPacketStatus( &RadioPktStatus );
                if( ( RadioEvents.RxDone != NULL ) )
                {
                    RadioEvents.RxDone( RadioRxPayload, size, RadioPktStatus.Params.LoRa.RssiPkt, RadioPktStatus.Params.LoRa.SnrPkt );
                }
            }
        }

        if( ( irqRegs & IRQ_CAD_DONE ) == IRQ_CAD_DONE )
        {
            printf("IRQ_CAD_DONE\r\n");
            //!< Update operating mode state to a value lower than \ref MODE_STDBY_XOSC
            SX126xSetOperatingMode( MODE_STDBY_RC );
            if( ( RadioEvents.CadDone != NULL ) )
            {
                RadioEvents.CadDone( ( ( irqRegs & IRQ_CAD_ACTIVITY_DETECTED ) == IRQ_CAD_ACTIVITY_DETECTED ) );
            }
        }

        if( ( irqRegs & IRQ_RX_TX_TIMEOUT ) == IRQ_RX_TX_TIMEOUT )
        {
            printf("IRQ_RX_TX_TIMEOUT\r\n");
            if( SX126xGetOperatingMode( ) == MODE_TX )
            {
                TimerStop( &TxTimeoutTimer );
                //!< Update operating mode state to a value lower than \ref MODE_STDBY_XOSC
                SX126xSetOperatingMode( MODE_STDBY_RC );
                if( ( RadioEvents.TxTimeout != NULL ) )
                {
                    RadioEvents.TxTimeout( );
                }
            }
            else if( SX126xGetOperatingMode( ) == MODE_RX )
            {
                TimerStop( &RxTimeoutTimer );
                //!< Update operating mode state to a value lower than \ref MODE_STDBY_XOSC
                SX126xSetOperatingMode( MODE_STDBY_RC );
                if( ( RadioEvents.RxTimeout != NULL ) )
                {
                    RadioEvents.RxTimeout( );
                }
            }
        }

        if( ( irqRegs & IRQ_PREAMBLE_DETECTED ) == IRQ_PREAMBLE_DETECTED )
        {
            printf("IRQ_PREAMBLE_DETECTED\r\n");
            //__NOP( );
        }

        if( ( irqRegs & IRQ_SYNCWORD_VALID ) == IRQ_SYNCWORD_VALID )
        {
            printf("IRQ_SYNCWORD_VALID\r\n");
            //__NOP( );
        }

        if( ( irqRegs & IRQ_HEADER_VALID ) == IRQ_HEADER_VALID )
        {
            printf("IRQ_HEADER_VALID\r\n");
            //__NOP( );
        }

        if( ( irqRegs & IRQ_HEADER_ERROR ) == IRQ_HEADER_ERROR )
        {
            printf("IRQ_HEADER_ERROR\r\n");
            TimerStop( &RxTimeoutTimer );
            if( RxContinuous == false )
            {
                //!< Update operating mode state to a value lower than \ref MODE_STDBY_XOSC
                SX126xSetOperatingMode( MODE_STDBY_RC );
            }
            if( ( RadioEvents.RxTimeout != NULL ) )
            {
                RadioEvents.RxTimeout( );
            }
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
leaq 0x2e08(%rip), %rdi      # 0x65c3
callq 0x2280
movb 0x6a83(%rip), %al       # 0xa249
movb $0x0, 0x6a7c(%rip)      # 0xa249
cmpb $0x1, %al
jne 0x39f3
callq 0x4200
movzwl %ax, %ebx
movl %ebx, %edi
callq 0x4758
callq 0x4d85
cmpl $0x1, %eax
jne 0x37f5
movb $0x1, 0x6a54(%rip)      # 0xa249
testb $0x1, %bl
je 0x3828
leaq 0x2dd3(%rip), %rdi      # 0x65d4
callq 0x2280
leaq 0x6a8b(%rip), %rdi      # 0xa298
callq 0x4e12
pushq $0x1
popq %rdi
callq 0x489d
movq 0x6a2f(%rip), %rax      # 0xa250
testq %rax, %rax
je 0x3828
callq *%rax
testb $0x2, %bl
je 0x38f1
leaq 0x2da9(%rip), %rdi      # 0x65e1
callq 0x2280
leaq 0x6a8c(%rip), %rdi      # 0xa2d0
callq 0x4e12
testb $0x40, %bl
jne 0x38d2
cmpb $0x0, 0x69ef(%rip)      # 0xa248
jne 0x3888
pushq $0x1
popq %rdi
callq 0x489d
movl $0x902, %edi            # imm = 0x902
xorl %esi, %esi
callq 0x4c2e
movl $0x944, %edi            # imm = 0x944
callq 0x4c96
orb $0x2, %al
movzbl %al, %esi
movl $0x944, %edi            # imm = 0x944
callq 0x4c2e
leaq 0x6b01(%rip), %rdi      # 0xa390
leaq -0x9(%rbp), %rsi
movl $0xff, %edx
callq 0x3c2e
leaq 0x6bec(%rip), %rdi      # 0xa490
callq 0x4652
movq 0x69b0(%rip), %rax      # 0xa260
testq %rax, %rax
je 0x38f1
movzbl -0x9(%rbp), %esi
movsbl 0x6bdc(%rip), %edx      # 0xa49c
movsbl 0x6bd6(%rip), %ecx      # 0xa49d
leaq 0x6ac2(%rip), %rdi      # 0xa390
callq *%rax
jmp 0x38f1
cmpb $0x0, 0x696f(%rip)      # 0xa248
jne 0x38e3
pushq $0x1
popq %rdi
callq 0x489d
movq 0x6986(%rip), %rax      # 0xa270
testq %rax, %rax
je 0x38f1
callq *%rax
testb %bl, %bl
jns 0x391f
leaq 0x2cf2(%rip), %rdi      # 0x65ee
callq 0x2280
pushq $0x1
popq %rdi
callq 0x489d
movq 0x6970(%rip), %rax      # 0xa280
testq %rax, %rax
je 0x391f
movl %ebx, %edi
shrl $0x8, %edi
andl $0x1, %edi
callq *%rax
btl $0x9, %ebx
jae 0x3984
leaq 0x2cd0(%rip), %rdi      # 0x65fc
callq 0x2280
callq 0x4891
cmpl $0x4, %eax
jne 0x3958
leaq 0x6956(%rip), %rdi      # 0xa298
callq 0x4e12
pushq $0x1
popq %rdi
callq 0x489d
movq 0x6902(%rip), %rax      # 0xa258
jmp 0x397d
callq 0x4891
cmpl $0x5, %eax
jne 0x3984
leaq 0x6967(%rip), %rdi      # 0xa2d0
callq 0x4e12
pushq $0x1
popq %rdi
callq 0x489d
movq 0x68eb(%rip), %rax      # 0xa268
testq %rax, %rax
je 0x3984
callq *%rax
testb $0x4, %bl
je 0x3995
leaq 0x2c7f(%rip), %rdi      # 0x660f
callq 0x2280
testb $0x8, %bl
je 0x39a6
leaq 0x2c85(%rip), %rdi      # 0x6626
callq 0x2280
testb $0x10, %bl
je 0x39b7
leaq 0x2c88(%rip), %rdi      # 0x663a
callq 0x2280
testb $0x20, %bl
je 0x39f3
leaq 0x2c89(%rip), %rdi      # 0x664c
callq 0x2280
leaq 0x6901(%rip), %rdi      # 0xa2d0
callq 0x4e12
cmpb $0x0, 0x686d(%rip)      # 0xa248
jne 0x39e5
pushq $0x1
popq %rdi
callq 0x489d
movq 0x687c(%rip), %rax      # 0xa268
testq %rax, %rax
je 0x39f3
callq *%rax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq