uart_drv.h

Go to the documentation of this file.
00001 /*H**************************************************************************
00002 * NAME:         uart_drv.h
00003 *----------------------------------------------------------------------------
00004 * Copyright (c) 2006 Atmel.
00005 *----------------------------------------------------------------------------
00006 * RELEASE:      at90usb162-cdc-1_0_1
00007 * REVISION:     1.1.2.3
00008 *----------------------------------------------------------------------------
00009 * PURPOSE:
00010 * Provide Uart driver
00011 *****************************************************************************/
00012 
00013 #ifndef _UART_DRV_H_
00014 #define _UART_DRV_H_
00015 
00016 #define MSK_UART_5BIT           0x00 /* UCSRnC register */
00017 #define MSK_UART_6BIT           0x02
00018 #define MSK_UART_7BIT           0x04
00019 #define MSK_UART_8BIT           0x06
00020 #define MSK_UART_9BIT           0x06
00021 
00022 #define MSK_UART_RX_DONE        0x80 /* UCSRnA register */
00023 #define MSK_UART_TX_COMPLET     0x40
00024 #define MSK_UART_DRE            0x20
00025 
00026 #define MSK_UART_ENABLE_IT_RX   0x80
00027 #define MSK_UART_ENABLE_IT_TX   0x40
00028 #define MSK_UART_ENABLE_RX      0x10 /* UCSRnB register */
00029 #define MSK_UART_ENABLE_TX      0x08
00030 #define MSK_UART_TX_BIT9        0x01
00031 #define MSK_UART_RX_BIT9        0x02
00032 
00033 #ifdef USE_UART1
00034     #define UCSRC   (UCSR0C)
00035     #define UCSRB   (UCSR0B)
00036     #define UCSRA   (UCSR0A)
00037     #define UDR     (UDR0)
00038     #define UBRRL   (UBRR0L)
00039     #define UBRRH   (UBRR0H)
00040     #define UBRR    (UBRR0)
00041 #endif
00042 #ifdef USE_UART2
00043     #define UCSRC    (UCSR1C)
00044     #define UCSRB    (UCSR1B)
00045     #define UCSRA    (UCSR1A)
00046     #define UDR      (UDR1)
00047     #define UBRRL    (UBRR1L)
00048     #define UBRRH    (UBRR1H)
00049     #define UBRR     (UBRR1)
00050 
00051 #endif
00052 
00053 
00054 #define Uart_hw_init(config)    (UCSRC=config)
00055 /*#define Uart_set_baudrate(bdr)  ( UBRRH = (Uchar)((((Uint32)FOSC*1000L)/((Uint32)bdr*16)-1)>>8),\
00056                                   UBRRL = (Uchar)(((Uint32)FOSC*1000 )/((Uint32)bdr*16)-1)    )*/
00057 #define Uart_enable()           (UCSRB|=MSK_UART_ENABLE_RX|MSK_UART_ENABLE_TX)
00058 #define Uart_tx_ready()         (UCSRA&MSK_UART_DRE)
00059 #define Uart_set_tx_busy()
00060 #define Uart_send_byte(ch)      (UDR=ch)
00061 #define Uart_rx_ready()         (UCSRA&MSK_UART_RX_DONE)
00062 #define Uart_get_byte()         (UDR)
00063 #define Uart_ack_rx_byte()
00064 
00065 #define Uart_enable_it_rx()    (UCSRB|=MSK_UART_ENABLE_IT_RX)
00066 #define Uart_enable_it_tx()    (UCSRB|=MSK_UART_ENABLE_IT_TX)
00067 #define Uart_disable_it_rx()   (UCSRB&=~MSK_UART_ENABLE_IT_RX)
00068 
00069 #endif

Generated on Fri Jun 15 14:15:32 2007 for Atmel by  doxygen 1.5.1-p1