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
00042
00043
00044 #ifndef _UART_DRV_H_
00045 #define _UART_DRV_H_
00046
00047 #define MSK_UART_5BIT 0x00
00048 #define MSK_UART_6BIT 0x02
00049 #define MSK_UART_7BIT 0x04
00050 #define MSK_UART_8BIT 0x06
00051 #define MSK_UART_9BIT 0x06
00052
00053 #define MSK_UART_RX_DONE 0x80
00054 #define MSK_UART_TX_COMPLET 0x40
00055 #define MSK_UART_DRE 0x20
00056
00057 #define MSK_UART_ENABLE_IT_RX 0x80
00058 #define MSK_UART_ENABLE_IT_TX 0x40
00059 #define MSK_UART_ENABLE_RX 0x10
00060 #define MSK_UART_ENABLE_TX 0x08
00061 #define MSK_UART_TX_BIT9 0x01
00062 #define MSK_UART_RX_BIT9 0x02
00063
00064 #ifdef USE_UART1
00065 #define UCSRC (UCSR0C)
00066 #define UCSRB (UCSR0B)
00067 #define UCSRA (UCSR0A)
00068 #define UDR (UDR0)
00069 #define UBRRL (UBRR0L)
00070 #define UBRRH (UBRR0H)
00071 #define UBRR (UBRR0)
00072 #endif
00073 #ifdef USE_UART2
00074 #define UCSRC (UCSR1C)
00075 #define UCSRB (UCSR1B)
00076 #define UCSRA (UCSR1A)
00077 #define UDR (UDR1)
00078 #define UBRRL (UBRR1L)
00079 #define UBRRH (UBRR1H)
00080 #define UBRR (UBRR1)
00081
00082 #endif
00083
00084
00085 #define Uart_hw_init(config) (UCSRC=config)
00086 #define Uart_enable() (UCSRB|=MSK_UART_ENABLE_RX|MSK_UART_ENABLE_TX)
00087 #define Uart_tx_ready() (UCSRA&MSK_UART_DRE)
00088 #define Uart_set_tx_busy()
00089 #define Uart_send_byte(ch) (UDR=ch)
00090 #define Uart_rx_ready() (UCSRA&MSK_UART_RX_DONE)
00091 #define Uart_get_byte() (UDR)
00092 #define Uart_ack_rx_byte()
00093
00094 #define Uart_enable_it_rx() (UCSRB|=MSK_UART_ENABLE_IT_RX)
00095 #define Uart_enable_it_tx() (UCSRB|=MSK_UART_ENABLE_IT_TX)
00096 #define Uart_disable_it_rx() (UCSRB&=~MSK_UART_ENABLE_IT_RX)
00097
00098 #endif