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_usart0 = {
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 devUsartAt910 = {
00169 0,
00170 {'u', 'a', 'r', 't', '0', 0, 0, 0, 0},
00171 IFTYP_CHAR,
00172 0,
00173 0,
00174 0,
00175 &dcb_usart0,
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(UART0_MODEM_CONTROL)
00194 #define US_PIOB_PINS_A ( \
00195 _BV(PB4_TXD0_A) | _BV(PB5_RXD0_A) | _BV(PB27_CTS0_A) | _BV(PB26_RTS0_A) \
00196 | _BV(PB25_RI0_A) | _BV(PB22_DSR0_A) | _BV(PB23_DCD0_A) | _BV(PB24_DTR0_A) \
00197 )
00198 #elif defined(UART0_HARDWARE_HANDSHAKE)
00199 #define US_PIOB_PINS_A ( \
00200 _BV(PB4_TXD0_A) | _BV(PB5_RXD0_A) | _BV(PB27_CTS0_A) | _BV(PB26_RTS0_A) \
00201 )
00202 #else
00203 #define US_PIOB_PINS_A (_BV(PB4_TXD0_A) | _BV(PB5_RXD0_A))
00204 #endif
00205 #define US_PIOB_PINS US_PIOB_PINS_A
00206 #endif
00207
00208
00209
00210
00211 #if defined(MCU_AT91SAM7S) || defined(MCU_AT91SAM7SE)
00212 #if defined(UART0_HARDWARE_HANDSHAKE)
00213 #define US_PIOA_PINS_A ( \
00214 _BV(PA6_TXD0_A) | _BV(PA5_RXD0_A) | _BV(PA8_CTS0_A) | _BV(PA7_RTS0_A) \
00215 )
00216 #else
00217 #define US_PIOA_PINS_A (_BV(PA5_RXD0_A) | _BV(PA6_TXD0_A))
00218 #endif
00219 #define US_PIOA_PINS US_PIOA_PINS_A
00220 #endif
00221
00222
00223
00224
00225 #if defined(MCU_AT91SAM7X)
00226 #if defined(UART0_HARDWARE_HANDSHAKE)
00227 #define US_PIOA_PINS_A ( \
00228 _BV(PA1_TXD0_A) | _BV(PA0_RXD0_A) | _BV(PA4_CTS0_A) | _BV(PA3_RTS0_A) \
00229 )
00230 #else
00231 #define US_PIOA_PINS_A (_BV(PA1_TXD0_A) | _BV(PA0_RXD0_A))
00232 #endif
00233 #define US_PIOA_PINS US_PIOA_PINS_A
00234 #endif
00235
00236
00237
00238
00239 #if defined(MCU_AT91R40008)
00240 #define US_PIO_PINS (_BV(P15_RXD0) | _BV(P14_TXD0))
00241 #endif
00242
00243
00244
00245
00246
00247 #ifdef AT91_UART0_RS485
00248 #if defined(MCU_AT91SAM7X256)
00249 #undef US_PIOA_PINS_A
00250 #define US_PIOA_PINS_A (_BV(PA0_RXD0_A) | _BV(PA1_TXD0_A) | _BV(PA3_RTS0_A))
00251 #undef AT91_UART_RS485_MODE
00252 #define AT91_UART_RS485_MODE
00253 #undef US_PIOA_PINS
00254 #define US_PIOA_PINS US_PIOA_PINS_A
00255 #endif
00256 #endif
00257
00258
00259 #define USARTn_BASE USART0_BASE
00260 #define US_ID US0_ID
00261 #define SIG_UART sig_UART0
00262 #define dcb_usart dcb_usart0
00263
00264 #include "usartat91.c"