// File: /workspace/github_c_makefile_star2_O3/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 %r14
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
movb $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movl 0x5f56(%rip), %eax      # 0xa49c
movl (%rdi), %ecx
cmpl %ecx, %eax
je 0x4569
leaq -0x14(%rbp), %rsi
movl %ecx, (%rsi)
movl %ecx, 0x5f44(%rip)      # 0xa49c
movl $0x8a, %edi
movl $0x1, %edx
callq 0x4b5f
movl (%rbx), %eax
cmpl $0x1, %eax
je 0x45dd
testl %eax, %eax
jne 0x46ba
movl 0x1c(%rbx), %eax
cmpl $0xf2, %eax
je 0x4614
cmpl $0xf1, %eax
jne 0x465d
movw $0xffff, -0x14(%rbp)    # imm = 0xFFFF
cmpl $0x0, 0x5f00(%rip)      # 0xa49c
jne 0x45d6
leaq -0x14(%rbp), %r14
movl $0x6bc, %edi            # imm = 0x6BC
movq %r14, %rsi
movl $0x2, %edx
callq 0x4d7e
cmpl $0x0, 0x5ee1(%rip)      # 0xa49c
movw $0x580, (%r14)          # imm = 0x580
jne 0x45d6
leaq -0x14(%rbp), %rsi
movl $0x6be, %edi            # imm = 0x6BE
movl $0x2, %edx
callq 0x4d7e
movb $0x2, %al
jmp 0x465d
leaq -0x1b(%rbp), %rcx
leaq -0x1c(%rbp), %rdx
movzwl 0x24(%rbx), %eax
rolw $0x8, %ax
movw %ax, -0x4(%rdx)
movl 0x28(%rbx), %eax
movl %eax, 0x5ea6(%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 0x46a2
movw $0xf1d, -0x14(%rbp)     # imm = 0xF1D
cmpl $0x0, 0x5e7b(%rip)      # 0xa49c
jne 0x465b
leaq -0x14(%rbp), %r14
movl $0x6bc, %edi            # imm = 0x6BC
movq %r14, %rsi
movl $0x2, %edx
callq 0x4d7e
cmpl $0x0, 0x5e5c(%rip)      # 0xa49c
movw $0x2110, (%r14)         # imm = 0x2110
jne 0x465b
leaq -0x14(%rbp), %rsi
movl $0x6be, %edi            # imm = 0x6BE
movl $0x2, %edx
callq 0x4d7e
movb $0x6, %al
leaq -0x18(%rbp), %rcx
leaq -0x19(%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 -0x20(%rbp), %rsi
movl $0x8c, %edi
callq 0x4b5f
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq