00001
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #ifndef _UART_DRV_H_
00042 #define _UART_DRV_H_
00043
00044 #define MSK_UART_5BIT 0x00
00045 #define MSK_UART_6BIT 0x02
00046 #define MSK_UART_7BIT 0x04
00047 #define MSK_UART_8BIT 0x06
00048 #define MSK_UART_9BIT 0x06
00049
00050 #define MSK_UART_RX_DONE 0x80
00051 #define MSK_UART_TX_COMPLET 0x40
00052 #define MSK_UART_DRE 0x20
00053
00054 #define MSK_UART_ENABLE_IT_RX 0x80
00055 #define MSK_UART_ENABLE_IT_TX 0x40
00056 #define MSK_UART_ENABLE_RX 0x10
00057 #define MSK_UART_ENABLE_TX 0x08
00058 #define MSK_UART_TX_BIT9 0x01
00059 #define MSK_UART_RX_BIT9 0x02
00060
00061 #ifdef USE_UART1
00062 #define UCSRC (UCSR0C)
00063 #define UCSRB (UCSR0B)
00064 #define UCSRA (UCSR0A)
00065 #define UDR (UDR0)
00066 #define UBRRL (UBRR0L)
00067 #define UBRRH (UBRR0H)
00068 #define UBRR (UBRR0)
00069 #endif
00070 #ifdef USE_UART2
00071 #define UCSRC (UCSR1C)
00072 #define UCSRB (UCSR1B)
00073 #define UCSRA (UCSR1A)
00074 #define UDR (UDR1)
00075 #define UBRRL (UBRR1L)
00076 #define UBRRH (UBRR1H)
00077 #define UBRR (UBRR1)
00078
00079 #endif
00080
00081
00082 #define Uart_hw_init(config) (UCSRC=config)
00083 #define Uart_enable() (UCSRB|=MSK_UART_ENABLE_RX|MSK_UART_ENABLE_TX)
00084 #define Uart_tx_ready() (UCSRA&MSK_UART_DRE)
00085 #define Uart_set_tx_busy()
00086 #define Uart_send_byte(ch) (UDR=ch)
00087 #define Uart_rx_ready() (UCSRA&MSK_UART_RX_DONE)
00088 #define Uart_get_byte() (UDR)
00089 #define Uart_ack_rx_byte()
00090
00091 #define Uart_enable_it_rx() (UCSRB|=MSK_UART_ENABLE_IT_RX)
00092 #define Uart_enable_it_tx() (UCSRB|=MSK_UART_ENABLE_IT_TX)
00093 #define Uart_disable_it_rx() (UCSRB&=~MSK_UART_ENABLE_IT_RX)
00094
00095 #endif