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 #include <cfg/os.h>
00072 #include <cfg/clock.h>
00073 #include <cfg/arch.h>
00074 #include <cfg/uart.h>
00075
00076 #include <string.h>
00077
00078 #include <sys/atom.h>
00079 #include <sys/event.h>
00080 #include <sys/timer.h>
00081
00082 #include <dev/irqreg.h>
00083 #include <dev/usartat91.h>
00084
00085 #ifndef NUT_CPU_FREQ
00086 #ifdef NUT_PLL_CPUCLK
00087 #include <dev/cy2239x.h>
00088 #else
00089 #define NUT_CPU_FREQ 73728000UL
00090 #endif
00091 #endif
00092
00093
00094
00095
00096 static uint32_t At91UsartGetSpeed(void);
00097 static int At91UsartSetSpeed(uint32_t rate);
00098 static uint8_t At91UsartGetDataBits(void);
00099 static int At91UsartSetDataBits(uint8_t bits);
00100 static uint8_t At91UsartGetParity(void);
00101 static int At91UsartSetParity(uint8_t mode);
00102 static uint8_t At91UsartGetStopBits(void);
00103 static int At91UsartSetStopBits(uint8_t bits);
00104 static uint32_t At91UsartGetFlowControl(void);
00105 static int At91UsartSetFlowControl(uint32_t flags);
00106 static uint32_t At91UsartGetStatus(void);
00107 static int At91UsartSetStatus(uint32_t flags);
00108 static uint8_t At91UsartGetClockMode(void);
00109 static int At91UsartSetClockMode(uint8_t mode);
00110 static void At91UsartTxStart(void);
00111 static void At91UsartRxStart(void);
00112 static int At91UsartInit(void);
00113 static int At91UsartDeinit(void);
00114
00119
00123 static USARTDCB dcb_usart0 = {
00124 0,
00125 0,
00126 0,
00127 0,
00128 {0, 0, 0, 0, 0, 0, 0, 0},
00129 {0, 0, 0, 0, 0, 0, 0, 0},
00130 0,
00131 At91UsartInit,
00132 At91UsartDeinit,
00133 At91UsartTxStart,
00134 At91UsartRxStart,
00135 At91UsartSetFlowControl,
00136 At91UsartGetFlowControl,
00137 At91UsartSetSpeed,
00138 At91UsartGetSpeed,
00139 At91UsartSetDataBits,
00140 At91UsartGetDataBits,
00141 At91UsartSetParity,
00142 At91UsartGetParity,
00143 At91UsartSetStopBits,
00144 At91UsartGetStopBits,
00145 At91UsartSetStatus,
00146 At91UsartGetStatus,
00147 At91UsartSetClockMode,
00148 At91UsartGetClockMode,
00149 };
00150
00166 NUTDEVICE devUsartAt910 = {
00167 0,
00168 {'u', 'a', 'r', 't', '0', 0, 0, 0, 0},
00169 IFTYP_CHAR,
00170 0,
00171 0,
00172 0,
00173 &dcb_usart0,
00174 UsartInit,
00175 UsartIOCtl,
00176 UsartRead,
00177 UsartWrite,
00178 UsartOpen,
00179 UsartClose,
00180 UsartSize
00181 };
00182
00186
00187
00188
00189
00190 #if defined(MCU_AT91SAM9260) || defined(MCU_AT91SAM9XE)
00191 #if defined(UART0_MODEM_CONTROL)
00192 #define US_PIOB_PINS_A ( \
00193 _BV(PB4_TXD0_A) | _BV(PB5_RXD0_A) | _BV(PB27_CTS0_A) | _BV(PB26_RTS0_A) \
00194 | _BV(PB25_RI0_A) | _BV(PB22_DSR0_A) | _BV(PB23_DCD0_A) | _BV(PB24_DTR0_A) \
00195 )
00196 #elif defined(UART0_HARDWARE_HANDSHAKE)
00197 #define US_PIOB_PINS_A ( \
00198 _BV(PB4_TXD0_A) | _BV(PB5_RXD0_A) | _BV(PB27_CTS0_A) | _BV(PB26_RTS0_A) \
00199 )
00200 #else
00201 #define US_PIOB_PINS_A (_BV(PB4_TXD0_A) | _BV(PB5_RXD0_A))
00202 #endif
00203 #define US_PIOB_PINS US_PIOB_PINS_A
00204 #endif
00205
00206
00207
00208
00209 #if defined(MCU_AT91SAM7S) || defined(MCU_AT91SAM7SE)
00210 #if defined(UART0_HARDWARE_HANDSHAKE)
00211 #define US_PIOA_PINS_A ( \
00212 _BV(PA6_TXD0_A) | _BV(PA5_RXD0_A) | _BV(PA8_CTS0_A) | _BV(PA7_RTS0_A) \
00213 )
00214 #else
00215 #define US_PIOA_PINS_A (_BV(PA5_RXD0_A) | _BV(PA6_TXD0_A))
00216 #endif
00217 #define US_PIOA_PINS US_PIOA_PINS_A
00218 #endif
00219
00220
00221
00222
00223 #if defined(MCU_AT91SAM7X)
00224 #if defined(UART0_HARDWARE_HANDSHAKE)
00225 #define US_PIOA_PINS_A ( \
00226 _BV(PA1_TXD0_A) | _BV(PA0_RXD0_A) | _BV(PA4_CTS0_A) | _BV(PA3_RTS0_A) \
00227 )
00228 #else
00229 #define US_PIOA_PINS_A (_BV(PA1_TXD0_A) | _BV(PA0_RXD0_A))
00230 #endif
00231 #define US_PIOA_PINS US_PIOA_PINS_A
00232 #endif
00233
00234
00235
00236
00237 #if defined(MCU_AT91R40008)
00238 #define US_PIO_PINS (_BV(P15_RXD0) | _BV(P14_TXD0))
00239 #endif
00240
00241
00242
00243
00244
00245 #ifdef AT91_UART0_RS485
00246 #if defined(MCU_AT91SAM7X256)
00247 #undef US_PIOA_PINS_A
00248 #define US_PIOA_PINS_A (_BV(PA0_RXD0_A) | _BV(PA1_TXD0_A) | _BV(PA3_RTS0_A))
00249 #undef AT91_UART_RS485_MODE
00250 #define AT91_UART_RS485_MODE
00251 #undef US_PIOA_PINS
00252 #define US_PIOA_PINS US_PIOA_PINS_A
00253 #endif
00254 #endif
00255
00256
00257 #define USARTn_BASE USART0_BASE
00258 #define US_ID US0_ID
00259 #define SIG_UART sig_UART0
00260 #define dcb_usart dcb_usart0
00261
00262 #include "usartat91.c"