mos/com/include/com.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 
00049 #ifndef _COM_H_
00050 #define _COM_H_
00051 
00052 #include "mos.h"
00053 #include "mutex.h"
00054 #include <stdarg.h>
00055 
00056 #ifdef SCONS
00057 #include "optsconfig.h"
00058 #else
00059 
00060 /* Defines which MAC layer to use */
00061 //#define CC1000_RAW
00062 #define CC1000_CSMA
00063 //#define CC1000_CSMA_ACK
00064 //#define CC1000_TDMA
00065 //#define CC1000_BMAC
00066 
00067 
00068 //ANS: Enable signal strength measurement
00069 
00070 #define GET_RSSI
00071 //#define TS_PACKET
00072 
00073 #endif
00074 
00075 
00076 #ifndef PLATFORM_LINUX
00077 // enable FEC code
00078 //#define RADIO_USE_FEC 1
00079 // send three size bytes instead of one, compute packet size from majority bits
00080 //#define RADIO_REDUNDANT_SIZE
00081 // Send 2 CRC bytes after the data that will be checked after FEC is done
00082 //#define RADIO_EXTRA_CRC
00083 #endif
00084 
00085 #ifdef RADIO_USE_FEC
00086 //#define FEC_SIZE_PARITY_COUNT 2
00087 #define FEC_DATA_PARITY_COUNT 8
00088 #endif
00089 
00090 #ifndef RADIO_EXTRA_CRC
00091 #define COM_DATA_SIZE 90 /* Size of com buffer. */
00092 #else
00093 // Add two more bytes to include a CRC that is checked AFTER error-correction
00094 // FIXME this is an ugly way to do this, since some protocols may use
00095 // this number to determine their payload sizes
00096 #define COM_DATA_SIZE 92
00097 #endif
00098 
00099 #ifdef PLATFORM_LINUX
00100 #define NUM_BUFS 255 /* Size of buffer pool. */
00101 
00102 #else
00103 #define NUM_BUFS 5
00104 #endif
00105 
00106 
00107 #ifdef TS_PACKET
00108 #ifdef ARCH_AVR
00109 #include "realtime.h"
00110 #endif
00111 #endif
00112 
00118 
00124 typedef struct comBuf_t {
00127    struct comBuf_t *next;
00131    uint8_t data[COM_DATA_SIZE];
00132 
00133 #ifdef GET_RSSI
00134 
00137    uint16_t signal;
00138 #endif
00139 #ifdef TS_PACKET
00140 
00142    uint32_t ts;
00145    uint8_t tcnt;
00146 #endif
00147 
00149    uint8_t size;
00150    uint16_t source;
00151 } comBuf;
00152 
00153 
00160 #define IFACE_SERIAL   0 
00161 
00162 #define IFACE_SERIAL2  1
00163 
00164 #define IFACE_RADIO    2 
00165 
00166 #define IFACE_LOOPBACK 3
00167 
00168 #define MAX_IFS        7
00169 
00170 
00171 #ifdef PLATFORM_LINUX
00172 #define IFACE_UDP      4 // udp/ip sockets
00173 #define IFACE_TCP      5 // tcp/ip sockets
00174 #define IFACE_TERMINAL 6 // terminal (input reading)
00175 #endif
00176 
00177 #ifdef PLATFORM_TELOSB
00178 #define com_send_IFACE_STDIO com_send_IFACE_SERIAL2
00179 #define com_ioctl_IFACE_STDIO com_ioctl_IFACE_SERIAL2
00180 #define com_mode_IFACE_STDIO com_mode_IFACE_SERIAL2
00181 #else
00182 
00186 #define com_send_IFACE_STDIO com_send_IFACE_SERIAL
00187 
00192 #define com_ioctl_IFACE_STDIO com_ioctl_IFACE_SERIAL
00193 
00197 #define com_mode_IFACE_STDIO com_mode_IFACE_SERIAL
00198 #endif
00199 
00200 /********* Device-specific function prototypes ************/
00211 uint8_t com_send_IFACE_SERIAL(comBuf *buf);
00218 void com_mode_IFACE_SERIAL(uint8_t mode);
00223 void com_ioctl_IFACE_SERIAL(uint8_t request, ...);
00224 
00229 uint8_t com_send_IFACE_SERIAL2(comBuf *buf);
00236 void com_mode_IFACE_SERIAL2(uint8_t mode);
00241 void com_ioctl_IFACE_SERIAL2(uint8_t request, ...);
00243 
00254 uint8_t com_send_IFACE_RADIO(comBuf *buf);
00261 void com_mode_IFACE_RADIO(uint8_t mode);
00273 void com_ioctl_IFACE_RADIO(uint8_t request, ...);
00275 
00281 uint8_t com_send_IFACE_TERMINAL(comBuf *buf);
00282 void com_mode_IFACE_TERMINAL(uint8_t mode);
00283 void com_ioctl_IFACE_TERMINAL(uint8_t request, ...);
00284 
00285 uint8_t com_send_IFACE_UDP(comBuf *buf);
00286 void com_mode_IFACE_UDP(uint8_t mode);
00287 void com_ioctl_IFACE_UDP(uint8_t request, ...);
00289 
00295 
00296 uint8_t com_send_IFACE_LOOPBACK(comBuf *buf);
00297 void com_mode_IFACE_LOOPBACK(uint8_t mode);
00298 void com_ioctl_IFACE_LOOPBACK(uint8_t request, ...);
00300 
00301 
00308 
00310 enum {
00312    IF_OFF = 0, 
00314    IF_STANDBY,
00316    IF_IDLE,
00318    IF_LISTEN,
00319 #ifdef RADIO_USE_FEC
00320 
00321    IF_FEC_ENABLE,
00323    IF_FEC_DISABLE 
00324 #endif
00325 };
00327 
00328 #define PREAMBLE            0x53
00329 #define PREAMBLE_SIZE       2
00330 
00331 
00338 #define SELECT_IFACE_BUSY 150
00339 
00340 #define IFACE_NOT_REGISTERED 160
00341 
00342 
00350 typedef uint8_t IF_SET;
00351 
00352 /* NOTE: These implementations limit the number of devices to 8. */
00353 
00355 #define IF_SET(iface, set) (*set |= 1 << iface) // TODO: check shift direction
00356 
00357 #define IF_CLEAR(iface, set) (*set &= ~(1 << iface))
00358 
00359 #define IF_ZERO(set) (*set = 0)
00360 
00361 #define IF_ISSET(iface, set) (*set & (1 << iface))
00362 
00372 uint8_t com_select (IF_SET *iset, uint32_t msec);
00373 
00375 #define COM_BLOCK -1
00376 
00377 #define COM_NOBLOCK 0
00378 
00380 
00381 
00382 
00387 uint8_t com_init();
00389 extern mos_mutex_t if_send_mutexes[MAX_IFS];
00390 
00395 
00399 void com_flush (uint8_t iface);
00400 
00401 
00408 #define com_send(iface,buf) com_send_##iface (buf)
00409 #define com_sendto(iface,buf,dest) com_sendto_##iface(buf,dest)
00410 
00419 comBuf *com_recv(uint8_t iface);
00420 
00428 comBuf *com_recv_timed(uint8_t iface, uint32_t msecs);
00429 
00435 #define com_ioctl(iface,request,args...) com_ioctl_##iface (request, ##args)
00436 
00442 #define com_mode(iface,mode) com_mode_##iface (mode)
00443 
00449 void com_free_buf (comBuf *buf);
00451 
00462 void com_swap_bufs (uint8_t iface, comBuf *buf, comBuf **ret);
00463 
00480 void buf_insert16(uint8_t* p, uint16_t pos, uint16_t word);
00481 
00487 void buf_insert32(uint8_t* p, uint16_t pos, uint32_t dword);
00488 
00494 uint16_t buf_extract16(uint8_t* p, uint16_t pos);
00495 
00501 uint32_t buf_extract32(uint8_t* p, uint16_t pos);
00503 
00504 
00505 
00506 
00507 /* ELF object propagation support */
00509 char is_elf_packet(comBuf *buf);
00511 #define ELFPKT_BYTE0 65
00512 
00513 #define ELFPKT_BYTE1 75
00514 
00515 #define ELFPKT_BYTE2 85
00516 
00517 #define ELFPKT_BYTE3 95
00518 
00519 #ifdef USING_ELF
00520 
00521 #include "msched.h"
00522 #include "com.h"
00524 mos_thread_t *elfthread;
00526 comBuf *elfbuf;
00528 char is_elf_packet(comBuf *buf);
00529 
00531 #endif
00532 
00533 
00534 #endif

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