コード例 #1
0
ファイル: syscalls.c プロジェクト: tcr/luajit-test
int _read(int file, char *ptr, int len) {
  int todo;
  if(len == 0)
    return 0;
  while(UART_FR(UART0_ADDR) & UART_FR_RXFE);
  *ptr++ = UART_DR(UART0_ADDR);
  for(todo = 1; todo < len; todo++) {
    if(UART_FR(UART0_ADDR) & UART_FR_RXFE) { break;  }
    *ptr++ = UART_DR(UART0_ADDR);

}
  return todo;

}
コード例 #2
0
ファイル: uart.c プロジェクト: Archer-sys/atomthreads
/**
 * \b uart_read
 *
 * Simple polled UART read.
 *
 * @param[in] ptr Pointer to receive buffer
 * @param[in] len Max bytes to read
 *
 * @retval Number of bytes read
 *
 */
int uart_read (char *ptr, int len)
{
    int todo = 0;

    /* Check we are initialised */
    if (initialised == FALSE)
    {
        uart_init();
    }

    /* Check parameters */
    if ((ptr == NULL) || (len == 0))
    {
        return 0;
    }

    /* Block thread on private access to the UART */
    if (atomMutexGet(&uart_mutex, 0) == ATOM_OK)
    {
        /* Wait for not-empty */
        while(UART_FR(UART0_ADDR) & UART_FR_RXFE)
            ;

        /* Read first byte */
        *ptr++ = UART_DR(UART0_ADDR);

        /* Loop over remaining bytes until empty */
        for (todo = 1; todo < len; todo++)
        {
            /* Quit if receive FIFO empty */
            if(UART_FR(UART0_ADDR) & UART_FR_RXFE)
            {
                break;
            }

            /* Read next byte */
            *ptr++ = UART_DR(UART0_ADDR);
        }

        /* Return mutex access */
        atomMutexPut(&uart_mutex);
    }

    /* Return number of bytes read */
    return todo;
}
コード例 #3
0
ファイル: syscalls.c プロジェクト: tcr/luajit-test
int _write(int file, char *ptr, int len) {
  int todo;
  for (todo = 0; todo < len; todo++) {
    UART_DR(UART0_ADDR) = *ptr++;

}
  return len;

}
コード例 #4
0
void serial_send(uint8_t ch, uint8_t v) {
	(void) ch;

	mutex_lock(&serial_lock);

	while(mmio_r32(UART_FR(UART0)) & (1 << 5))
		;
	mmio_w32(UART_DR(UART0), v);

	mutex_unlock(&serial_lock);
}
コード例 #5
0
uint8_t serial_recv(uint8_t ch) {
	(void) ch;

	mutex_lock(&serial_lock);

	while(mmio_r32(UART_FR(UART0)) & (1 << 4))
		;
	register uint8_t t = (uint8_t) mmio_r32(UART_DR(UART0));

	mutex_lock(&serial_lock);
	return t;
}
コード例 #6
0
ファイル: uart.c プロジェクト: Archer-sys/atomthreads
/**
 * \b uart_write_halt
 *
 * Simple polled UART write for handling critical failures
 * by printing out a message on the UART and looping forever.
 * Can be called from interrupt (unlike the standard
 * uart_write()) but is not thread-safe because it cannot
 * take the thread-safety mutex, and hence is only useful for
 * a last-resort catastrophic debug message.
 *
 * @param[in] ptr Pointer to write string
 */
void uart_write_halt (const char *ptr)
{
    /* Check parameters */
    if (ptr != NULL)
    {
        /* Loop through all bytes until NULL terminator encountered */
        while (*ptr != '\0')
        {
            /* Wait for empty */
            while(UART_FR(UART0_ADDR) & UART_FR_TXFF)
                ;

            /* Write byte to UART */
            UART_DR(UART0_ADDR) = *ptr++;
        }
    }

    /* Loop forever */
    while (1)
        ;

}
コード例 #7
0
ファイル: uart.c プロジェクト: Archer-sys/atomthreads
/**
 * \b uart_write
 *
 * Simple polled UART write.
 *
 * @param[in] ptr Pointer to write buffer
 * @param[in] len Number of bytes to write
 *
 * @retval Number of bytes written
 */
int uart_write (const char *ptr, int len)
{
    int todo;

    /* Check we are initialised */
    if (initialised == FALSE)
    {
        uart_init();
    }

    /* Check parameters */
    if ((ptr == NULL) || (len == 0))
    {
        return 0;
    }

    /* Block thread on private access to the UART */
    if (atomMutexGet(&uart_mutex, 0) == ATOM_OK)
    {
        /* Loop through all bytes to write */
        for (todo = 0; todo < len; todo++)
        {
            /* Wait for empty */
            while(UART_FR(UART0_ADDR) & UART_FR_TXFF)
                ;

            /* Write byte to UART */
            UART_DR(UART0_ADDR) = *ptr++;
        }

        /* Return mutex access */
        atomMutexPut(&uart_mutex);
    }

    /* Return bytes-written count */
    return len;
}
コード例 #8
0
ファイル: tUartPL011.c プロジェクト: ev3rt-git/ev3rt-hrp3
/*
 *  送信する文字の書込み
 */
Inline void
uart_pl011_putchar(CELLCB *p_cellcb, char c)
{
	sil_wrw_mem(UART_DR(ATTR_baseAddress), (uint32_t) c);
}
コード例 #9
0
ファイル: tUartPL011.c プロジェクト: ev3rt-git/ev3rt-hrp3
/*
 *  受信した文字の取出し
 */
Inline char
uart_pl011_getchar(CELLCB *p_cellcb)
{
	return((char) sil_rew_mem(UART_DR(ATTR_baseAddress)));
}