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