Xmega Application Note


sw_usart.h File Reference


Detailed Description

This file shows how to implement a half duplex software driven uart.

This single file shows how to implement a software uart using Timer0 and external interrupt 0.

Note that the RX_PIN must be the external interrupt 0 pin on your AVR of choice. The TX_PIN can be chosen to be any suitable pin. Note that this code is intended to run from an internal 8 MHz clock source.

Application note:
AVR1907: Xplain Evaluation Board
Documentation
For comprehensive code documentation, supported compilers, compiler settings and supported devices see readme.html
Author:
Atmel Corporation: http://www.atmel.com
Support email: avr@atmel.com
Revision
3122
Date
2010-01-13 13:26:22 +0100 (on, 13 jan 2010)

Copyright (c) 2010, Atmel Corporation All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. The name of ATMEL may not be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Definition in file sw_usart.h.

#include "config.h"

Include dependency graph for sw_usart.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define INTERRUPT_EXEC_CYCL   (0xFF - 10)
 Cycles to execute interrupt rutine from interrupt.
#define SW_USART_BAUD   9600
#define SW_USART_BUFFER_SIZE   32
#define SW_USART_CLR_TX_PIN()   ( SW_USART_TRX_PORT &= ~( 1 << SW_USART_TX_PIN ) )
#define SW_USART_EXT_ICR   EICRA
#define SW_USART_EXT_IFR   EIFR
#define SW_USART_GET_RX_PIN()   ( SW_USART_TRX_PIN & ( 1 << SW_USART_RX_PIN ) )
#define SW_USART_PRESCALER   TIMER_PRESCALER_8_gc
#define SW_USART_RX_CLEAR_TIMER_INTERRUPT()   ( TIFR0 |= ((1 << OCF0A) ) )
#define SW_USART_RX_COMP_VECT   TIMER0_COMPA_vect
#define SW_USART_RX_COMPARE   OCR0A
#define SW_USART_RX_CTRL   TCCR0A
#define SW_USART_RX_DISABLE_EXTERNAL0_INTERRUPT()   ( EIMSK &= ~( 1<< INT0 ) )
#define SW_USART_RX_DISABLE_PRESCALER()   ( SW_USART_RX_PRESCALE = 0x00)
#define SW_USART_RX_DISABLE_TIMER_INTERRUPT()   ( TIMSK0 &= ~( 1<< OCIE0A ) )
#define SW_USART_RX_ENABLE_EXTERNAL0_INTERRUPT()   ( EIMSK |= ( 1<< INT0 ) )
#define SW_USART_RX_ENABLE_PRESCALER()   ( SW_USART_RX_PRESCALE = SW_USART_PRESCALER )
#define SW_USART_RX_ENABLE_TIMER_INTERRUPT()   ( TIMSK0 |= ( 1<< OCIE0A ) )
#define SW_USART_RX_PIN   PD0
#define SW_USART_RX_PRESCALE   TCCR0B
#define SW_USART_RX_TIMER   TCNT0
#define SW_USART_SET_TX_PIN()   ( SW_USART_TRX_PORT |= ( 1 << SW_USART_TX_PIN ) )
#define SW_USART_TICKS2WAITONE   (uint8_t) ((1000000 / SW_USART_BAUD) - 1)
 Wait one bit period.
#define SW_USART_TRX_DDR   DDRD
#define SW_USART_TRX_PIN   PIND
#define SW_USART_TRX_PORT   PORTD
#define SW_USART_TX_CLEAR_TIMER_INTERRUPT()   ( TIFR2 |= ((1 << OCF2A) ) )
#define SW_USART_TX_COMP_VECT   TIMER2_COMPA_vect
#define SW_USART_TX_COMPARE   OCR2A
#define SW_USART_TX_CTRL   TCCR2A
#define SW_USART_TX_DISABLE_PRESCALER()   ( SW_USART_TX_PRESCALE = 0x00)
#define SW_USART_TX_DISABLE_TIMER_INTERRUPT()   ( TIMSK2 &= ~( 1<< OCIE2A ) )
#define SW_USART_TX_ENABLE_PRESCALER()   ( SW_USART_TX_PRESCALE = SW_USART_PRESCALER )
#define SW_USART_TX_ENABLE_TIMER_INTERRUPT()   ( TIMSK2 |= ( 1<< OCIE2A ) )
#define SW_USART_TX_PIN   PD1
#define SW_USART_TX_PRESCALE   TCCR2B
#define SW_USART_TX_TIMER   TCNT2

Typedefs

typedef enum TIMER_PRESCALER_enum TIMER_PRESCALER_t

Enumerations

enum  AsynchronousStates_t {
  IDLE, TRANSMIT, TRANSMIT_STOP_BIT, RECEIVE,
  DATA_PENDING
}
 Type defined enumeration holding software UART's state. More...
enum  TIMER_PRESCALER_enum {
  TIMER_PRESCALER_OFF_gc = (0x00), TIMER_PRESCALER_1_gc = (0x01), TIMER_PRESCALER_8_gc = (0x02), TIMER_PRESCALER_64_gc = (0x03),
  TIMER_PRESCALER_256_gc = (0x04), TIMER_PRESCALER_1024_gc = (0x05), TIMER_PRESCALER_EXT_FALLING_gc = (0x06), TIMER_PRESCALER_EXT_RISING_gc = (0x07)
}
 Timer prescaler enumeration. More...

Functions

void SW_USART_init (void)
 Function to initialize the software UART.
void SW_USART_PutChar (const uint8_t c)
 Send a unsigned char.
uint8_t SW_USART_RX_Buffer_GetByte (void)
 Get byte from the RX buffer.
void SW_USART_RX_Buffer_PutByte (uint8_t)
 Function to put byte in RX buffer.
void SW_USART_Set_Baudrate (uint32_t)
 Set new baudrate.
uint8_t SW_USART_Test_Hit (void)
 Function to check if data is pending in the buffer.
uint8_t SW_USART_Tx_Ready (void)
 Function to check if transmitter is busy.

Variables

static volatile uint8_t SW_USART_RX_Buffer [SW_USART_BUFFER_SIZE]
static volatile uint8_t SW_USART_RX_Head = 0
static volatile uint8_t SW_USART_RX_Num = 0
static volatile uint8_t SW_USART_RX_Tail = 0
static volatile uint8_t SwUartRXBitCount
static volatile uint8_t SwUartRXData
static volatile uint8_t SwUartTICKS2WAITONE = SW_USART_TICKS2WAITONE
static volatile uint8_t SwUartTXBitCount
static volatile uint8_t SwUartTXData
static volatile
AsynchronousStates_t 
SwUsartRXState
static volatile
AsynchronousStates_t 
SwUsartTXState


Define Documentation

#define INTERRUPT_EXEC_CYCL   (0xFF - 10)

Cycles to execute interrupt rutine from interrupt.

Definition at line 94 of file sw_usart.h.

Referenced by ISR().

#define SW_USART_BAUD   9600

Desired baudrate. In current implementation only 4800 and 9600 baud is supported.

Definition at line 88 of file sw_usart.h.

#define SW_USART_BUFFER_SIZE   32

Software buffer size

Definition at line 87 of file sw_usart.h.

Referenced by SW_USART_RX_Buffer_GetByte(), and SW_USART_RX_Buffer_PutByte().

 
#define SW_USART_CLR_TX_PIN (  )     ( SW_USART_TRX_PORT &= ~( 1 << SW_USART_TX_PIN ) )

Definition at line 150 of file sw_usart.h.

Referenced by ISR(), and SW_USART_PutChar().

#define SW_USART_EXT_ICR   EICRA

External Interrupt Control Register

Definition at line 103 of file sw_usart.h.

Referenced by SW_USART_init().

#define SW_USART_EXT_IFR   EIFR

External Interrupt Flag Register

Definition at line 102 of file sw_usart.h.

Referenced by ISR(), and SW_USART_init().

 
#define SW_USART_GET_RX_PIN (  )     ( SW_USART_TRX_PIN & ( 1 << SW_USART_RX_PIN ) )

Definition at line 151 of file sw_usart.h.

Referenced by ISR().

#define SW_USART_PRESCALER   TIMER_PRESCALER_8_gc

Definition at line 122 of file sw_usart.h.

 
#define SW_USART_RX_CLEAR_TIMER_INTERRUPT (  )     ( TIFR0 |= ((1 << OCF0A) ) )

Definition at line 136 of file sw_usart.h.

Referenced by ISR().

#define SW_USART_RX_COMP_VECT   TIMER0_COMPA_vect

Timer Compare Interrupt Vector

Definition at line 104 of file sw_usart.h.

#define SW_USART_RX_COMPARE   OCR0A

Output Compare Register

Definition at line 100 of file sw_usart.h.

Referenced by ISR(), and SW_USART_init().

#define SW_USART_RX_CTRL   TCCR0A

Timer/Counter Control Register

Definition at line 98 of file sw_usart.h.

Referenced by SW_USART_init().

 
#define SW_USART_RX_DISABLE_EXTERNAL0_INTERRUPT (  )     ( EIMSK &= ~( 1<< INT0 ) )

Definition at line 138 of file sw_usart.h.

Referenced by ISR().

 
#define SW_USART_RX_DISABLE_PRESCALER (  )     ( SW_USART_RX_PRESCALE = 0x00)

Definition at line 140 of file sw_usart.h.

Referenced by ISR().

 
#define SW_USART_RX_DISABLE_TIMER_INTERRUPT (  )     ( TIMSK0 &= ~( 1<< OCIE0A ) )

Definition at line 135 of file sw_usart.h.

Referenced by ISR(), and SW_USART_init().

 
#define SW_USART_RX_ENABLE_EXTERNAL0_INTERRUPT (  )     ( EIMSK |= ( 1<< INT0 ) )

Definition at line 137 of file sw_usart.h.

Referenced by ISR(), and SW_USART_init().

 
#define SW_USART_RX_ENABLE_PRESCALER (  )     ( SW_USART_RX_PRESCALE = SW_USART_PRESCALER )

Definition at line 139 of file sw_usart.h.

Referenced by ISR().

 
#define SW_USART_RX_ENABLE_TIMER_INTERRUPT (  )     ( TIMSK0 |= ( 1<< OCIE0A ) )

Definition at line 134 of file sw_usart.h.

Referenced by ISR().

#define SW_USART_RX_PIN   PD0

Receive data pin, must be INT0

Definition at line 113 of file sw_usart.h.

Referenced by SW_USART_init().

#define SW_USART_RX_PRESCALE   TCCR0B

Timer/Counter Control (Prescaler) Register

Definition at line 99 of file sw_usart.h.

Referenced by SW_USART_init().

#define SW_USART_RX_TIMER   TCNT0

Timer Counter register

Definition at line 101 of file sw_usart.h.

Referenced by ISR().

 
#define SW_USART_SET_TX_PIN (  )     ( SW_USART_TRX_PORT |= ( 1 << SW_USART_TX_PIN ) )

Definition at line 149 of file sw_usart.h.

Referenced by ISR(), and SW_USART_init().

#define SW_USART_TICKS2WAITONE   (uint8_t) ((1000000 / SW_USART_BAUD) - 1)

Wait one bit period.

Definition at line 91 of file sw_usart.h.

#define SW_USART_TRX_DDR   DDRD

TRX Data direction register

Definition at line 114 of file sw_usart.h.

Referenced by SW_USART_init().

#define SW_USART_TRX_PIN   PIND

TRX Pin register

Definition at line 116 of file sw_usart.h.

#define SW_USART_TRX_PORT   PORTD

TRX Port register

Definition at line 115 of file sw_usart.h.

Referenced by SW_USART_init().

 
#define SW_USART_TX_CLEAR_TIMER_INTERRUPT (  )     ( TIFR2 |= ((1 << OCF2A) ) )

Definition at line 144 of file sw_usart.h.

Referenced by SW_USART_PutChar().

#define SW_USART_TX_COMP_VECT   TIMER2_COMPA_vect

Timer Compare Interrupt Vector

Definition at line 110 of file sw_usart.h.

#define SW_USART_TX_COMPARE   OCR2A

Output Compare Register

Definition at line 108 of file sw_usart.h.

Referenced by SW_USART_init(), and SW_USART_PutChar().

#define SW_USART_TX_CTRL   TCCR2A

Timer/Counter Control Register

Definition at line 106 of file sw_usart.h.

Referenced by SW_USART_init().

 
#define SW_USART_TX_DISABLE_PRESCALER (  )     ( SW_USART_TX_PRESCALE = 0x00)

Definition at line 146 of file sw_usart.h.

Referenced by SW_USART_PutChar().

 
#define SW_USART_TX_DISABLE_TIMER_INTERRUPT (  )     ( TIMSK2 &= ~( 1<< OCIE2A ) )

Definition at line 143 of file sw_usart.h.

Referenced by ISR(), and SW_USART_init().

 
#define SW_USART_TX_ENABLE_PRESCALER (  )     ( SW_USART_TX_PRESCALE = SW_USART_PRESCALER )

Definition at line 145 of file sw_usart.h.

Referenced by SW_USART_PutChar().

 
#define SW_USART_TX_ENABLE_TIMER_INTERRUPT (  )     ( TIMSK2 |= ( 1<< OCIE2A ) )

Definition at line 142 of file sw_usart.h.

Referenced by SW_USART_PutChar().

#define SW_USART_TX_PIN   PD1

Transmit data pin

Definition at line 112 of file sw_usart.h.

Referenced by SW_USART_init().

#define SW_USART_TX_PRESCALE   TCCR2B

Timer/Counter Control (Prescaler) Register

Definition at line 107 of file sw_usart.h.

Referenced by SW_USART_init().

#define SW_USART_TX_TIMER   TCNT2

Timer Counter register

Definition at line 109 of file sw_usart.h.

Referenced by SW_USART_PutChar().


Typedef Documentation


Enumeration Type Documentation

Type defined enumeration holding software UART's state.

Enumerator:
IDLE  Idle state, both transmit and receive possible.
TRANSMIT  Transmitting byte.
TRANSMIT_STOP_BIT  Transmitting stop bit.
RECEIVE  Receiving byte.
DATA_PENDING  Byte received and ready to read.

Definition at line 78 of file sw_usart.h.

00079 {
00080     IDLE,                 
00081     TRANSMIT,             
00082     TRANSMIT_STOP_BIT,    
00083     RECEIVE,              
00084     DATA_PENDING          
00085 }AsynchronousStates_t;

Timer prescaler enumeration.

Enumerator:
TIMER_PRESCALER_OFF_gc  Timer prescaler off. Timer stopped.
TIMER_PRESCALER_1_gc  Timer runs at CPU speed.
TIMER_PRESCALER_8_gc  Timer runs at CPU/8 speed.
TIMER_PRESCALER_64_gc  Timer runs at CPU/64 speed.
TIMER_PRESCALER_256_gc  Timer runs at CPU/256 speed.
TIMER_PRESCALER_1024_gc  Timer runs at CPU/1024 speed.
TIMER_PRESCALER_EXT_FALLING_gc  Timer runs of external clock. Falling edge triggered.
TIMER_PRESCALER_EXT_RISING_gc  Timer runs of external clock. Rising edge triggered.

Definition at line 64 of file sw_usart.h.

00064                                   {
00065         TIMER_PRESCALER_OFF_gc         = (0x00), 
00066         TIMER_PRESCALER_1_gc           = (0x01), 
00067         TIMER_PRESCALER_8_gc           = (0x02), 
00068         TIMER_PRESCALER_64_gc          = (0x03), 
00069         TIMER_PRESCALER_256_gc         = (0x04), 
00070         TIMER_PRESCALER_1024_gc        = (0x05), 
00071         TIMER_PRESCALER_EXT_FALLING_gc = (0x06), 
00072         TIMER_PRESCALER_EXT_RISING_gc  = (0x07), 
00073 } TIMER_PRESCALER_t;


Function Documentation

void SW_USART_init ( void   ) 

Function to initialize the software UART.

This function will set up pins to transmit and receive on. Control of Timer0 and External interrupt 0.

Definition at line 200 of file sw_usart.c.

References IDLE, SW_USART_EXT_ICR, SW_USART_EXT_IFR, SW_USART_RX_COMPARE, SW_USART_RX_CTRL, SW_USART_RX_DISABLE_TIMER_INTERRUPT, SW_USART_RX_ENABLE_EXTERNAL0_INTERRUPT, SW_USART_RX_PIN, SW_USART_RX_PRESCALE, SW_USART_SET_TX_PIN, SW_USART_TRX_DDR, SW_USART_TRX_PORT, SW_USART_TX_COMPARE, SW_USART_TX_CTRL, SW_USART_TX_DISABLE_TIMER_INTERRUPT, SW_USART_TX_PIN, SW_USART_TX_PRESCALE, SwUartTICKS2WAITONE, SwUsartRXState, and SwUsartTXState.

Referenced by cdc_task_init().

00201 {
00202         /* Setup the TRX PORT for the Soft UART.
00203          * RX_PIN is input, tri-stated.
00204          * TX_PIN is output, set high to IDLE state.
00205          */
00206         SW_USART_TRX_PORT |= ( 1 << SW_USART_RX_PIN );
00207         SW_USART_TRX_DDR |= ( 1 << SW_USART_TX_PIN );
00208         SW_USART_SET_TX_PIN();
00209         
00210         /* Disable all TX and RX interrupts. */
00211         SW_USART_RX_DISABLE_TIMER_INTERRUPT();
00212         SW_USART_TX_DISABLE_TIMER_INTERRUPT();
00213         
00214         /* Initialize the RX Timer to CTC mode.
00215          * This will clear the timer on compare match, and the counter start
00216          * at bottom again. The compare value is equal to on bit length.
00217          */
00218         SW_USART_RX_PRESCALE = 0x00;
00219         SW_USART_RX_CTRL = 0x02;
00220         SW_USART_RX_COMPARE = SwUartTICKS2WAITONE;
00221 
00222         /* Initialize the TX Timer to CTC mode.
00223          * This will clear the timer on compare match, and the counter start
00224          * at bottom again. The compare value is equal to on bit length.
00225          */
00226         SW_USART_TX_PRESCALE = 0x00;
00227         SW_USART_TX_CTRL = 0x02;
00228         SW_USART_TX_COMPARE = SwUartTICKS2WAITONE;
00229         
00230         /* Initialize the RX external interrupt for sensing the start bit.
00231          * This will trigger on the falling edge of the IO pin.
00232          * Clear any pending interrupts and enable the interrupt.
00233          */
00234         SW_USART_EXT_ICR |= ( 1 << ISC01 );
00235         SW_USART_EXT_IFR |= (1 << INTF0 );
00236         SW_USART_RX_ENABLE_EXTERNAL0_INTERRUPT();
00237         
00238         /* Set TRX states initially to IDLE. */
00239         SwUsartRXState = IDLE;
00240         SwUsartTXState = IDLE;
00241 }

void SW_USART_PutChar ( const uint8_t  c  ) 

Send a unsigned char.

This function sends a unsigned char on the TX_PIN using the timer2 isr.

Note:
SW_USART_init(void) must be called in advance.
Parameters:
c char to transmit.
Return values:
void 

Definition at line 255 of file sw_usart.c.

References IDLE, SW_USART_CLR_TX_PIN, SW_USART_TX_CLEAR_TIMER_INTERRUPT, SW_USART_TX_COMPARE, SW_USART_TX_DISABLE_PRESCALER, SW_USART_TX_ENABLE_PRESCALER, SW_USART_TX_ENABLE_TIMER_INTERRUPT, SW_USART_TX_TIMER, SwUartTICKS2WAITONE, SwUartTXBitCount, SwUartTXData, SwUsartTXState, and TRANSMIT.

Referenced by cdc_task().

00256 {
00257         /* Wait until the TX is not busy or the communication will fail */
00258         while( SwUsartTXState != IDLE ){
00259         }
00260         
00261         /* Disable the clock to the timer and set the compare value to one bit length. */
00262         SW_USART_TX_DISABLE_PRESCALER();
00263         SW_USART_TX_COMPARE = SwUartTICKS2WAITONE;
00264 
00265         /* Change state to indicate that the TX is busy. */
00266         SwUsartTXState = TRANSMIT;
00267 
00268         /* Set intial bitcount value and copy byte into the TX buffer. */
00269         SwUartTXData = c;
00270         SwUartTXBitCount = 0;
00271         
00272         /* Clear the timer counter value and clear any pending interrupts. */
00273         SW_USART_TX_TIMER = 0;
00274         SW_USART_TX_CLEAR_TIMER_INTERRUPT();
00275         
00276         /* Start the timer, set pin value to transmit start bit and enable interrupt. */
00277         SW_USART_TX_ENABLE_PRESCALER();
00278         SW_USART_CLR_TX_PIN();
00279         SW_USART_TX_ENABLE_TIMER_INTERRUPT();
00280 }

uint8_t SW_USART_RX_Buffer_GetByte ( void   ) 

Get byte from the RX buffer.

Note:
The pointers might be changed in interrupts, and it's important to disable the global interrupt while manipulating the values that might be changed in the interrupt.
Return values:
Byte from buffer

Definition at line 336 of file sw_usart.c.

References AVR_ENTER_CRITICAL_REGION, AVR_LEAVE_CRITICAL_REGION, SW_USART_BUFFER_SIZE, SW_USART_RX_Buffer, SW_USART_RX_Num, and SW_USART_RX_Tail.

Referenced by cdc_task().

00337 {
00338         uint8_t ret_byte = 0;
00339         
00340         /* Check if there is any bytes in the buffer. */
00341         if(SW_USART_RX_Num > 0){
00342                 ret_byte = SW_USART_RX_Buffer[SW_USART_RX_Tail];
00343         
00344                 /* Enter a critical region as the value might be changed in an interrupt. */
00345                 AVR_ENTER_CRITICAL_REGION();
00346                 
00347                 /* Decrease number of bytes left in buffer. */
00348                 SW_USART_RX_Num--;
00349                 
00350                 /* Leave the critical region and restore SREG register. */
00351                 AVR_LEAVE_CRITICAL_REGION();
00352                 
00353                 /* Increase the tail pointer and wrap around if necessary. */
00354                 SW_USART_RX_Tail++;
00355                 if(SW_USART_RX_Tail >= SW_USART_BUFFER_SIZE){
00356                         SW_USART_RX_Tail = 0;
00357                 }
00358         }
00359         return ret_byte;
00360 }

void SW_USART_RX_Buffer_PutByte ( uint8_t  rx_byte  ) 

Function to put byte in RX buffer.

Note:
This function is called from an interrupt and might change the pointers while the SW_USART_RX_Buffer_GetByte(void) function access the same values.
Parameters:
rx_byte to put into buffer.

Definition at line 310 of file sw_usart.c.

References SW_USART_BUFFER_SIZE, SW_USART_RX_Buffer, SW_USART_RX_Head, and SW_USART_RX_Num.

Referenced by ISR().

00311 {
00312         /* Check if buffer is full. The byte will be lost if the buffer is full.*/
00313         if(SW_USART_RX_Num < SW_USART_BUFFER_SIZE ){
00314                 SW_USART_RX_Buffer[SW_USART_RX_Head] = rx_byte;
00315                 
00316                 /* Increase the number of bytes in buffer and the pointer. */
00317                 SW_USART_RX_Num++;
00318                 SW_USART_RX_Head++;
00319                 
00320                 /* Check if we should wrap around. */
00321                 if(SW_USART_RX_Head >= SW_USART_BUFFER_SIZE){
00322                         SW_USART_RX_Head = 0;
00323                 }
00324         }       
00325 }

void SW_USART_Set_Baudrate ( uint32_t  new_baud  ) 

Set new baudrate.

Note:
Change do not work yet, do not use.
Parameters:
new_baud The new baudrate to set.

Definition at line 369 of file sw_usart.c.

Referenced by cdc_set_line_coding().

00370 {
00371 //      SwUartTICKS2WAITONE = (uint8_t) ((1000000/new_baud)-1);
00372 }

uint8_t SW_USART_Test_Hit ( void   ) 

Function to check if data is pending in the buffer.

Return values:
true if data is pending, false otherwise

Definition at line 287 of file sw_usart.c.

References SW_USART_RX_Num.

Referenced by cdc_task().

00288 {
00289         return (SW_USART_RX_Num > 0);
00290 }

uint8_t SW_USART_Tx_Ready ( void   ) 

Function to check if transmitter is busy.

Return values:
true if ready, false otherwise.

Definition at line 297 of file sw_usart.c.

References IDLE, and SwUsartTXState.

00298 {
00299         return ( SwUsartTXState == IDLE );
00300 }


Variable Documentation

volatile uint8_t SW_USART_RX_Buffer[SW_USART_BUFFER_SIZE] [static]

Definition at line 164 of file sw_usart.h.

Referenced by SW_USART_RX_Buffer_GetByte(), and SW_USART_RX_Buffer_PutByte().

volatile uint8_t SW_USART_RX_Head = 0 [static]

Definition at line 165 of file sw_usart.h.

Referenced by SW_USART_RX_Buffer_PutByte().

volatile uint8_t SW_USART_RX_Num = 0 [static]

volatile uint8_t SW_USART_RX_Tail = 0 [static]

Definition at line 166 of file sw_usart.h.

Referenced by SW_USART_RX_Buffer_GetByte().

volatile uint8_t SwUartRXBitCount [static]

RX bit counter.

Definition at line 161 of file sw_usart.h.

Referenced by ISR().

volatile uint8_t SwUartRXData [static]

Storage for received bits.

Definition at line 160 of file sw_usart.h.

Referenced by ISR().

volatile uint8_t SwUartTICKS2WAITONE = SW_USART_TICKS2WAITONE [static]

Definition at line 162 of file sw_usart.h.

Referenced by ISR(), SW_USART_init(), and SW_USART_PutChar().

volatile uint8_t SwUartTXBitCount [static]

TX bit counter.

Definition at line 159 of file sw_usart.h.

Referenced by ISR(), and SW_USART_PutChar().

volatile uint8_t SwUartTXData [static]

Data to be transmitted.

Definition at line 158 of file sw_usart.h.

Referenced by ISR(), and SW_USART_PutChar().

Holds the state of the UART.

Definition at line 156 of file sw_usart.h.

Referenced by ISR(), and SW_USART_init().

Holds the state of the UART.

Definition at line 157 of file sw_usart.h.

Referenced by ISR(), SW_USART_init(), SW_USART_PutChar(), and SW_USART_Tx_Ready().

@DOC_TITLE@
Generated on Mon Jan 18 09:26:10 2010 for AVR1907 Xplain USB Gateway by doxygen 1.5.5