AVR Z-LINKŪ


com.h File Reference


Detailed Description

This files implements the API for the communications library for the FTDI chip on the STK541 board and the AVR USART used for the RZ502 version.

This file contains the function prototypes for the Transceiver Access Toolbox, hence it is an API. The Transceiver Access Toolbox is an abstraction layer that hides the details of the radio transceiver from the end-user. The goal for the Transceiver Access Toolbox is to wrap the services that the radio transceiver can perform into easy to use functions.

Application note:
AVR2001: Transceiver Access Toolbox for the AT86RF230
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
$Name$
Revision
613
$RCSfile$
Date
2006-04-07 14:40:07 +0200 (fr, 07 apr 2006)

Copyright (c) 2006, 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 com.h.

#include <stdint.h>
#include <stdbool.h>
#include "compiler.h"

Include dependency graph for com.h:

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

Go to the source code of this file.

Defines

#define DISABLE_RECEIVE_COMPLETE_INTERRUPT   ( UCSR0B &= ~( 1 << RXCIE0 ) )
#define DISABLE_RECEIVER   ( UCSR0B &= ~( 1 << RXEN0 ) )
#define DISABLE_TRANSMITTER   ( UCSR0B &= ~( 1 << TXEN0 ) )
#define ENABLE_RECEIVE_COMPLETE_INTERRUPT   ( UCSR0B |= ( 1 << RXCIE0 ) )
#define ENABLE_RECEIVER   ( UCSR0B |= ( 1 << RXEN0 ) )
#define ENABLE_TRANSMITTER   ( UCSR0B |= ( 1 << TXEN0 ) )
#define FTDI_CONFIGURE_PIN_CHANGE_INTERRUPT()   ( EICRB &= ~( ( 1 << ISC71 ) | ( 1 << ISC70 ) ) )
#define FTDI_DDR   ( DDRE )
#define FTDI_DISABLE_RECEIVER()   (EIMSK &= ~( 1 << FTDI_RX_PIN ) )
#define FTDI_ENABLE_RECEIVER()   ( EIMSK |= ( 1 << FTDI_RX_PIN ) )
#define FTDI_ENABLE_TX()   ( FTDI_DDR &= ~( 1 << FTDI_TX_PIN ) )
#define FTDI_Fifo   ( ( volatile uint8_t * )FTDI_FIFO_ADDRESS )
#define FTDI_FIFO_ADDRESS   ( 0xF000 )
#define FTDI_PIN   ( PINE )
#define FTDI_PORT   ( PORTE )
#define FTDI_RX_PIN   ( PINE7 )
#define FTDI_TX_MASK   ( 1 << FTDI_TX_PIN )
#define FTDI_TX_PIN   ( PINE6 )
#define LOW   ( 0x00 )
#define XRAM_DISABLE()   XMCRA &= ~( 1 << SRE )
#define XRAM_ENABLE()   XMCRA |= ( 1 << SRE ); XMCRB |= ( 1 << XMBK )

Enumerations

enum  baud_rate_t { BR_9600 = 0x33, BR_19200 = 0x19, BR_38400 = 0x0C }
 Enumeration that defines the available baud rates for
the serial interface. The values cana be found in the datasheet on page 233. More...

Functions

uint8_t com_get_number_of_received_bytes (void)
 This function returns number of bytes received during last data reception.
uint8_t * com_get_received_data (void)
 This function retruns the address to the first byte in the buffer where received data is stored3.
void com_init (baud_rate_t rate)
 This function initializes the chosen communication interface (USB or USART).
void com_reset_receiver (void)
 This function is used to reset the commuincation interface after each data reception is done, and the end-user has read data.
void com_send_hex (uint8_t nmbr)
 This function prints the supplied argument as a hex number.
void com_send_string (uint8_t *data, uint8_t data_length)
 This function sends data on the chosen communication interface (USB or USART).


Define Documentation

#define DISABLE_RECEIVE_COMPLETE_INTERRUPT   ( UCSR0B &= ~( 1 << RXCIE0 ) )

Disables an interrupt each time the receiver completes a symbol.

Definition at line 71 of file com.h.

Referenced by com_reset_receiver(), and ISR().

#define DISABLE_RECEIVER   ( UCSR0B &= ~( 1 << RXEN0 ) )

Disables receiver.

Definition at line 65 of file com.h.

#define DISABLE_TRANSMITTER   ( UCSR0B &= ~( 1 << TXEN0 ) )

Disables transmitter.

Definition at line 68 of file com.h.

#define ENABLE_RECEIVE_COMPLETE_INTERRUPT   ( UCSR0B |= ( 1 << RXCIE0 ) )

Enables an interrupt each time the receiver completes a symbol.

Definition at line 70 of file com.h.

Referenced by com_init(), and com_reset_receiver().

#define ENABLE_RECEIVER   ( UCSR0B |= ( 1 << RXEN0 ) )

Enables receiver.

Definition at line 64 of file com.h.

Referenced by com_init().

#define ENABLE_TRANSMITTER   ( UCSR0B |= ( 1 << TXEN0 ) )

Enables transmitter.

Definition at line 67 of file com.h.

Referenced by com_init().

 
#define FTDI_CONFIGURE_PIN_CHANGE_INTERRUPT (  )     ( EICRB &= ~( ( 1 << ISC71 ) | ( 1 << ISC70 ) ) )

Definition at line 87 of file com.h.

Referenced by com_init().

#define FTDI_DDR   ( DDRE )

Definition at line 78 of file com.h.

 
#define FTDI_DISABLE_RECEIVER (  )     (EIMSK &= ~( 1 << FTDI_RX_PIN ) )

Definition at line 89 of file com.h.

Referenced by com_reset_receiver(), and ISR().

 
#define FTDI_ENABLE_RECEIVER (  )     ( EIMSK |= ( 1 << FTDI_RX_PIN ) )

Definition at line 88 of file com.h.

Referenced by com_init(), and com_reset_receiver().

 
#define FTDI_ENABLE_TX (  )     ( FTDI_DDR &= ~( 1 << FTDI_TX_PIN ) )

Definition at line 86 of file com.h.

Referenced by com_init().

#define FTDI_Fifo   ( ( volatile uint8_t * )FTDI_FIFO_ADDRESS )

Definition at line 84 of file com.h.

Referenced by com_send_hex(), com_send_string(), and ISR().

#define FTDI_FIFO_ADDRESS   ( 0xF000 )

Definition at line 83 of file com.h.

#define FTDI_PIN   ( PINE )

Definition at line 79 of file com.h.

Referenced by com_send_hex(), and com_send_string().

#define FTDI_PORT   ( PORTE )

Definition at line 77 of file com.h.

#define FTDI_RX_PIN   ( PINE7 )

Definition at line 82 of file com.h.

#define FTDI_TX_MASK   ( 1 << FTDI_TX_PIN )

Definition at line 81 of file com.h.

Referenced by com_send_hex(), and com_send_string().

#define FTDI_TX_PIN   ( PINE6 )

Definition at line 80 of file com.h.

#define LOW   ( 0x00 )

Definition at line 73 of file com.h.

Referenced by com_send_hex(), and com_send_string().

 
#define XRAM_DISABLE (  )     XMCRA &= ~( 1 << SRE )

Definition at line 75 of file com.h.

 
#define XRAM_ENABLE (  )     XMCRA |= ( 1 << SRE ); XMCRB |= ( 1 << XMBK )

Definition at line 74 of file com.h.

Referenced by com_init().


Enumeration Type Documentation

enum baud_rate_t

Enumeration that defines the available baud rates for
the serial interface. The values cana be found in the datasheet on page 233.

Note:
The members should not be altered. This is possibly harmful for
setting of the baud rate registers in serialInterfaceInitialization.
Enumerator:
BR_9600  Sets the baud rate to 9600.
BR_19200  Sets the baud rate to 19200.
BR_38400  Sets the baud rate to 38400.

Definition at line 98 of file com.h.

00098             {
00099   
00100   BR_9600  = 0x33, 
00101   BR_19200 = 0x19, 
00102   BR_38400 = 0x0C  
00103 }baud_rate_t;


Function Documentation

uint8_t com_get_number_of_received_bytes ( void   ) 

This function returns number of bytes received during last data reception.

Return values:
0 No data is available. Data reception is not done.
1 Error: Typed Frame Too Long.
Returns:
Any non zero value returned indicatest that data is available and should be read.

Definition at line 187 of file com.c.

References com_data_reception_finished, and com_number_of_received_bytes.

Referenced by main().

00187                                                 {
00188     
00189     if (com_data_reception_finished == true) {
00190         return com_number_of_received_bytes; 
00191     } else { return 0; }
00192 }

uint8_t* com_get_received_data ( void   ) 

This function retruns the address to the first byte in the buffer where received data is stored3.

Note:
This function should only be called after it has been verified that the data reception is done (com_get_number_of_received_bytes() != 0).
Returns:
Pointer to the first byte in the array of received data.

Definition at line 177 of file com.c.

References com_buffer.

Referenced by main().

00177                                        {
00178     return &com_buffer[0];
00179 }

void com_init ( baud_rate_t  rate  ) 

This function initializes the chosen communication interface (USB or USART).

Parameters:
[in] rate Baudrate used by the AVR's USART.

Definition at line 77 of file com.c.

References com_data_reception_finished, com_number_of_received_bytes, ENABLE_RECEIVE_COMPLETE_INTERRUPT, ENABLE_RECEIVER, ENABLE_TRANSMITTER, FTDI_CONFIGURE_PIN_CHANGE_INTERRUPT, FTDI_ENABLE_RECEIVER, FTDI_ENABLE_TX, and XRAM_ENABLE.

Referenced by avr_init().

00077                                  {
00078   
00079 #if defined( RZ502 )    
00080     //Initialize USART module.
00081     UBRR0H = 0x00;
00082     UBRR0L = rate;
00083   
00084     //Enable USART transmitter module. Always on.
00085     ENABLE_RECEIVER;
00086     ENABLE_TRANSMITTER;
00087         
00088     //8-N-1.
00089     UCSR0C |= ( 1 << UCSZ01 ) | ( 1 << UCSZ00 ); 
00090   
00091     com_number_of_received_bytes = 0;
00092     com_data_reception_finished = false;
00093     ENABLE_RECEIVE_COMPLETE_INTERRUPT;
00094 
00095 #elif defined( STK541 )
00096     XRAM_ENABLE( ); 
00097         
00098         /* make sure USB_RXF and USB_TXE are inputs */
00099         FTDI_ENABLE_TX( );
00100         
00101         //Enable external interrupt on FTDI_RX pin.
00102         FTDI_CONFIGURE_PIN_CHANGE_INTERRUPT( );
00103         FTDI_ENABLE_RECEIVER( );
00104 #else
00105     #error "Board Option Not Supported."  
00106 #endif  
00107 }

void com_reset_receiver ( void   ) 

This function is used to reset the commuincation interface after each data reception is done, and the end-user has read data.

Definition at line 198 of file com.c.

References com_data_reception_finished, com_number_of_received_bytes, DISABLE_RECEIVE_COMPLETE_INTERRUPT, ENABLE_RECEIVE_COMPLETE_INTERRUPT, FTDI_DISABLE_RECEIVER, and FTDI_ENABLE_RECEIVER.

Referenced by main().

00198                                {
00199     
00200 #if defined( RZ502 )    
00201     DISABLE_RECEIVE_COMPLETE_INTERRUPT;
00202     
00203     com_number_of_received_bytes = 0;
00204     com_data_reception_finished = false;
00205     
00206     uint8_t dummy = 0;
00207     //Following loop is used to ensure that the rx FIFO is flushed.
00208         //Sometimes it gets cloged up with old data.
00209         for( ;  UCSR0A & ( 1 << RXC0 ); ){
00210                 dummy = UDR0;  
00211         }
00212     
00213     ENABLE_RECEIVE_COMPLETE_INTERRUPT;
00214 #elif defined( STK541 )
00215     FTDI_DISABLE_RECEIVER( );
00216     
00217     com_number_of_received_bytes = 0;
00218     com_data_reception_finished = false;
00219     
00220     FTDI_ENABLE_RECEIVER( );
00221 #else
00222     #error "Board Option Not Supported."
00223 #endif    
00224 }

void com_send_hex ( uint8_t  nmbr  ) 

This function prints the supplied argument as a hex number.

Parameters:
[in] nmbr Number to be printed as a hexadescimal number.

Definition at line 138 of file com.c.

References FTDI_Fifo, FTDI_PIN, FTDI_TX_MASK, hex_lookup, and LOW.

Referenced by main().

00138                                  {
00139 
00140     #if defined( RZ502 )        
00141         for(; !(UCSR0A & (1 << UDRE0));) {;}
00142             UDR0 = '0'; //Put symbol in data register.
00143     
00144         for(; !(UCSR0A & (1 << UDRE0));) {;}
00145             UDR0 = 'x'; //Put symbol in data register.
00146         
00147         for(; !(UCSR0A & (1 << UDRE0));) {;}
00148             UDR0 = hex_lookup[ ( nmbr >> 4 ) & 0x0F ];
00149         
00150         for(; !(UCSR0A & (1 << UDRE0));) {;}
00151             UDR0 = hex_lookup[ ( nmbr & 0x0F ) ];
00152 #elif defined( STK541 )
00153         
00154         //Wait until the fifo is ready.
00155             while((FTDI_TX_MASK & FTDI_PIN) != LOW){;}
00156             *FTDI_Fifo = '0'; //Put symbol in data register.
00157     
00158         while((FTDI_TX_MASK & FTDI_PIN) != LOW){;}
00159             *FTDI_Fifo = 'x'; //Put symbol in data register.
00160         
00161         while((FTDI_TX_MASK & FTDI_PIN) != LOW){;}
00162             *FTDI_Fifo = hex_lookup[ ( nmbr >> 4 ) & 0x0F ];
00163         
00164         while((FTDI_TX_MASK & FTDI_PIN) != LOW){;}
00165             *FTDI_Fifo = hex_lookup[ ( nmbr & 0x0F ) ];
00166 #else
00167     #error "Board Option Not Supported."
00168 #endif
00169 }

void com_send_string ( uint8_t *  data,
uint8_t  data_length 
)

This function sends data on the chosen communication interface (USB or USART).

Parameters:
[in] data Pointer to data that is to be sent on the communication interface.
[in] data_length Number of bytes to read from the array pointed to by data.

Definition at line 114 of file com.c.

References FTDI_Fifo, FTDI_PIN, FTDI_TX_MASK, and LOW.

Referenced by main().

00114                                                           {
00115     
00116     while (--data_length > 0) {
00117         
00118 #if defined( RZ502 )        
00119         for(; !(UCSR0A & (1 << UDRE0));) {;}
00120             UDR0 = *data++; //Put symbol in data register.
00121     
00122 #elif defined( STK541 )
00123         //Wait until the fifo is ready.
00124             while((FTDI_TX_MASK & FTDI_PIN) != LOW){;}
00125         
00126             //Write symbol to memory address.
00127             *FTDI_Fifo = ( *data++ );
00128 #else
00129     #error "Board Option Not Supported."
00130 #endif
00131     }    
00132 }

@DOC_TITLE@
Generated on Wed Jul 25 21:15:49 2007 for AVR2001 Software Programmer's Manual by doxygen 1.4.7