示例#1
0
/* -------------------------------------------------------------------------- */
ssize_t
_read_r (struct _reent *reent,
         int           file,
         void          *b,
         size_t        len)
{
    char *buf = (char*) b;

	if (STDIN_FILENO == file)
	{
		
		if (BOARD_HAS_UART)
		{
			/* UART supported. Read from it */


			int  i;
			
			for (i = 0; i < len; i++)
			{
				buf[i] = __uart_getc ();
#ifdef UART_AUTO_ECHO
				__uart_putc (buf[i]);
#endif
				/* Return partial buffer if we get EOL */
				if ('\n' == buf[i])
				{
					return  i;
				}
			}
			
			return  i;			/* Filled the buffer */
		}
		else
		{
			return  0;			/* EOF */
		}
	}
	else
	{
		reent->_errno = EBADF;
		return  -1;
	}
}	/* _read () */
示例#2
0
int main(void)
{

  printf("\r\n");
  printf("Timer + UART demo\r\n");
  printf("Press any key to increment the LED counter, except backspace which will\r\n");
  printf("cause it to decrement\r\n");

  /* Set the GPIO to all out */
  char dir = 0xff;
  *(gpio_base+1) = dir;
  /* Initialise with the first data value */
  *(gpio_base+0) = dat;

  /* Initialise the counter at 1Hz, it won't start yet */
  or1k_timer_init(1);

  /* Install a custom timer handler */
  or1k_exception_handler_add(0x5,or1k_timer_interrupt_handler_new);
  
  /* OK, start the timer now */
  or1k_timer_enable();

  /* Now loop and check for UART input */
  while (1)
    {
      char c = __uart_getc();

      /* If it was backspace, decrement the LEDs */
      if (c==0x7f)
	dat-=2;

      /* Update the GPIO LED output on any keypress, just like the timer had
	 gone off */
      or1k_timer_user_handler();
      
    }

  return 0;
}