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 #include <cfg/os.h>
00060 #include <cfg/clock.h>
00061 #include <cfg/arch.h>
00062
00063 #include <string.h>
00064
00065 #include <sys/atom.h>
00066 #include <sys/event.h>
00067 #include <sys/timer.h>
00068
00069 #include <dev/irqreg.h>
00070 #include <dev/usartat91.h>
00071
00072 #ifndef NUT_CPU_FREQ
00073 #ifdef NUT_PLL_CPUCLK
00074 #include <dev/cy2239x.h>
00075 #else
00076 #define NUT_CPU_FREQ 73728000UL
00077 #endif
00078 #endif
00079
00080
00081
00082
00083 static u_long At91UsartGetSpeed(void);
00084 static int At91UsartSetSpeed(u_long rate);
00085 static u_char At91UsartGetDataBits(void);
00086 static int At91UsartSetDataBits(u_char bits);
00087 static u_char At91UsartGetParity(void);
00088 static int At91UsartSetParity(u_char mode);
00089 static u_char At91UsartGetStopBits(void);
00090 static int At91UsartSetStopBits(u_char bits);
00091 static u_long At91UsartGetFlowControl(void);
00092 static int At91UsartSetFlowControl(u_long flags);
00093 static u_long At91UsartGetStatus(void);
00094 static int At91UsartSetStatus(u_long flags);
00095 static u_char At91UsartGetClockMode(void);
00096 static int At91UsartSetClockMode(u_char mode);
00097 static void At91UsartTxStart(void);
00098 static void At91UsartRxStart(void);
00099 static int At91UsartInit(void);
00100 static int At91UsartDeinit(void);
00101
00106
00110 static USARTDCB dcb_usart0 = {
00111 0,
00112 0,
00113 0,
00114 0,
00115 {0, 0, 0, 0, 0, 0, 0, 0},
00116 {0, 0, 0, 0, 0, 0, 0, 0},
00117 0,
00118 At91UsartInit,
00119 At91UsartDeinit,
00120 At91UsartTxStart,
00121 At91UsartRxStart,
00122 At91UsartSetFlowControl,
00123 At91UsartGetFlowControl,
00124 At91UsartSetSpeed,
00125 At91UsartGetSpeed,
00126 At91UsartSetDataBits,
00127 At91UsartGetDataBits,
00128 At91UsartSetParity,
00129 At91UsartGetParity,
00130 At91UsartSetStopBits,
00131 At91UsartGetStopBits,
00132 At91UsartSetStatus,
00133 At91UsartGetStatus,
00134 At91UsartSetClockMode,
00135 At91UsartGetClockMode,
00136 };
00137
00153 NUTDEVICE devUsartAt910 = {
00154 0,
00155 {'u', 'a', 'r', 't', '0', 0, 0, 0, 0},
00156 IFTYP_CHAR,
00157 0,
00158 0,
00159 0,
00160 &dcb_usart0,
00161 UsartInit,
00162 UsartIOCtl,
00163 UsartRead,
00164 UsartWrite,
00165 UsartOpen,
00166 UsartClose,
00167 UsartSize
00168 };
00169
00173
00174 #if defined(MCU_AT91SAM9260) || defined(MCU_AT91SAM9XE512)
00175 #define US_PIOB_PINS_A (_BV(PB4_TXD0_A) | _BV(PB5_RXD0_A))
00176 #define US_PIOB_PINS US_PIOB_PINS_A
00177 #endif
00178
00179 #if defined(MCU_AT91SAM7X256)
00180 #ifdef AT91_UART0_RS485
00181 #define US_PIOA_PINS_A (_BV(PA0_RXD0_A) | _BV(PA1_TXD0_A) | _BV(PA3_RTS0_A))
00182 #define AT91_UART_RS485_MODE
00183 #else
00184 #define US_PIOA_PINS_A (_BV(PA0_RXD0_A) | _BV(PA1_TXD0_A))
00185 #undef AT91_UART_RS485_MODE
00186 #endif
00187 #define US_PIOA_PINS US_PIOA_PINS_A
00188 #endif
00189
00190 #if defined(MCU_AT91SAM7S256) || defined(MCU_AT91SAM7SE512)
00191 #define US_PIOA_PINS_A (_BV(PA5_RXD0_A) | _BV(PA6_TXD0_A))
00192 #define US_PIO_PINS US_PIOA_PINS_A
00193 #endif
00194
00195 #if defined(MCU_AT91R40008)
00196 #define US_PIO_PINS (_BV(P15_RXD0) | _BV(P14_TXD0))
00197 #endif
00198
00199 #define USARTn_BASE USART0_BASE
00200 #define US_ID US0_ID
00201 #define SIG_UART sig_UART0
00202 #define dcb_usart dcb_usart0
00203
00204 #include "usartat91.c"