00001
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 #ifndef _USART_H_
00058 #define _USART_H_
00059
00060 #ifdef __GNUC__
00061 #include <avr32/io.h>
00062 #elif __ICCAVR32__
00063 #include <avr32/ioap7000.h>
00064 #else
00065 #error No known compiler used
00066 #endif
00067
00068
00072 struct usart_options_t
00073 {
00077 unsigned long baudrate;
00078
00082 unsigned char charlength;
00083
00089 unsigned char paritytype;
00090
00097 unsigned short stopbits;
00098
00104 unsigned char channelmode;
00105 };
00106
00107
00108 struct iso7816_options_t
00109 {
00110
00111
00112
00113 unsigned long iso7816_hz;
00114
00115
00116
00117
00118
00119 unsigned short fidi_ratio;
00120
00121
00122
00123
00124
00125
00126
00127
00128 int inhibit_nack;
00129
00130
00131
00132
00133
00134
00135
00136 int dis_suc_nack;
00137
00138
00139
00140
00141 unsigned char max_iterations;
00142
00143
00144
00145
00146
00147
00148 int bit_order;
00149 };
00150
00151
00152
00153
00154
00155
00156
00162 void usart_reset( volatile struct avr32_usart_t * usart );
00163
00164
00173 int usart_init_rs232( volatile struct avr32_usart_t * usart, struct usart_options_t * opt, long cpu_hz );
00174
00175
00176
00177
00178
00179
00180
00181
00192 int usart_send_addr(volatile struct avr32_usart_t * usart, int addr);
00193
00194
00202 int usart_write_char(volatile struct avr32_usart_t * usart, int c);
00203
00204
00211 inline void usart_bw_write_char(volatile struct avr32_usart_t * usart, int c);
00212
00220 int usart_putchar(volatile struct avr32_usart_t * usart, int c);
00221
00233 int usart_read_char(volatile struct avr32_usart_t * usart, int * c);
00234
00240 int usart_getchar(volatile struct avr32_usart_t * usart);
00241
00250 void usart_reset_status(volatile struct avr32_usart_t * usart);
00251
00253 #define USART_SUCCESS 0
00254
00256 #define USART_FAILURE -1
00257
00258 #define USART_INVALID_INPUT 1
00259 #define USART_INVALID_ARGUMENT -1
00260
00261 #define USART_TX_BUSY 2
00262
00263 #define USART_RX_EMPTY 3
00264
00265 #define USART_RX_ERROR 4
00266
00268 #define USART_MODE_FAULT 5
00269
00271 #define USART_ADDR_RECEIVED 1
00272
00274 #define USART_DEFAULT_TIMEOUT 10000
00275
00277 #define USART_EVEN_PARITY 0
00278
00279 #define USART_ODD_PARITY 1
00280
00281 #define USART_SPACE_PARITY 2
00282
00283 #define USART_MARK_PARITY 3
00284
00285 #define USART_NO_PARITY 4
00286
00287 #define USART_MULTIDROP_PARITY 6
00288
00290 #define USART_MODE_NORMAL 0x00
00291
00292 #define USART_MODE_RS485 0x01
00293
00294 #define USART_MODE_HW_HSH 0x02
00295
00296 #define USART_MODE_MODEM 0x03
00297
00298 #define USART_MODE_ISO7816_T0 0x04
00299
00300 #define USART_MODE_ISO7816_T1 0x06
00301
00302 #define USART_MODE_IRDA 0x08
00303
00304 #define USART_MODE_SW_HSH 0x0C
00305
00307 #define USART_NORMAL_CHMODE 0
00308
00309 #define USART_AUTO_ECHO 1
00310
00311 #define USART_LOCAL_LOOPBACK 2
00312
00313 #define USART_REMOTE_LOOPBACK 3
00314
00316 #define USART_1_STOPBIT 0
00317
00318 #define USART_1_5_STOPBITS 1
00319
00320 #define USART_2_STOPBITS 2
00321
00322
00323
00324
00325
00326 #define INT_RXRDY 0
00327 #define INT_TXRDY 1
00328 #define INT_RXBRK 2
00329 #define INT_ENDRX 3
00330 #define INT_ENDTX 4
00331 #define INT_OVRE 5
00332 #define INT_FRAM 6
00333 #define INT_PARE 7
00334 #define INT_TIMEOUT 8
00335 #define INT_TXEMPTY 9
00336 #define INT_ITERATION 10
00337 #define INT_TXBUFE 11
00338 #define INT_RXBUFF 12
00339 #define INT_NACK 13
00340 #define INT_RIIC 16
00341 #define INT_DSRIC 17
00342 #define INT_DCDIC 18
00343 #define INT_CTSIC 19
00344 #define INT_MANE 20
00345
00346 #endif //#ifndef _AVR32_USART_H_