// File: /workspace/github_cpp_makefile_star2_O1/mattdibi[P]Programmatore-JTAG-per-Xilinx/serial.cpp
// Function: Serial::Open(char const*, unsigned int)
void Serial::Open(const char *Device,const unsigned Bauds)
{
   // Struttura per memorizzare i parametri della connessione
   struct termios options;

   // Apre la connessione in lettura/scrittura
   fd = open(Device, O_RDWR | O_NOCTTY | O_NDELAY);
   if (fd == -1)
   {
      // Se non è possibile aprire la connessione, lancia un'eccezione
      throw ErrorOpeningException();
   }

   // Impostazione dei flag per la seriale
   fcntl(fd, F_SETFL, FNDELAY);

   // Impostazione del puntatore della struttura per le opzioni
   tcgetattr(fd, &options);

   // Azzeramento la struttura options
   bzero(&options, sizeof(options));

   // Impostazione la velocità della seriale
   speed_t Speed;
   switch (Bauds)
   {
      case 110:
         Speed=B110;
         break;
      case 300:
         Speed=B300;
         break;
      case 600:
         Speed=B600;
         break;
      case 1200:
         Speed=B1200;
         break;
      case 2400:
         Speed=B2400;
         break;
      case 4800:
         Speed=B4800;
         break;
      case 9600:
         Speed=B9600;
         break;
      case 19200:
         Speed=B19200;
         break;
      case 38400:
         Speed=B38400;
         break;
      case 57600:
         Speed=B57600;
         break;
      case 115200:
         Speed=B115200;
         break;
      default:
         throw ErrorSpeedException();
   }
   cfsetispeed(&options, Speed);
   cfsetospeed(&options, Speed);

   // Impostazione dei flag
   options.c_cflag |= ( CLOCAL | CREAD |  CS8);
   options.c_iflag |= ( IGNPAR | IGNBRK );
   options.c_cc[VTIME]=0;
   options.c_cc[VMIN]=0;
   tcsetattr(fd, TCSANOW, &options);
   return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x48, %rsp
movl %edx, %r14d
movq %rdi, %rbx
movq %rsi, %rdi
movl $0x902, %esi            # imm = 0x902
xorl %eax, %eax
callq 0x31a0
movl %eax, (%rbx)
cmpl $-0x1, %eax
je 0x572a
movl %eax, %edi
movl $0x4, %esi
movl $0x800, %edx            # imm = 0x800
xorl %eax, %eax
callq 0x3130
movl (%rbx), %edi
leaq -0x60(%rbp), %r15
movq %r15, %rsi
callq 0x3290
xorps %xmm0, %xmm0
movaps %xmm0, (%r15)
movaps %xmm0, 0x10(%r15)
movaps %xmm0, 0x20(%r15)
movups %xmm0, 0x2c(%r15)
cmpl $0x12bf, %r14d          # imm = 0x12BF
jle 0x563c
cmpl $0x95ff, %r14d          # imm = 0x95FF
jg 0x5670
cmpl $0x12c0, %r14d          # imm = 0x12C0
je 0x56d0
cmpl $0x2580, %r14d          # imm = 0x2580
je 0x56b8
cmpl $0x4b00, %r14d          # imm = 0x4B00
jne 0x5754
movl $0xe, %r15d
jmp 0x56e6
cmpl $0x257, %r14d           # imm = 0x257
jle 0x5697
cmpl $0x258, %r14d           # imm = 0x258
je 0x56e0
cmpl $0x4b0, %r14d           # imm = 0x4B0
je 0x56c8
cmpl $0x960, %r14d           # imm = 0x960
jne 0x5754
movl $0xb, %r15d
jmp 0x56e6
cmpl $0x9600, %r14d          # imm = 0x9600
je 0x56d8
cmpl $0xe100, %r14d          # imm = 0xE100
je 0x56c0
cmpl $0x1c200, %r14d         # imm = 0x1C200
jne 0x5754
movl $0x1002, %r15d          # imm = 0x1002
jmp 0x56e6
movl $0x3, %r15d
cmpl $0x6e, %r14d
je 0x56e6
cmpl $0x12c, %r14d           # imm = 0x12C
jne 0x5754
movl $0x7, %r15d
jmp 0x56e6
movl $0xd, %r15d
jmp 0x56e6
movl $0x1001, %r15d          # imm = 0x1001
jmp 0x56e6
movl $0x9, %r15d
jmp 0x56e6
movl $0xc, %r15d
jmp 0x56e6
movl $0xf, %r15d
jmp 0x56e6
movl $0x8, %r15d
leaq -0x60(%rbp), %r14
movq %r14, %rdi
movl %r15d, %esi
callq 0x3140
movq %r14, %rdi
movl %r15d, %esi
callq 0x3280
orl $0x8b0, 0x8(%r14)       # imm = 0x8B0
orb $0x5, (%r14)
movw $0x0, 0x16(%r14)
movl (%rbx), %edi
xorl %esi, %esi
movq %r14, %rdx
callq 0x32d0
addq $0x48, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movl $0x8, %edi
callq 0x3110
leaq 0x457d(%rip), %rcx      # 0x9cb8
movq %rcx, (%rax)
leaq 0x44eb(%rip), %rsi      # 0x9c30
movq 0x4894(%rip), %rdx      # 0x9fe0
movq %rax, %rdi
callq 0x33d0
movl $0x8, %edi
callq 0x3110
leaq 0x457b(%rip), %rcx      # 0x9ce0
movq %rcx, (%rax)
leaq 0x44d9(%rip), %rsi      # 0x9c48
jmp 0x5745
nop