// File: /workspace/github_cpp_makefile_star2_O2/jkingan[P]ladyheather/heathgps.cpp
// Function: set_ubx_pps(int, unsigned char, unsigned char, unsigned char, double, double, int)
void set_ubx_pps(int chan, u08 pps_rate, u08 pps_enable,  u08 pps_polarity,  double delay, double pps_delay, int save)
{
   if(read_only) return;

   if(saw_ubx_tp5) {
      if(pps_enable == 0) {
//sprintf(debug_text2, "pps disable:%02X  tp5:%02X", pps_rate, saw_ubx_tp5); 
         set_pps_freq(chan, 0.0, 0.10, pps_polarity, delay, pps_delay, save);
      }
      else {
         if(pps_rate == RATE_100PPS) {  // 100 hz
            set_pps_freq(chan, 100.0, 0.10, pps_polarity, delay, pps_delay, save);
         }
         else if(pps_rate == RATE_1000PPS) { // 1000 Hz
            set_pps_freq(chan, 1000.0, 0.10, pps_polarity, delay, pps_delay, save);
         }
         else {
            set_pps_freq(chan, 1.0, 0.10, pps_polarity, delay, pps_delay, save);
         }
//sprintf(debug_text2, "pps enable:%02X  tp5:%02X", pps_rate, saw_ubx_tp5);
      }
   }
   else {
      send_ubx_start(UBX_PPS, 20);

      if(pps_rate == RATE_100PPS) {
         send_dword(10000);    // 100 pps
         send_dword(100);      // 100 us width
      }
      else if(pps_rate == RATE_1000PPS) {
         send_dword(1000);     // 1000 pps
         send_dword(500);      // 500 us width
      }
      else {
         send_dword(1000000);  // 1 sec
         send_dword(10000);    // 10 msec width
      }

      if(pps_enable == 0)   send_byte(0);    // pulse off
      else if(pps_polarity) send_byte(0xFF); // neg pulse
      else                  send_byte(1);    // pos pulse

      if(time_flags & TFLAGS_UTC) send_byte(0);  // align to UTC
      else                        send_byte(1);  // align to GPS

      send_byte(1);  // always on

      send_byte(0);  // rsvd

      send_word((s16) (delay*1.0E9));
      send_word(0);  // rf delay
      send_dword((S32) pps_delay);

      send_ubx_end();
   }


   if(save) save_segment(6, 28);  // save PPS timing config in EEPROM

   if(saw_ubx_tp5) request_ubx_tp5(chan);
   else if(chan == 0) request_ubx_msg(UBX_PPS);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
leaq 0x2be501(%rip), %rax    # 0x32101a
cmpb $0x0, (%rax)
je 0x62b2d
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r8d, %r14d
movaps %xmm1, %xmm3
movapd %xmm0, %xmm2
movl %ecx, %r12d
movl %edx, %r15d
movl %esi, %r13d
movl %edi, %ebx
leaq 0x2948e3(%rip), %rax    # 0x2f742c
cmpl $0x0, (%rax)
je 0x62b72
movzbl %r12b, %esi
testb %r15b, %r15b
je 0x62ba7
cmpb $-0x7d, %r13b
je 0x62bb5
movzbl %r13b, %eax
cmpl $0x82, %eax
jne 0x62bbf
movsd 0x904f0(%rip), %xmm0    # 0xf3060
jmp 0x62bc7
movsd %xmm2, -0x30(%rbp)
movsd %xmm3, -0x38(%rbp)
pushq $0x14
popq %rsi
movl $0x607, %edi            # imm = 0x607
callq 0x57bf3
cmpb $-0x7e, %r13b
je 0x62bde
movzbl %r13b, %eax
cmpl $0x83, %eax
jne 0x62be9
movl $0x1f4, %r13d           # imm = 0x1F4
movl $0x3e8, %edi            # imm = 0x3E8
jmp 0x62bf4
movsd 0x90559(%rip), %xmm1    # 0xf3108
xorpd %xmm0, %xmm0
jmp 0x62bcf
movsd 0x9047b(%rip), %xmm0    # 0xf3038
jmp 0x62bc7
movsd 0x904a9(%rip), %xmm0    # 0xf3070
movsd 0x90539(%rip), %xmm1    # 0xf3108
movl %ebx, %edi
movl %r14d, %edx
callq 0x8793a
jmp 0x62c74
pushq $0x64
popq %r13
movl $0x2710, %edi           # imm = 0x2710
jmp 0x62bf4
movl $0x2710, %r13d          # imm = 0x2710
movl $0xf4240, %edi          # imm = 0xF4240
callq 0x525e2
movl %r13d, %edi
callq 0x525e2
xorl %eax, %eax
negb %r12b
movl $0x0, %ecx
sbbl %ecx, %ecx
orb $0x1, %cl
testb %r15b, %r15b
movzbl %cl, %ecx
cmovel %eax, %ecx
movzbl %cl, %edi
callq 0x523f2
leaq 0x29487c(%rip), %rax    # 0x2f74a4
movb (%rax), %al
notb %al
andb $0x1, %al
movzbl %al, %edi
callq 0x523f2
pushq $0x1
popq %rdi
callq 0x523f2
xorl %edi, %edi
callq 0x523f2
movsd -0x30(%rbp), %xmm0
mulsd 0x903d6(%rip), %xmm0    # 0xf3028
cvttsd2si %xmm0, %eax
movzwl %ax, %edi
callq 0x52599
xorl %edi, %edi
callq 0x52599
cvttsd2si -0x38(%rbp), %edi
callq 0x525e2
callq 0x57cca
testl %r14d, %r14d
je 0x62c81
pushq $0x6
popq %rdi
callq 0x6166c
leaq 0x2947a4(%rip), %rax    # 0x2f742c
cmpl $0x0, (%rax)
je 0x62ca2
movl %ebx, %edi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x61e62
testl %ebx, %ebx
jne 0x62b1e
movl $0x607, %edi            # imm = 0x607
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x59749