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
00042 #ifndef _UART_H_
00043 #define _UART_H_
00044
00045 #ifndef SCONS
00046 #include "mos.h"
00047 #endif
00048
00049 #ifndef PLATFORM_LINUX
00050
00052 #define PARITY 1
00053
00054 #define UART_IOCTL_BAUD_RATE 0
00055 #define UART_IOCTL_COM_MODE0 1
00056 #define UART_IOCTL_RAW_MODE0 2
00057 #define UART_IOCTL_COM_MODE1 3
00058 #define UART_IOCTL_RAW_MODE1 4
00059
00060 #define UART0 0
00061 #define UART1 1
00062
00064 #ifdef CLOCK_SPEED_1_0
00065 #define B2400 25
00066 #define B4800 12
00067 #define B9600 6
00068 #define B14400 3
00069 #define B19200 2
00070 #define B28800 1
00071 #define B38400 1
00072 #define B57600 0
00073 #define B76800 0
00074 #define B115200 0
00075 #endif
00076
00077 #ifdef CLOCK_SPEED_1_84
00078 #define B2400 47
00079 #define B4800 23
00080 #define B9600 11
00081 #define B14400 7
00082 #define B19200 5
00083 #define B28800 3
00084 #define B38400 2
00085 #define B57600 1
00086 #define B76800 1
00087 #define B115200 0
00088 #endif
00089
00090 #ifdef CLOCK_SPEED_2_0
00091 #define B2400 51
00092 #define B4800 25
00093 #define B9600 12
00094 #define B14400 8
00095 #define B19200 6
00096 #define B28800 3
00097 #define B38400 2
00098 #define B57600 1
00099 #define B76800 1
00100 #define B115200 0
00101 #endif
00102
00103 #ifdef CLOCK_SPEED_3_68
00104 #define B2400 95
00105 #define B4800 47
00106 #define B9600 23
00107 #define B14400 15
00108 #define B19200 11
00109 #define B28800 7
00110 #define B38400 5
00111 #define B57600 3
00112 #define B76800 2
00113 #define B115200 1
00114 #endif
00115
00116
00117 #ifdef CLOCK_SPEED_4_0
00118 #define B2400 207
00119 #define B4800 103
00120 #define B9600 51
00121 #define B14400 34
00122 #define B19200 25
00123 #define B28800 16
00124 #define B38400 12
00125 #define B57600 8
00126 #define B76800 6
00127 #define B115200 3
00128 #endif
00129
00130 #ifdef CLOCK_SPEED_7_37
00131 #define B2400 191
00132 #define B4800 95
00133 #define B9600 47
00134 #define B14400 31
00135 #define B19200 23
00136 #define B28800 15
00137 #define B38400 11
00138 #define B57600 7
00139 #define B76800 5
00140 #define B115200 3
00141 #define B230400 1
00142 #endif
00143
00144 #ifdef CLOCK_SPEED_8_0
00145 #define B2400 207
00146 #define B4800 103
00147 #define B9600 51
00148 #define B14400 34
00149 #define B19200 25
00150 #define B28800 16
00151 #define B38400 12
00152 #define B57600 8
00153 #define B76800 6
00154 #define B115200 3
00155 #define B230400 1
00156 #define B250000 1
00157 #endif
00158
00159 #ifdef CLOCK_SPEED_11_05
00160 #define B2400 287
00161 #define B4800 143
00162 #define B9600 71
00163 #define B14400 47
00164 #define B19200 35
00165 #define B28800 23
00166 #define B38400 17
00167 #define B57600 11
00168 #define B76800 8
00169 #define B115200 5
00170 #define B230400 2
00171 #define B250000 2
00172 #endif
00173
00174 #ifdef CLOCK_SPEED_14_74
00175 #define B2400 383
00176 #define B4800 191
00177 #define B9600 95
00178 #define B14400 63
00179 #define B19200 47
00180 #define B28800 31
00181 #define B38400 23
00182 #define B57600 15
00183 #define B76800 11
00184 #define B115200 7
00185 #define B230400 3
00186 #define B250000 3
00187 #define B500000 1
00188 #endif
00189
00190 #ifdef CLOCK_SPEED_16_0
00191 #define B2400 416
00192 #define B4800 207
00193 #define B9600 103
00194 #define B14400 68
00195 #define B19200 51
00196 #define B28800 34
00197 #define B38400 25
00198 #define B57600 16
00199 #define B76800 12
00200 #define B115200 8
00201 #define B230400 3
00202 #define B250000 3
00203 #define B500000 1
00204 #endif
00205
00206 #ifdef CLOCK_SPEED_18_43
00207 #define B2400 479
00208 #define B4800 239
00209 #define B9600 119
00210 #define B14400 79
00211 #define B19200 59
00212 #define B28800 39
00213 #define B38400 29
00214 #define B57600 19
00215 #define B76800 14
00216 #define B115200 9
00217 #define B230400 4
00218 #define B250000 4
00219 #endif
00220
00221 #ifdef CLOCK_SPEED_20_0
00222 #define B2400 520
00223 #define B4800 259
00224 #define B9600 129
00225 #define B14400 86
00226 #define B19200 64
00227 #define B28800 42
00228 #define B38400 32
00229 #define B57600 21
00230 #define B76800 15
00231 #define B115200 10
00232 #define B230400 4
00233 #define B250000 4
00234 #endif
00235
00236 #else
00237 #error "Clock Speed Undefined"
00238 #endif
00239
00240
00241
00243 void uart_init(void);
00244
00245 #ifdef NEED_RAW_MODE
00246
00247 #define uart_read(uart_num, buf, count) uart_read##uart_num(buf, count)
00248 #define uart_write(uart_num, buf, count) uart_write##uart_num(buf, count)
00249 uint8_t uart_read0(uint8_t *buf, uint8_t count);
00250 uint8_t uart_write0(uint8_t *buf, uint8_t count);
00251 uint8_t uart_read1(uint8_t *buf, uint8_t count);
00252 uint8_t uart_write1(uint8_t *buf, uint8_t count);
00253
00254 #endif
00255
00256 #if defined(USB_SERIAL)
00257 #define DEFAULT_BAUD_RATE B115200
00258 #elif defined(PLATFORM_MICA2) || defined(PLATFORM_MICAZ) || defined(PLATFORM_MICROBLAZE)
00259 #define DEFAULT_BAUD_RATE B57600
00260 #elif defined(PLATFORM_TELOSB)
00261 #define DEFAULT_BAUD_RATE 57600
00262 #elif defined(PLATFORM_MICA2DOT) || defined(PLATFORM_AVRDEV)
00263 #define DEFAULT_BAUD_RATE B38400
00264 #else
00265 #error "Undefined baud rate for this platform"
00266 #endif
00267
00268
00269 #endif