SimAVR
AVR Simulator
UART

Data Structures

struct  avr_uart_t
 

Macros

#define AVR_IOCTL_UART_GETIRQ(_name)   AVR_IOCTL_DEF('u','a','r',(_name))
 add port number to get the real IRQ More...
 
#define AVR_IOCTL_UART_SET_FLAGS(_name)   AVR_IOCTL_DEF('u','a','s',(_name))
 
#define AVR_IOCTL_UART_GET_FLAGS(_name)   AVR_IOCTL_DEF('u','a','g',(_name))
 

Typedefs

typedef struct avr_uart_t avr_uart_t
 

Enumerations

enum  {
  UART_IRQ_INPUT = 0, UART_IRQ_OUTPUT, UART_IRQ_OUT_XON, UART_IRQ_OUT_XOFF,
  UART_IRQ_COUNT
}
 The method of "connecting" the the UART from external code is to use 4 IRQS. More...
 
enum  { AVR_UART_FLAG_POOL_SLEEP = (1 << 0), AVR_UART_FLAG_STDIO = (1 << 1) }
 

Functions

 DECLARE_FIFO (uint8_t, uart_fifo, 64)
 
void avr_uart_init (avr_t *avr, avr_uart_t *port)
 

Detailed Description

Macro Definition Documentation

#define AVR_IOCTL_UART_GET_FLAGS (   _name)    AVR_IOCTL_DEF('u','a','g',(_name))
#define AVR_IOCTL_UART_GETIRQ (   _name)    AVR_IOCTL_DEF('u','a','r',(_name))

add port number to get the real IRQ

#define AVR_IOCTL_UART_SET_FLAGS (   _name)    AVR_IOCTL_DEF('u','a','s',(_name))

Typedef Documentation

typedef struct avr_uart_t avr_uart_t

Enumeration Type Documentation

anonymous enum

The method of "connecting" the the UART from external code is to use 4 IRQS.

The easy one is UART->YOU, where you will be called with the byte every time the AVR firmware sends one. Do whatever you like with it.

The slightly more tricky one is the INPUT part. Since the AVR is quite a bit slower than your code most likely, there is a way for the AVR UART to tell you to "pause" sending it bytes when its own input buffer is full. So, the UART will send XON to you when its fifo is empty, XON means you can send as many bytes as you have until XOFF is sent. Note that these are two IRQs because you /will/ be called with XOFF when sending a byte in INPUT... So it's a reentrant process.

When XOFF has been called, do not send any new bytes, they would be dropped. Instead wait for XON again and continue. See examples/parts/uart_udp.c for a full implementation

Pseudo code:

volatile int off = 0; void irq_xon() { off = 0; while (!off && bytes_left) avr_raise_irq(UART_IRQ_INPUT, a_byte); } void irq_xoff() { off = 1; }

Enumerator
UART_IRQ_INPUT 
UART_IRQ_OUTPUT 
UART_IRQ_OUT_XON 

signaled (continuously) when input fifo is not full

UART_IRQ_OUT_XOFF 

signaled when input fifo IS full

UART_IRQ_COUNT 
anonymous enum
Enumerator
AVR_UART_FLAG_POOL_SLEEP 

the uart code monitors for firmware that pool on reception registers, and can do an atomic usleep() if it's detected, this helps regulating CPU

AVR_UART_FLAG_STDIO 

print lines on the console

Function Documentation

void avr_uart_init ( avr_t avr,
avr_uart_t port 
)

Here is the call graph for this function:

Here is the caller graph for this function:

DECLARE_FIFO ( uint8_t  ,
uart_fifo  ,
64   
)