rs232_atmega128.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2006, Technical University of Munich
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the Institute nor the names of its contributors
00014  *    may be used to endorse or promote products derived from this software
00015  *    without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00027  * SUCH DAMAGE.
00028  *
00029  * This file is part of the Contiki operating system.
00030  *
00031  * @(#)$$
00032  */
00033 
00034 /**
00035  * \file
00036  *         AVR specific definitions for the rs232 port.
00037  *
00038  * \author
00039  *         Simon Barner <barner@in.tum.de
00040  */
00041 
00042 #ifndef __RS232_ATMEGA128__
00043 #define __RS232_ATMEGA128__
00044 /******************************************************************************/
00045 /***   Includes                                                               */
00046 /******************************************************************************/
00047 #include <avr/io.h>
00048 
00049 /******************************************************************************/
00050 /***   RS232 ports                                                            */
00051 /******************************************************************************/
00052 #define RS232_PORT_0 0
00053 #define RS232_PORT_1 1
00054 
00055 /******************************************************************************/
00056 /***   Baud rates                                                             */
00057 /******************************************************************************/
00058 #if (F_CPU == 16000000UL)
00059 /* Single speed operation (U2X = 0)*/
00060 #define USART_BAUD_2400 416
00061 #define USART_BAUD_4800 207
00062 #define USART_BAUD_9600 103
00063 #define USART_BAUD_14400 68
00064 #define USART_BAUD_19200 51
00065 #define USART_BAUD_28800 34
00066 #define USART_BAUD_38400 25
00067 #define USART_BAUD_57600 16
00068 #define USART_BAUD_76800 12
00069 #define USART_BAUD_115200 8
00070 #define USART_BAUD_230400 3
00071 #define USART_BAUD_250000 3
00072 #define USART_BAUD_500000 1
00073 #define USART_BAUD_1000000 0
00074 #elif (F_CPU == 14745600UL)
00075 /* Single speed operation (U2X = 0)*/
00076 #define USART_BAUD_2400 383
00077 #define USART_BAUD_4800 191
00078 #define USART_BAUD_9600 95
00079 #define USART_BAUD_14400 63
00080 #define USART_BAUD_19200 47
00081 #define USART_BAUD_28800 31
00082 #define USART_BAUD_38400 23
00083 #define USART_BAUD_57600 15
00084 #define USART_BAUD_76800 11
00085 #define USART_BAUD_115200 7
00086 #define USART_BAUD_230400 3
00087 #define USART_BAUD_250000 3
00088 #define USART_BAUD_500000 1
00089 #define USART_BAUD_1000000 0
00090 #elif (F_CPU == 8000000UL)
00091 /* Single speed operation (U2X = 0)*/
00092 #define USART_BAUD_2400 207
00093 #define USART_BAUD_4800 103
00094 #define USART_BAUD_9600 51
00095 #define USART_BAUD_14400 34
00096 #define USART_BAUD_19200 25
00097 #define USART_BAUD_28800 16
00098 #define USART_BAUD_38400 12
00099 #define USART_BAUD_57600 8
00100 #define USART_BAUD_76800 6
00101 #define USART_BAUD_115200 3
00102 #define USART_BAUD_230400 1
00103 #define USART_BAUD_250000 1
00104 #define USART_BAUD_500000 0
00105 /* For Micaz the MCU clock rate is 7.3728 MHz*/
00106 #elif (F_CPU == 7372800UL)
00107 /* Single speed operation (U2X = 0)*/
00108 #define USART_BAUD_2400 191
00109 #define USART_BAUD_4800 95
00110 #define USART_BAUD_9600 47
00111 #define USART_BAUD_14400 31
00112 #define USART_BAUD_19200 23
00113 #define USART_BAUD_28800 15
00114 #define USART_BAUD_38400 11
00115 #define USART_BAUD_57600 7
00116 #define USART_BAUD_76800 5
00117 #define USART_BAUD_115200 3
00118 #define USART_BAUD_230400 1
00119 #define USART_BAUD_250000 1
00120 #define USART_BAUD_500000 0
00121 #else
00122 #error "Please define the baud rates for your CPU clock: ATmega128 handbook p. \
00123 195-198 or set the rate in contiki-conf.h"
00124 #endif
00125 
00126 
00127 /******************************************************************************/
00128 /***   Interrupt settings                                                     */
00129 /******************************************************************************/
00130 #define USART_INTERRUPT_RX_COMPLETE _BV (RXCIE)
00131 #define USART_INTERRUPT_TX_COMPLETE _BV (TXCIE)
00132 #define USART_INTERRUPT_DATA_REG_EMPTY _BV (UDRIE)
00133 
00134 /******************************************************************************/
00135 /***   Receiver / transmitter                                                 */
00136 /******************************************************************************/
00137 #define USART_RECEIVER_ENABLE _BV (RXEN)
00138 #define USART_TRANSMITTER_ENABLE _BV (TXEN)
00139 
00140 /******************************************************************************/
00141 /***   Mode select                                                            */
00142 /******************************************************************************/
00143 #define USART_MODE_ASYNC 0x00
00144 #define USART_MODE_SYNC _BV (UMSEL)
00145 
00146 /******************************************************************************/
00147 /***   Parity                                                                 */
00148 /******************************************************************************/
00149 #define USART_PARITY_NONE 0x00
00150 #define USART_PARITY_EVEN _BV (UPM1)
00151 #define USART_PARITY_ODD  _BV (UPM1) | _BV (UPM0)
00152 
00153 /******************************************************************************/
00154 /***   Stop bits                                                              */
00155 /******************************************************************************/
00156 #define USART_STOP_BITS_1 0x00
00157 #define USART_STOP_BITS_2 _BV (USBS)
00158 
00159 /******************************************************************************/
00160 /***   Character size                                                         */
00161 /******************************************************************************/
00162 #define USART_DATA_BITS_5 0x00
00163 #define USART_DATA_BITS_6 _BV (UCSZ0)
00164 #define USART_DATA_BITS_7 _BV (UCSZ1)
00165 #define USART_DATA_BITS_8 _BV (UCSZ1) | _BV (UCSZ0)
00166 // #define USART_DATA_BITS_9 (needs also UCSZ2 bit in UCSRnB)
00167 
00168 /******************************************************************************/
00169 /***   Clock polarity                                                         */
00170 /******************************************************************************/
00171 #define USART_RISING_XCKN_EDGE 0x00
00172 #define USART_FALLING_XCKN_EDGE _BV (UCPOL)
00173 
00174 #endif /* #ifndef __RS232_ATMEGA128__ */

Generated on Mon Apr 11 14:23:36 2011 for Contiki 2.5 by  doxygen 1.6.1