00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef _UART_DRV_H_
00015 #define _UART_DRV_H_
00016
00017 #define MSK_UART_5BIT 0x00
00018 #define MSK_UART_6BIT 0x02
00019 #define MSK_UART_7BIT 0x04
00020 #define MSK_UART_8BIT 0x06
00021 #define MSK_UART_9BIT 0x06
00022
00023 #define MSK_UART_RX_DONE 0x80
00024 #define MSK_UART_TX_COMPLET 0x40
00025 #define MSK_UART_DRE 0x20
00026
00027 #define MSK_UART_ENABLE_IT_RX 0x80
00028 #define MSK_UART_ENABLE_IT_TX 0x40
00029 #define MSK_UART_ENABLE_RX 0x10
00030 #define MSK_UART_ENABLE_TX 0x08
00031 #define MSK_UART_TX_BIT9 0x01
00032 #define MSK_UART_RX_BIT9 0x02
00033
00034 #ifdef USE_UART1
00035 #define UCSRC (UCSR0C)
00036 #define UCSRB (UCSR0B)
00037 #define UCSRA (UCSR0A)
00038 #define UDR (UDR0)
00039 #define UBRRL (UBRR0L)
00040 #define UBRRH (UBRR0H)
00041 #define UBRR (UBRR0)
00042 #endif
00043 #ifdef USE_UART2
00044 #define UCSRC (UCSR1C)
00045 #define UCSRB (UCSR1B)
00046 #define UCSRA (UCSR1A)
00047 #define UDR (UDR1)
00048 #define UBRRL (UBRR1L)
00049 #define UBRRH (UBRR1H)
00050 #define UBRR (UBRR1)
00051
00052 #endif
00053
00054
00055 #define Uart_hw_init(config) (UCSRC=config)
00056
00057
00058 #define Uart_enable() (UCSRB|=MSK_UART_ENABLE_RX|MSK_UART_ENABLE_TX)
00059 #define Uart_tx_ready() (UCSRA&MSK_UART_DRE)
00060 #define Uart_set_tx_busy()
00061 #define Uart_send_byte(ch) (UDR=ch)
00062 #define Uart_rx_ready() (UCSRA&MSK_UART_RX_DONE)
00063 #define Uart_get_byte() (UDR)
00064 #define Uart_ack_rx_byte()
00065
00066 #define Uart_enable_it_rx() (UCSRB|=MSK_UART_ENABLE_IT_RX)
00067 #define Uart_enable_it_tx() (UCSRB|=MSK_UART_ENABLE_IT_TX)
00068 #define Uart_disable_it_rx() (UCSRB&=~MSK_UART_ENABLE_IT_RX)
00069
00070 #endif