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