uart_io/uart_io.c File Reference

#include <stdio.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include "uart_io.h"
#include "uart_io_config.h"
#include <util/setbaud.h>

Go to the source code of this file.

Data Structures

struct  circular_buffer_t
struct  uart_t

Defines

#define UART_IO_CONCAT(a, b)   a ## b
#define UART_IO_CONCAT_EXPANDED(a, b)   UART_IO_CONCAT(a, b)
#define UART_IO_UTIL_OUTPORT(name)   UART_IO_CONCAT(PORT, name)
#define UART_IO_UTIL_INPORT(name)   UART_IO_CONCAT(PIN, name)
#define UART_IO_UTIL_DDRPORT(name)   UART_IO_CONCAT(DDR, name)
#define INVERTER1_IN_OUTPORT   UART_IO_UTIL_OUTPORT(INVERTER1_IN_PORT)
#define INVERTER1_IN_DDRPORT   UART_IO_UTIL_DDRPORT(INVERTER1_IN_PORT)
#define INVERTER1_IN_INPORT   UART_IO_UTIL_INPORT(INVERTER1_IN_PORT)
#define INVERTER1_OUT_OUTPORT   UART_IO_UTIL_OUTPORT(UART_IO_TX_OUTPORT)
#define INVERTER1_OUT_DDRPORT   UART_IO_UTIL_DDRPORT(UART_IO_TX_OUTPORT)
#define INVERTER1_OUT_INPORT   UART_IO_UTIL_INPORT(UART_IO_TX_OUTPORT)
#define INVERTER1_OUT_PIN   UART_IO_TX_OUTPIN
#define INVERTER1_IN_IS_HIGH()   bit_is_set(INVERTER1_IN_INPORT,INVERTER1_IN_PIN)
#define INVERTER1_OUT_HIGH()   INVERTER1_OUT_OUTPORT |= _BV(INVERTER1_OUT_PIN)
#define INVERTER1_OUT_LOW()   INVERTER1_OUT_OUTPORT &= ~_BV(INVERTER1_OUT_PIN)
#define UART_IO_BUFFER_SIZE   (1<<(UART_IO_BUFFER_SIZE_FACTOR))
#define UART_IO_GET_UBRR_X1(baud)   ((F_CPU/((baud)*16L))-1)
#define UART_IO_GET_UBRR_X2(baud)   ((F_CPU/((baud)*8L))-1)
#define BAUD   UART_IO_BAUDRATE

Functions

 SIGNAL (SIG_INTERRUPT1)
 SIGNAL (SIG_UART_DATA)
FILE * uart_io_init (void)
char uart_io_ok_to_powersave (void)


Detailed Description

_ _ _ _ | |__ (_)_ __| | _| | ___ _ __ ___ ___ | '_ \| | '__| |/ / |/ _ \ '__/ __|/ _ \ | |_) | | | | <| | __/ | _ \ __/ |_.__/|_|_| |_|||_|(_)___/|

Initializes the UART a FILE stream and attaches a circular ram buffer so that output is fast.

A software inverter is also assumed to be connected from the UART TX to the INT1 line so that the output can be made compatible with a PC without any external inverter or conversion logic.

Copyright 2007 J�rgen Birkler jorgen.birkler@gmail.com

Definition in file uart_io.c.


Define Documentation

#define BAUD   UART_IO_BAUDRATE

#define INVERTER1_IN_DDRPORT   UART_IO_UTIL_DDRPORT(INVERTER1_IN_PORT)

Definition at line 50 of file uart_io.c.

#define INVERTER1_IN_INPORT   UART_IO_UTIL_INPORT(INVERTER1_IN_PORT)

Definition at line 51 of file uart_io.c.

 
#define INVERTER1_IN_IS_HIGH (  )     bit_is_set(INVERTER1_IN_INPORT,INVERTER1_IN_PIN)

Definition at line 71 of file uart_io.c.

Referenced by SIGNAL().

#define INVERTER1_IN_OUTPORT   UART_IO_UTIL_OUTPORT(INVERTER1_IN_PORT)

Definition at line 49 of file uart_io.c.

#define INVERTER1_OUT_DDRPORT   UART_IO_UTIL_DDRPORT(UART_IO_TX_OUTPORT)

Definition at line 55 of file uart_io.c.

 
#define INVERTER1_OUT_HIGH (  )     INVERTER1_OUT_OUTPORT |= _BV(INVERTER1_OUT_PIN)

Definition at line 72 of file uart_io.c.

Referenced by SIGNAL().

#define INVERTER1_OUT_INPORT   UART_IO_UTIL_INPORT(UART_IO_TX_OUTPORT)

Definition at line 56 of file uart_io.c.

 
#define INVERTER1_OUT_LOW (  )     INVERTER1_OUT_OUTPORT &= ~_BV(INVERTER1_OUT_PIN)

Definition at line 73 of file uart_io.c.

Referenced by SIGNAL().

#define INVERTER1_OUT_OUTPORT   UART_IO_UTIL_OUTPORT(UART_IO_TX_OUTPORT)

Definition at line 54 of file uart_io.c.

#define INVERTER1_OUT_PIN   UART_IO_TX_OUTPIN

Definition at line 57 of file uart_io.c.

#define UART_IO_BUFFER_SIZE   (1<<(UART_IO_BUFFER_SIZE_FACTOR))

Definition at line 100 of file uart_io.c.

Referenced by SIGNAL().

#define UART_IO_CONCAT ( a,
 )     a ## b

Definition at line 31 of file uart_io.c.

#define UART_IO_CONCAT_EXPANDED ( a,
 )     UART_IO_CONCAT(a, b)

Definition at line 32 of file uart_io.c.

#define UART_IO_GET_UBRR_X1 ( baud   )     ((F_CPU/((baud)*16L))-1)

Definition at line 151 of file uart_io.c.

#define UART_IO_GET_UBRR_X2 ( baud   )     ((F_CPU/((baud)*8L))-1)

Definition at line 152 of file uart_io.c.

#define UART_IO_UTIL_DDRPORT ( name   )     UART_IO_CONCAT(DDR, name)

Definition at line 36 of file uart_io.c.

#define UART_IO_UTIL_INPORT ( name   )     UART_IO_CONCAT(PIN, name)

Definition at line 35 of file uart_io.c.

#define UART_IO_UTIL_OUTPORT ( name   )     UART_IO_CONCAT(PORT, name)

Definition at line 34 of file uart_io.c.


Function Documentation

SIGNAL ( SIG_UART_DATA   ) 

Definition at line 137 of file uart_io.c.

00138 {
00139   if (uart.tx.put == uart.tx.get)
00140   {
00141     UCSRB &= ~_BV(UCSRB); //Disable interrupt
00142   }
00143   else {
00144     UDR = uart.tx.buffer[uart.tx.get];
00145     ++uart.tx.get;
00146     uart.tx.get %= UART_IO_BUFFER_SIZE;
00147   }
00148 }

SIGNAL ( SIG_INTERRUPT1   ) 

Definition at line 76 of file uart_io.c.

00078 {
00079   if (INVERTER1_IN_IS_HIGH())
00080   {
00081     INVERTER1_OUT_LOW();
00082   }
00083   else
00084   {
00085     INVERTER1_OUT_HIGH();
00086   }
00087   __asm__("reti"::);
00088 }

FILE* uart_io_init ( void   ) 

Initialize the UART, interrupts, pin and software inverter.

Definition at line 172 of file uart_io.c.

Referenced by main().

00173 {
00174   uart_io_enable_tx();
00175   INVERTER1_ENABLE();
00176   return &uart_file_io;
00177 }

char uart_io_ok_to_powersave ( void   ) 

Returns 1 if ok to disable CPU clock 0 if not

Note:
Not implemented; always return 1

Definition at line 179 of file uart_io.c.

00180 {
00181   return 0;
00182 }


Generated on Fri Oct 30 20:43:20 2009 for USB IR HID Device by  doxygen 1.5.8