mos/com/include/uart.h

Go to the documentation of this file.
00001 //  This file is part of MOS, the MANTIS Operating System
00002 //  See http://mantis.cs.colorado.edu/
00003 //
00004 //  Copyright (c) 2002 - 2007 University of Colorado, Boulder
00005 //
00006 //   All rights reserved.
00007 //
00008 //   Redistribution and use in source and binary forms, with or without
00009 //   modification, are permitted provided that the following conditions are
00010 //   met:
00011 //
00012 //       * Redistributions of source code must retain the above copyright
00013 //         notice, this list of conditions and the following disclaimer.
00014 //       * Redistributions in binary form must reproduce the above
00015 //         copyright notice, this list of conditions and the following
00016 //         disclaimer in the documentation and/or other materials provided
00017 //         with the distribution. 
00018 //       * Neither the name of the MANTIS Project nor the names of its
00019 //         contributors may be used to endorse or promote products derived
00020 //         from this software without specific prior written permission.
00021 //
00022 //   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023 //   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024 //   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00025 //   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00026 //   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027 //   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028 //   BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029 //   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030 //   CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 //   LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032 //   ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033 //   POSSIBILITY OF SUCH DAMAGE.
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 // U2X = 1 for these values
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 //#define NEED_RAW_MODE
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

Generated on Mon Nov 23 06:25:59 2009 for MANTIS by  doxygen 1.4.6