// File: /workspace/github_c_makefile_star2_O0/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
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movb $0x0, -0xa(%rbp)
leaq -0x13(%rbp), %rdi
xorl %esi, %esi
movl $0x9, %edx
callq 0x2100
movl 0x8156(%rip), %eax      # 0xe4cc
movq -0x8(%rbp), %rcx
cmpl (%rcx), %eax
je 0x6389
movq -0x8(%rbp), %rax
movl (%rax), %edi
callq 0x60a0
movq -0x8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x18(%rbp)
testl %eax, %eax
je 0x63b7
jmp 0x6398
movl -0x18(%rbp), %eax
subl $0x1, %eax
je 0x6477
jmp 0x63a6
movl -0x18(%rbp), %eax
subl $0xf, %eax
je 0x64cb
jmp 0x64c9
movq -0x8(%rbp), %rax
cmpl $0xf1, 0x1c(%rax)
jne 0x63de
movl $0xffff, %edi           # imm = 0xFFFF
callq 0x5730
movl $0x8005, %edi           # imm = 0x8005
callq 0x5790
movb $0x2, -0xa(%rbp)
jmp 0x6411
movq -0x8(%rbp), %rax
cmpl $0xf2, 0x1c(%rax)
jne 0x6405
movl $0x1d0f, %edi           # imm = 0x1D0F
callq 0x5730
movl $0x1021, %edi           # imm = 0x1021
callq 0x5790
movb $0x6, -0xa(%rbp)
jmp 0x640f
movq -0x8(%rbp), %rax
movl 0x1c(%rax), %eax
movb %al, -0xa(%rbp)
jmp 0x6411
movb $0x9, -0x9(%rbp)
movq -0x8(%rbp), %rax
movzwl 0x4(%rax), %eax
sarl $0x8, %eax
andl $0xff, %eax
movb %al, -0x13(%rbp)
movq -0x8(%rbp), %rax
movw 0x4(%rax), %ax
movb %al, -0x12(%rbp)
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
movb %al, -0x11(%rbp)
movq -0x8(%rbp), %rax
movb 0xc(%rax), %al
movb %al, -0x10(%rbp)
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
movb %al, -0xf(%rbp)
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
movb %al, -0xe(%rbp)
movq -0x8(%rbp), %rax
movb 0x18(%rax), %al
movb %al, -0xd(%rbp)
movb -0xa(%rbp), %al
movb %al, -0xc(%rbp)
movq -0x8(%rbp), %rax
movl 0x20(%rax), %eax
movb %al, -0xb(%rbp)
jmp 0x64cd
movb $0x6, -0x9(%rbp)
movq -0x8(%rbp), %rax
movzwl 0x24(%rax), %eax
sarl $0x8, %eax
andl $0xff, %eax
movb %al, -0x13(%rbp)
movq -0x8(%rbp), %rax
movw 0x24(%rax), %ax
movb %al, -0x12(%rbp)
movq -0x8(%rbp), %rax
movl 0x28(%rax), %eax
movl %eax, 0x802a(%rip)      # 0xe4d0
movb %al, -0x11(%rbp)
movq -0x8(%rbp), %rax
movb 0x2c(%rax), %al
movb %al, -0x10(%rbp)
movq -0x8(%rbp), %rax
movl 0x30(%rax), %eax
movb %al, -0xf(%rbp)
movq -0x8(%rbp), %rax
movl 0x34(%rax), %eax
movb %al, -0xe(%rbp)
jmp 0x64cd
jmp 0x64cb
jmp 0x64e2
leaq -0x13(%rbp), %rsi
movzbl -0x9(%rbp), %eax
movl $0x8c, %edi
movzwl %ax, %edx
callq 0x6d60
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax,%rax)