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 <cfg/arch.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_usart0 = {
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 devUsartAt910 = {
00160 0,
00161 {'u', 'a', 'r', 't', '0', 0, 0, 0, 0},
00162 IFTYP_CHAR,
00163 0,
00164 0,
00165 0,
00166 &dcb_usart0,
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(UART0_MODEM_CONTROL)
00185 #define US_PIOB_PINS_A ( \
00186 _BV(PB4_TXD0_A) | _BV(PB5_RXD0_A) | _BV(PB27_CTS0_A) | _BV(PB26_RTS0_A) \
00187 | _BV(PB25_RI0_A) | _BV(PB22_DSR0_A) | _BV(PB23_DCD0_A) | _BV(PB24_DTR0_A) \
00188 )
00189 #elif defined(UART0_HARDWARE_HANDSHAKE)
00190 #define US_PIOB_PINS_A ( \
00191 _BV(PB4_TXD0_A) | _BV(PB5_RXD0_A) | _BV(PB27_CTS0_A) | _BV(PB26_RTS0_A) \
00192 )
00193 #else
00194 #define US_PIOB_PINS_A (_BV(PB4_TXD0_A) | _BV(PB5_RXD0_A))
00195 #endif
00196 #define US_PIOB_PINS US_PIOB_PINS_A
00197 #endif
00198
00199
00200
00201
00202 #if defined(MCU_AT91SAM7S) || defined(MCU_AT91SAM7SE)
00203 #if defined(UART0_HARDWARE_HANDSHAKE)
00204 #define US_PIOA_PINS_A ( \
00205 _BV(PA6_TXD0_A) | _BV(PA5_RXD0_A) | _BV(PA8_CTS0_A) | _BV(PA7_RTS0_A) \
00206 )
00207 #else
00208 #define US_PIOA_PINS_A (_BV(PA5_RXD0_A) | _BV(PA6_TXD0_A))
00209 #endif
00210 #define US_PIOA_PINS US_PIOA_PINS_A
00211 #endif
00212
00213
00214
00215
00216 #if defined(MCU_AT91SAM7X)
00217 #if defined(UART0_HARDWARE_HANDSHAKE)
00218 #define US_PIOA_PINS_A ( \
00219 _BV(PA1_TXD0_A) | _BV(PA0_RXD0_A) | _BV(PA4_CTS0_A) | _BV(PA3_RTS0_A) \
00220 )
00221 #else
00222 #define US_PIOA_PINS_A (_BV(PA1_TXD0_A) | _BV(PA0_RXD0_A))
00223 #endif
00224 #define US_PIOA_PINS US_PIOA_PINS_A
00225 #endif
00226
00227
00228
00229
00230 #if defined(MCU_AT91R40008)
00231 #define US_PIO_PINS (_BV(P15_RXD0) | _BV(P14_TXD0))
00232 #endif
00233
00234
00235
00236
00237
00238 #ifdef AT91_UART0_RS485
00239 #if defined(MCU_AT91SAM7X256)
00240 #undef US_PIOA_PINS_A
00241 #define US_PIOA_PINS_A (_BV(PA0_RXD0_A) | _BV(PA1_TXD0_A) | _BV(PA3_RTS0_A))
00242 #undef AT91_UART_RS485_MODE
00243 #define AT91_UART_RS485_MODE
00244 #undef US_PIOA_PINS
00245 #define US_PIOA_PINS US_PIOA_PINS_A
00246 #endif
00247 #endif
00248
00249 #define USARTn_BASE USART0_BASE
00250 #define US_ID US0_ID
00251 #define SIG_UART sig_UART0
00252 #define dcb_usart dcb_usart0
00253
00254 #include "usartat91.c"