コード例 #1
0
ファイル: ymodem.c プロジェクト: qiurenguo2014/mkboot
static  int32_t Receive_Byte (uint8_t *c, uint32_t timeout)
{
	u8 temp8;
	while(timeout-- > 0)
		{
		if(GetUart(&temp8) == 1)
			{
			*c = temp8; 
			return 0;
			}
		}
  return -1;
}
コード例 #2
0
ファイル: ser_port.c プロジェクト: dorienh/smmu
void InitPort (void)
{
  int mcr;
  int temp;

  if(port_initted)
    return;
  
  //
  // Reset the output queue
  //

  outque.head = outque.tail = 0;

  //
  // find the irq and io address of the port
  //
  GetUart ();

  //
  // init com port settings
  //
  regs.x.ax = 0xf3;               //f3= 9600 n 8 1
  regs.x.dx = comport - 1;
  int86 (0x14, &regs, &regs);
  
  //
  // check for a 16550
  //
  OUTPUT(uart + FIFO_CONTROL_REGISTER, FCR_FIFO_ENABLE + FCR_TRIGGER_04);
  temp = INPUT(uart + INTERRUPT_ID_REGISTER);
  if ((temp & 0xf8) == 0xc0)
    {
      uart_type = UART_16550;
      usermsg ("UART is a 16550");
    }
  else
    {
      uart_type = UART_8250;
      OUTPUT(uart + FIFO_CONTROL_REGISTER, 0);
      usermsg("UART is an 8250");
    }
  
  //
  // prepare for interrupts
  //

  OUTPUT(uart + INTERRUPT_ENABLE_REGISTER, 0);
  mcr = INPUT(uart + MODEM_CONTROL_REGISTER);
  mcr |= MCR_OUT2;
  mcr &= ~MCR_LOOPBACK;
  OUTPUT(uart + MODEM_CONTROL_REGISTER, mcr);
  
  INPUT(uart);  // Clear any pending interrupts
  INPUT(uart + INTERRUPT_ID_REGISTER);
  
  //
  // hook the irq vector
  //
  irqintnum = irq + 8;
  
  asm("cli"); // disable interrupts

  _go32_dpmi_get_protected_mode_interrupt_vector(irqintnum, &oldirqvect);
  newirqvect.pm_offset = (int)isr_8250;
  newirqvect.pm_selector = _go32_my_cs();
  _go32_dpmi_allocate_iret_wrapper(&newirqvect);
  _go32_dpmi_set_protected_mode_interrupt_vector(irqintnum, &newirqvect);

  asm("sti"); // enable interrupts
	
  OUTPUT(0x20 + 1, INPUT(0x20 + 1) & ~(1<<irq));

  asm("cli"); // disable again

  // enable RX and TX interrupts at the uart
  
  OUTPUT(uart + INTERRUPT_ENABLE_REGISTER,
	 IER_RX_DATA_READY + IER_TX_HOLDING_REGISTER_EMPTY);

  // enable interrupts through the interrupt controller
  
  OUTPUT(0x20, 0xc2);

  // set DTR
  OUTPUT(uart + MODEM_CONTROL_REGISTER
	  , INPUT(uart + MODEM_CONTROL_REGISTER) | MCR_DTR);
  
  asm("sti"); // re-enable

  port_initted = true;
}