00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
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
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 #include <cfg/os.h>
00072 #include <cfg/clock.h>
00073 #include <cfg/arch.h>
00074 #include <cfg/uart.h>
00075
00076 #include <string.h>
00077
00078 #include <sys/atom.h>
00079 #include <sys/event.h>
00080 #include <sys/timer.h>
00081
00082 #include <dev/irqreg.h>
00083 #include <dev/usartat91.h>
00084
00085 #ifndef NUT_CPU_FREQ
00086 #ifdef NUT_PLL_CPUCLK
00087 #include <dev/cy2239x.h>
00088 #else
00089 #define NUT_CPU_FREQ 73728000UL
00090 #endif
00091 #endif
00092
00093
00094
00095
00096 static uint32_t At91UsartGetSpeed(void);
00097 static int At91UsartSetSpeed(uint32_t rate);
00098 static uint8_t At91UsartGetDataBits(void);
00099 static int At91UsartSetDataBits(uint8_t bits);
00100 static uint8_t At91UsartGetParity(void);
00101 static int At91UsartSetParity(uint8_t mode);
00102 static uint8_t At91UsartGetStopBits(void);
00103 static int At91UsartSetStopBits(uint8_t bits);
00104 static uint32_t At91UsartGetFlowControl(void);
00105 static int At91UsartSetFlowControl(uint32_t flags);
00106 static uint32_t At91UsartGetStatus(void);
00107 static int At91UsartSetStatus(uint32_t flags);
00108 static uint8_t At91UsartGetClockMode(void);
00109 static int At91UsartSetClockMode(uint8_t mode);
00110 static void At91UsartTxStart(void);
00111 static void At91UsartRxStart(void);
00112 static int At91UsartInit(void);
00113 static int At91UsartDeinit(void);
00114
00119
00123 static USARTDCB dcb_usart1 = {
00124 0,
00125 0,
00126 0,
00127 0,
00128 {0, 0, 0, 0, 0, 0, 0, 0},
00129 {0, 0, 0, 0, 0, 0, 0, 0},
00130 0,
00131 At91UsartInit,
00132 At91UsartDeinit,
00133 At91UsartTxStart,
00134 At91UsartRxStart,
00135 At91UsartSetFlowControl,
00136 At91UsartGetFlowControl,
00137 At91UsartSetSpeed,
00138 At91UsartGetSpeed,
00139 At91UsartSetDataBits,
00140 At91UsartGetDataBits,
00141 At91UsartSetParity,
00142 At91UsartGetParity,
00143 At91UsartSetStopBits,
00144 At91UsartGetStopBits,
00145 At91UsartSetStatus,
00146 At91UsartGetStatus,
00147 At91UsartSetClockMode,
00148 At91UsartGetClockMode,
00149 };
00150
00166 NUTDEVICE devUsartAt911 = {
00167 0,
00168 {'u', 'a', 'r', 't', '1', 0, 0, 0, 0},
00169 IFTYP_CHAR,
00170 1,
00171 0,
00172 0,
00173 &dcb_usart1,
00174 UsartInit,
00175 UsartIOCtl,
00176 UsartRead,
00177 UsartWrite,
00178 UsartOpen,
00179 UsartClose,
00180 UsartSize
00181 };
00182
00186
00187
00188
00189
00190 #if defined(MCU_AT91SAM9260) || defined(MCU_AT91SAM9XE)
00191 #if defined(UART1_HARDWARE_HANDSHAKE)
00192 #define US_PIOB_PINS_A ( \
00193 _BV(PB6_TXD1_A) | _BV(PB7_RXD1_A) | _BV(PB29_CTS1_A) | _BV(PB28_RTS1_A) \
00194 )
00195 #else
00196 #define US_PIOB_PINS_A (_BV(PB6_TXD1_A) | _BV(PB7_RXD1_A))
00197 #endif
00198 #define US_PIOB_PINS US_PIOB_PINS_A
00199 #endif
00200
00201
00202
00203
00204 #if defined(MCU_AT91SAM7S) || defined(MCU_AT91SAM7SE)
00205 #if defined(UART1_MODEM_CONTROL)
00206 #define US_PIOA_PINS_A ( \
00207 _BV(PA22_TXD1_A) | _BV(PA21_RXD1_A) | _BV(PA25_CTS1_A) | _BV(PA24_RTS1_A) \
00208 )
00209 #define US_PIOB_PINS_A ( \
00210 _BV(PB29_RI1_A) | _BV(PB28_DSR1_A) | _BV(PB26_DCD1_A) | _BV(PB27_DTR1_A) \
00211 )
00212 #define US_PIOB_PINS US_PIOB_PINS_A
00213 #elif defined(UART1_HARDWARE_HANDSHAKE)
00214 #define US_PIOA_PINS_A ( \
00215 _BV(PA22_TXD1_A) | _BV(PA21_RXD1_A) | _BV(PA25_CTS1_A) | _BV(PA24_RTS1_A) \
00216 )
00217 #else
00218 #define US_PIOA_PINS_A (_BV(PA21_RXD1_A) | _BV(PA22_TXD1_A))
00219 #endif
00220 #define US_PIOA_PINS US_PIOA_PINS_A
00221 #endif
00222
00223
00224
00225
00226 #if defined(MCU_AT91SAM7X)
00227 #if defined(UART1_MODEM_CONTROL)
00228 #define US_PIOA_PINS_A ( \
00229 _BV(PA6_TXD1_A) | _BV(PA5_RXD1_A) | _BV(PA9_CTS1_A) | _BV(PA8_RTS1_A) \
00230 )
00231 #define US_PIOB_PINS_B ( \
00232 _BV(PB26_RI1_B) | _BV(PB24_DSR1_B) | _BV(PB23_DCD1_B) | _BV(PB25_DTR1_B) \
00233 )
00234 #define US_PIOB_PINS US_PIOB_PINS_B
00235 #elif defined(UART1_HARDWARE_HANDSHAKE)
00236 #define US_PIOA_PINS_A ( \
00237 _BV(PA6_TXD1_A) | _BV(PA5_RXD1_A) | _BV(PA9_CTS1_A) | _BV(PA8_RTS1_A) \
00238 )
00239 #else
00240 #define US_PIOA_PINS_A (_BV(PA6_TXD1_A) | _BV(PA5_RXD1_A))
00241 #endif
00242 #define US_PIOA_PINS US_PIOA_PINS_A
00243 #endif
00244
00245
00246
00247
00248 #if defined(MCU_AT91R40008)
00249 #define US_PIO_PINS (_BV(P22_RXD1) | _BV(P21_TXD1))
00250 #endif
00251
00252
00253
00254
00255
00256 #ifdef AT91_UART1_RS485
00257 #if defined(MCU_AT91SAM7X256)
00258 #undef US_PIOA_PINS_A
00259 #define US_PIOA_PINS_A (_BV(PA5_RXD1_A) | _BV(PA6_TXD1_A) | _BV(PA8_RTS1_A))
00260 #undef AT91_UART_RS485_MODE
00261 #define AT91_UART_RS485_MODE
00262 #undef US_PIOA_PINS
00263 #define US_PIOA_PINS US_PIOA_PINS_A
00264 #endif
00265 #endif
00266
00267
00268 #define USARTn_BASE USART1_BASE
00269 #define US_ID US1_ID
00270 #define SIG_UART sig_UART1
00271 #define dcb_usart dcb_usart1
00272
00273 #include "usartat91.c"