// File: /workspace/github_c_makefile_star2_O2/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
andq $0x0, -0x18(%rbp)
movb $0x0, -0x10(%rbp)
movl 0x5ff4(%rip), %eax      # 0xa4ac
movl (%rdi), %edi
cmpl %edi, %eax
je 0x44c5
callq 0x42ec
movl (%rbx), %eax
cmpl $0x1, %eax
je 0x44fb
testl %eax, %eax
jne 0x459d
movl 0x1c(%rbx), %eax
cmpl $0xf2, %eax
je 0x452c
cmpl $0xf1, %eax
jne 0x4542
movl $0xffff, %edi           # imm = 0xFFFF
callq 0x3d31
movl $0x8005, %edi           # imm = 0x8005
callq 0x3d6d
movb $0x2, %al
jmp 0x4542
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, 0x5f98(%rip)      # 0xa4b0
movb %al, -0x2(%rdx)
movb 0x2c(%rbx), %al
movb %al, -0x1(%rdx)
movb 0x30(%rbx), %al
movw $0x6, %si
pushq $0x34
jmp 0x4584
movl $0x1d0f, %edi           # imm = 0x1D0F
callq 0x3d31
movl $0x1021, %edi           # imm = 0x1021
callq 0x3d6d
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
pushq $0x20
popq %rdi
movb %al, (%rdx)
movb (%rbx,%rdi), %al
movb %al, (%rcx)
movzwl %si, %edx
leaq -0x18(%rbp), %rsi
movl $0x8c, %edi
callq 0x49f9
addq $0x18, %rsp
popq %rbx
popq %rbp
retq