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 #include <cfg/os.h>
00041 #include <cfg/clock.h>
00042 #include <cfg/arch.h>
00043 #include <cfg/uart.h>
00044 #include <cfg/arch/gpio.h>
00045
00046 #include <string.h>
00047
00048 #include <sys/atom.h>
00049 #include <sys/event.h>
00050 #include <sys/timer.h>
00051
00052 #include <dev/irqreg.h>
00053 #include <dev/usartat91.h>
00054
00055 #ifndef NUT_CPU_FREQ
00056 #ifdef NUT_PLL_CPUCLK
00057 #include <dev/cy2239x.h>
00058 #else
00059 #define NUT_CPU_FREQ 73728000UL
00060 #endif
00061 #endif
00062
00063
00064
00065
00066 static uint32_t At91UsartGetSpeed(void);
00067 static int At91UsartSetSpeed(uint32_t rate);
00068 static uint8_t At91UsartGetDataBits(void);
00069 static int At91UsartSetDataBits(uint8_t bits);
00070 static uint8_t At91UsartGetParity(void);
00071 static int At91UsartSetParity(uint8_t mode);
00072 static uint8_t At91UsartGetStopBits(void);
00073 static int At91UsartSetStopBits(uint8_t bits);
00074 static uint32_t At91UsartGetFlowControl(void);
00075 static int At91UsartSetFlowControl(uint32_t flags);
00076 static uint32_t At91UsartGetStatus(void);
00077 static int At91UsartSetStatus(uint32_t flags);
00078 static uint8_t At91UsartGetClockMode(void);
00079 static int At91UsartSetClockMode(uint8_t mode);
00080 static void At91UsartTxStart(void);
00081 static void At91UsartRxStart(void);
00082 static int At91UsartInit(void);
00083 static int At91UsartDeinit(void);
00084
00089
00093 static USARTDCB dcb_usart0 = {
00094 0,
00095 0,
00096 0,
00097 0,
00098 {0, 0, 0, 0, 0, 0, 0, 0},
00099 {0, 0, 0, 0, 0, 0, 0, 0},
00100 0,
00101 At91UsartInit,
00102 At91UsartDeinit,
00103 At91UsartTxStart,
00104 At91UsartRxStart,
00105 At91UsartSetFlowControl,
00106 At91UsartGetFlowControl,
00107 At91UsartSetSpeed,
00108 At91UsartGetSpeed,
00109 At91UsartSetDataBits,
00110 At91UsartGetDataBits,
00111 At91UsartSetParity,
00112 At91UsartGetParity,
00113 At91UsartSetStopBits,
00114 At91UsartGetStopBits,
00115 At91UsartSetStatus,
00116 At91UsartGetStatus,
00117 At91UsartSetClockMode,
00118 At91UsartGetClockMode,
00119 };
00120
00136 NUTDEVICE devUsartAt910 = {
00137 0,
00138 {'u', 'a', 'r', 't', '0', 0, 0, 0, 0},
00139 IFTYP_CHAR,
00140 0,
00141 0,
00142 0,
00143 &dcb_usart0,
00144 UsartInit,
00145 UsartIOCtl,
00146 UsartRead,
00147 UsartWrite,
00148 UsartOpen,
00149 UsartClose,
00150 UsartSize
00151 };
00152
00156
00157
00158 #if defined(UART0_MODEM_CONTROL)
00159 #define UART_MODEM_CONTROL
00160 #define UART_HARDWARE_HANDSHAKE
00161 #elif defined(UART0_HARDWARE_HANDSHAKE)
00162 #define UART_HARDWARE_HANDSHAKE
00163 #endif
00164
00165
00166
00167
00168 #if defined(MCU_AT91SAM9260) || defined(MCU_AT91SAM9XE)
00169
00170 #define UART_RXTX_PINS (_BV(PB5_RXD0_A) | _BV(PB4_TXD0_A))
00171 #define UART_HDX_PIN _BV(PB26_RTS0_A)
00172 #define UART_RTS_PIN _BV(PB26_RTS0_A)
00173 #define UART_CTS_PIN _BV(PB27_CTS0_A)
00174 #define UART_MODEM_PINS (_BV(PB24_DTR0_A) | _BV(PB22_DSR0_A) | _BV(PB23_DCD0_A) | _BV(PB25_RI0_A))
00175
00176 #define UART_RXTX_PINS_ENABLE() outr(PIOB_ASR, UART_RXTX_PINS); \
00177 outr(PIOB_PDR, UART_RXTX_PINS)
00178
00179 #if defined(UART_HARDWARE_HANDSHAKE)
00180 #define UART_HDX_PIN_ENABLE() outr(PIOB_ASR, UART_HDX_PIN); \
00181 outr(PIOB_PDR, UART_HDX_PIN)
00182 #define UART_RTS_PIN_ENABLE() outr(PIOB_ASR, UART_RTS_PIN); \
00183 outr(PIOB_PDR, UART_RTS_PIN)
00184 #define UART_CTS_PIN_ENABLE() outr(PIOB_ASR, UART_CTS_PIN); \
00185 outr(PIOB_PDR, UART_CTS_PIN)
00186 #endif
00187
00188 #if defined(UART_MODEM_CONTROL)
00189 #define UART_MODEM_PINS_ENABLE() outr(PIOB_ASR, UART_MODEM_PINS); \
00190 outr(PIOB_PDR, UART_MODEM_PINS)
00191 #endif
00192
00193
00194
00195
00196 #elif defined(MCU_AT91SAM7S) || defined(MCU_AT91SAM7SE)
00197
00198 #define UART_RXTX_PINS (_BV(PA5_RXD0_A) | _BV(PA6_TXD0_A))
00199 #define UART_HDX_PIN _BV(PA7_RTS0_A)
00200 #define UART_RTS_PIN _BV(PA7_RTS0_A)
00201 #define UART_CTS_PIN _BV(PA8_CTS0_A)
00202
00203 #define UART_RXTX_PINS_ENABLE() outr(PIOA_ASR, UART_RXTX_PINS); \
00204 outr(PIOA_PDR, UART_RXTX_PINS)
00205
00206 #if defined(UART_HARDWARE_HANDSHAKE)
00207 #define UART_HDX_PIN_ENABLE() outr(PIOA_ASR, UART_HDX_PIN); \
00208 outr(PIOA_PDR, UART_HDX_PIN)
00209 #define UART_RTS_PIN_ENABLE() outr(PIOA_ASR, UART_RTS_PIN); \
00210 outr(PIOA_PDR, UART_RTS_PIN)
00211 #define UART_CTS_PIN_ENABLE() outr(PIOA_ASR, UART_CTS_PIN); \
00212 outr(PIOA_PDR, UART_CTS_PIN)
00213 #endif
00214
00215
00216
00217
00218 #elif defined(MCU_AT91SAM7X)
00219
00220 #define UART_RXTX_PINS (_BV(PA0_RXD0_A) | _BV(PA1_TXD0_A))
00221 #define UART_HDX_PIN _BV(PA3_RTS0_A)
00222 #define UART_RTS_PIN _BV(PA3_RTS0_A)
00223 #define UART_CTS_PIN _BV(PA4_CTS0_A)
00224
00225 #define UART_RXTX_PINS_ENABLE() outr(PIOA_ASR, UART_RXTX_PINS); \
00226 outr(PIOA_PDR, UART_RXTX_PINS)
00227
00228 #if defined(UART_HARDWARE_HANDSHAKE)
00229 #define UART_HDX_PIN_ENABLE() outr(PIOA_ASR, UART_HDX_PIN); \
00230 outr(PIOA_PDR, UART_HDX_PIN)
00231 #define UART_RTS_PIN_ENABLE() outr(PIOA_ASR, UART_RTS_PIN); \
00232 outr(PIOA_PDR, UART_RTS_PIN)
00233 #define UART_CTS_PIN_ENABLE() outr(PIOA_ASR, UART_CTS_PIN); \
00234 outr(PIOA_PDR, UART_CTS_PIN)
00235 #endif
00236
00237
00238
00239
00240 #elif defined(MCU_AT91R40008)
00241
00242 #define UART_RXTX_PINS (_BV(P15_RXD0) | _BV(P14_TXD0))
00243
00244 #define UART_RXTX_PINS_ENABLE() outr(PIO_PDR, UART_RXTX_PINS)
00245
00246
00247
00248
00249
00250
00251
00252
00253 #endif
00254
00255
00256
00257
00258 #if defined(ETHERNUT3)
00259 #define UART_USES_NPL 1
00260 #endif
00261
00262
00263
00264
00265
00266 #if defined(UART0_HDX_BIT)
00267 #define UART_HDX_BIT UART0_HDX_BIT
00268 #endif
00269 #if defined(UART0_HDX_PIO_ID)
00270 #define UART_HDX_PIO_ID UART0_HDX_PIO_ID
00271 #endif
00272
00273 #if defined(UART0_RTS_BIT)
00274 #define UART_RTS_BIT UART0_RTS_BIT
00275 #endif
00276 #if defined(UART0_RTS_PIO_ID)
00277 #define UART_RTS_PIO_ID UART0_RTS_PIO_ID
00278 #endif
00279
00280 #if defined(UART0_CTS_BIT)
00281 #define UART_CTS_BIT UART0_CTS_BIT
00282 #endif
00283 #if defined(UART0_CTS_PIO_ID)
00284 #define UART_CTS_PIO_ID UART0_CTS_PIO_ID
00285 #endif
00286 #if defined(UART0_CTS_SIGNAL)
00287 #define UART_CTS_SIGNAL UART0_CTS_SIGNAL
00288 #endif
00289
00290 #if defined(UART1_INIT_BAUDRATE)
00291 #define UART_INIT_BAUDRATE UART1_INIT_BAUDRATE
00292 #endif
00293
00294 #define USARTn_BASE USART0_BASE
00295 #define US_ID US0_ID
00296 #define SIG_UART sig_UART0
00297 #define dcb_usart dcb_usart0
00298
00299 #include "usartat91.c"