00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef UART_H
00019 #define UART_H
00020
00021 #include "global.h"
00022 #include "buffer.h"
00023
00024
00025
00026 #define UART_DEFAULT_BAUD_RATE 9600
00027
00028
00029
00030 #ifndef UART_TX_BUFFER_SIZE
00031 #define UART_TX_BUFFER_SIZE 0x0040
00032 #endif
00033 #ifndef UART_RX_BUFFER_SIZE
00034 #define UART_RX_BUFFER_SIZE 0x0040
00035 #endif
00036
00037
00038
00039
00040 #ifdef UART_BUFFER_EXTERNAL_RAM
00041
00042 #define UART_TX_BUFFER_ADDR 0x1000
00043 #define UART_RX_BUFFER_ADDR 0x1100
00044 #endif
00045
00046
00047
00048
00049 #ifndef UART_INTERRUPT_HANDLER
00050 #define UART_INTERRUPT_HANDLER SIGNAL
00051 #endif
00052
00053
00054 #ifdef UCSRB
00055 #define UCR UCSRB
00056 #endif
00057
00058 #if defined(UBRR) && !defined(UBRRL)
00059 #define UBRRL UBRR
00060 #endif
00061
00062
00063 #if defined(__AVR_ATmega128__)
00064 #define UDR UDR0
00065 #define UCR UCSR0B
00066 #define UBRRL UBRR0L
00067 #define UBRRH UBRR0H
00068 #define SIG_UART_TRANS SIG_UART0_TRANS
00069 #define SIG_UART_RECV SIG_UART0_RECV
00070 #define SIG_UART_DATA SIG_UART0_DATA
00071 #endif
00072 #if defined(__AVR_ATmega161__)
00073 #define UDR UDR0
00074 #define UCR UCSR0B
00075 #define UBRRL UBRR0
00076 #define SIG_UART_TRANS SIG_UART0_TRANS
00077 #define SIG_UART_RECV SIG_UART0_RECV
00078 #define SIG_UART_DATA SIG_UART0_DATA
00079 #endif
00080
00081
00082
00083
00084
00085 void uartInitBuffers(void);
00086
00087
00088 void uartInit(void);
00089
00090
00091 void uartSetRxHandler(void (*rx_func)(unsigned char c));
00092
00093
00094 void uartSetBaudRate(u32 baudrate);
00095
00096
00097 cBuffer* uartGetRxBuffer(void);
00098
00099
00100 cBuffer* uartGetTxBuffer(void);
00101
00102
00103 void uartSendByte(u08 data);
00104
00105
00106
00107
00108
00109
00110
00111 u08 uartReceiveByte(u08* data);
00112
00113
00114 u08 uartReceiveBufferIsEmpty(void);
00115
00116
00117 void uartFlushReceiveBuffer(void);
00118
00119
00120 void uartAddToTxBuffer(u08 data);
00121
00122
00123 void uartSendTxBuffer(void);
00124
00125
00126 u08 uartSendBuffer(char *buffer, u16 nBytes);
00127
00128 #endif
00129
00130