Contiki 2.6

tr1001.h

00001 /*
00002  * Copyright (c) 2005, Swedish Institute of Computer Science
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the Institute nor the names of its contributors
00014  *    may be used to endorse or promote products derived from this software
00015  *    without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00027  * SUCH DAMAGE.
00028  *
00029  * This file is part of the Contiki operating system.
00030  *
00031  * @(#)$Id: tr1001.h,v 1.9 2010/03/02 22:40:39 nifi Exp $
00032  */
00033 #ifndef __TR1001_H__
00034 #define __TR1001_H__
00035 
00036 #include "contiki-net.h"
00037 #include "dev/radio.h"
00038 
00039 #include "contiki-conf.h"
00040 
00041 /**
00042  * Radio driver for TR1001
00043  */
00044 extern const struct radio_driver tr1001_driver;
00045 
00046 /**
00047  * Initialize the radio transceiver.
00048  *
00049  * Turns on reception of bytes and installs the receive interrupt
00050  * handler.
00051  */
00052 int tr1001_init(void);
00053 
00054 /**
00055  * Set the speed of the TR1001 radio device.
00056  *
00057  * This function sets the speed of the TR1001 radio transceiver. Both
00058  * the sender and the receiver must have the same speed for
00059  * communication to work.
00060  *
00061  * \param speed The speed of the TR1001 radio: TR1001_19200,
00062  * TR1001_38400, TR1001_57600 or TR1001_115200.
00063  *
00064  */
00065 void tr1001_set_speed(unsigned char s);
00066 #define TR1001_19200  1
00067 #define TR1001_38400  2
00068 #define TR1001_57600  3
00069 #define TR1001_115200 4
00070 
00071 /**
00072  * Set the transmission power of the transceiver.
00073  *
00074  * The sensor board is equipped with a DS1804 100 position trimmer
00075  * potentiometer which is used to set the transmission input current
00076  * to the radio transceiver chip, thus setting the transmission power
00077  * of the radio transceiver.
00078  *
00079  * This function sets the trimmer potentiometer to a value between 1
00080  * and 100.
00081  *
00082  * \param p The power of the transceiver, between 1 (lowest) and 100
00083  * (highest).
00084  */
00085 void tr1001_set_txpower(unsigned char p);
00086 
00087 /**
00088  * \brief   The highest transmission power
00089  */
00090 #define TR1001_TXPOWER_HIGHEST 100
00091 
00092 /**
00093  * \brief   The lowest transmission power
00094  */
00095 #define TR1001_TXPOWER_LOWEST  1
00096 
00097 /**
00098  * Send a packet.
00099  *
00100  * This function causes a packet to be sent out after a small random
00101  * delay, but without doing any MAC layer collision detection or
00102  * back-offs. The packet is sent with a 4 byte header that contains a
00103  * a "type" identifier, an 8-bit packet ID field and the length of the
00104  * packet in network byte order.
00105  *
00106  * This function should normally not be called from user
00107  * programs. Rather, the uIP TCP/IP or Rime stack should be used.
00108  */
00109 int tr1001_send(const void *packet, unsigned short len);
00110 
00111 /**
00112  * Check if an incoming packet has been received.
00113  *
00114  * This function checks the receive buffer to see if an entire packet
00115  * has been received. The actual reception is handled by an interrupt
00116  * handler.
00117  *
00118  * This function should normally not be called from user
00119  * programs. Rather, the uIP TCP/IP or Rime stack should be used.
00120  *
00121  * \return The length of the received packet, or 0 if no packet has
00122  * been received.
00123  */
00124 int tr1001_read(void *buf, unsigned short bufsize);
00125 
00126 extern unsigned char tr1001_rxbuf[];
00127 extern volatile unsigned char tr1001_rxstate;
00128 
00129 /**
00130  * Calculate the signal strength of a received packet.
00131  *
00132  * This function calculates the received signal strength of the last
00133  * received packet. This function typically is called when a packet
00134  * has been received.
00135  */
00136 unsigned short tr1001_sstrength(void);
00137 
00138 #endif /* __TR1001_H__ */