// File: /workspace/github_c_makefile_star2_O1/lupyuen[P]lora-sx1262/src/sx126x.c
// Function: SX126xSetPacketParams
void SX126xSetPacketParams( PacketParams_t *packetParams )
{
    uint8_t n;
    uint8_t crcVal = 0;
    uint8_t buf[9] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };

    // Check if required configuration corresponds to the stored packet type
    // If not, silently update radio packet type
    if( PacketType != packetParams->PacketType )
    {
        SX126xSetPacketType( packetParams->PacketType );
    }

    switch( packetParams->PacketType )
    {
    case PACKET_TYPE_GFSK:
        if( packetParams->Params.Gfsk.CrcLength == RADIO_CRC_2_BYTES_IBM )
        {
            SX126xSetCrcSeed( CRC_IBM_SEED );
            SX126xSetCrcPolynomial( CRC_POLYNOMIAL_IBM );
            crcVal = RADIO_CRC_2_BYTES;
        }
        else if( packetParams->Params.Gfsk.CrcLength == RADIO_CRC_2_BYTES_CCIT )
        {
            SX126xSetCrcSeed( CRC_CCITT_SEED );
            SX126xSetCrcPolynomial( CRC_POLYNOMIAL_CCITT );
            crcVal = RADIO_CRC_2_BYTES_INV;
        }
        else
        {
            crcVal = packetParams->Params.Gfsk.CrcLength;
        }
        n = 9;
        buf[0] = ( packetParams->Params.Gfsk.PreambleLength >> 8 ) & 0xFF;
        buf[1] = packetParams->Params.Gfsk.PreambleLength;
        buf[2] = packetParams->Params.Gfsk.PreambleMinDetect;
        buf[3] = ( packetParams->Params.Gfsk.SyncWordLength /*<< 3*/ ); // convert from byte to bit
        buf[4] = packetParams->Params.Gfsk.AddrComp;
        buf[5] = packetParams->Params.Gfsk.HeaderType;
        buf[6] = packetParams->Params.Gfsk.PayloadLength;
        buf[7] = crcVal;
        buf[8] = packetParams->Params.Gfsk.DcFree;
        break;
    case PACKET_TYPE_LORA:
        n = 6;
        buf[0] = ( packetParams->Params.LoRa.PreambleLength >> 8 ) & 0xFF;
        buf[1] = packetParams->Params.LoRa.PreambleLength;
        buf[2] = LoRaHeaderType = packetParams->Params.LoRa.HeaderType;
        buf[3] = packetParams->Params.LoRa.PayloadLength;
        buf[4] = packetParams->Params.LoRa.CrcMode;
        buf[5] = packetParams->Params.LoRa.InvertIQ;
        break;
    default:
    case PACKET_TYPE_NONE:
        return;
    }
    SX126xWriteCommand( RADIO_SET_PACKETPARAMS, buf, n );
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movb $0x0, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movl (%rdi), %eax
cmpl %eax, 0x5fab(%rip)      # 0xa49c
je 0x450e
leaq -0xc(%rbp), %rsi
movl %eax, (%rsi)
movl %eax, 0x5f9d(%rip)      # 0xa49c
movl $0x8a, %edi
movl $0x1, %edx
callq 0x4aff
movl (%rbx), %eax
cmpl $0x1, %eax
je 0x457e
testl %eax, %eax
jne 0x4658
movl 0x1c(%rbx), %eax
cmpl $0xf2, %eax
je 0x45b5
cmpl $0xf1, %eax
jne 0x45fb
movw $0xffff, -0xc(%rbp)     # imm = 0xFFFF
cmpl $0x0, 0x5f59(%rip)      # 0xa49c
jne 0x4558
leaq -0xc(%rbp), %rsi
movl $0x6bc, %edi            # imm = 0x6BC
movl $0x2, %edx
callq 0x4d1e
movw $0x580, -0xc(%rbp)      # imm = 0x580
cmpl $0x0, 0x5f37(%rip)      # 0xa49c
jne 0x457a
leaq -0xc(%rbp), %rsi
movl $0x6be, %edi            # imm = 0x6BE
movl $0x2, %edx
callq 0x4d1e
movb $0x2, %al
jmp 0x45fb
leaq -0x13(%rbp), %rcx
leaq -0x14(%rbp), %rdx
movzwl 0x24(%rbx), %eax
rolw $0x8, %ax
movw %ax, -0x4(%rdx)
movl 0x28(%rbx), %eax
movl %eax, 0x5f05(%rip)      # 0xa4a0
movb %al, -0x2(%rdx)
movb 0x2c(%rbx), %al
movb %al, -0x1(%rdx)
movb 0x30(%rbx), %al
movw $0x6, %si
movl $0x34, %edi
jmp 0x4640
movw $0xf1d, -0xc(%rbp)      # imm = 0xF1D
cmpl $0x0, 0x5eda(%rip)      # 0xa49c
jne 0x45d7
leaq -0xc(%rbp), %rsi
movl $0x6bc, %edi            # imm = 0x6BC
movl $0x2, %edx
callq 0x4d1e
movw $0x2110, -0xc(%rbp)     # imm = 0x2110
cmpl $0x0, 0x5eb8(%rip)      # 0xa49c
jne 0x45f9
leaq -0xc(%rbp), %rsi
movl $0x6be, %edi            # imm = 0x6BE
movl $0x2, %edx
callq 0x4d1e
movb $0x6, %al
leaq -0x10(%rbp), %rcx
leaq -0x11(%rbp), %rdx
movzwl 0x4(%rbx), %esi
rolw $0x8, %si
movw %si, -0x7(%rdx)
movb 0x8(%rbx), %sil
movb %sil, -0x5(%rdx)
movb 0xc(%rbx), %sil
movb %sil, -0x4(%rdx)
movb 0x10(%rbx), %sil
movb %sil, -0x3(%rdx)
movb 0x14(%rbx), %sil
movb %sil, -0x2(%rdx)
movb 0x18(%rbx), %sil
movb %sil, -0x1(%rdx)
movw $0x9, %si
movl $0x20, %edi
movb %al, (%rdx)
movb (%rbx,%rdi), %al
movb %al, (%rcx)
movzwl %si, %edx
leaq -0x18(%rbp), %rsi
movl $0x8c, %edi
callq 0x4aff
addq $0x18, %rsp
popq %rbx
popq %rbp
retq