summaryrefslogtreecommitdiffstats
path: root/bsps/shared/grlib/uart/apbuart_polled.c
blob: 948e0966b862fc2bff7c6a86fa200fe32bf20f64 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
 *  COPYRIGHT (c) 2010.
 *  Cobham Gaisler AB.
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.rtems.org/license/LICENSE.
 */

#include <grlib/apbuart.h>

void apbuart_outbyte_polled(
  struct apbuart_regs *regs,
  unsigned char ch,
  int wait_sent
)
{
  while ( (regs->status & APBUART_STATUS_TE) == 0 ) {
    /* Lower bus utilization while waiting for UART */
    __asm__ volatile ("nop"::); __asm__ volatile ("nop"::);
    __asm__ volatile ("nop"::); __asm__ volatile ("nop"::);
    __asm__ volatile ("nop"::); __asm__ volatile ("nop"::);
    __asm__ volatile ("nop"::); __asm__ volatile ("nop"::);
  }

  regs->data = (unsigned int) ch;

  /* Wait until the character has been sent? */
  if (wait_sent) {
    while ((regs->status & APBUART_STATUS_TE) == 0)
      ;
  }
}

int apbuart_inbyte_nonblocking(struct apbuart_regs *regs)
{
  /* Clear errors */
  if (regs->status & APBUART_STATUS_ERR)
    regs->status = ~APBUART_STATUS_ERR;

  if ((regs->status & APBUART_STATUS_DR) == 0)
    return -1;
  else
    return (int) regs->data;
}