00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef _UART_DRV_H_
00014 #define _UART_DRV_H_
00015
00016 #define MSK_UART_5BIT 0x00
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
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
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
00056
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