Contiki 2.5
tr1001.h
1 /*
2  * Copyright (c) 2005, Swedish Institute of Computer Science
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * This file is part of the Contiki operating system.
30  *
31  * @(#)$Id: tr1001.h,v 1.9 2010/03/02 22:40:39 nifi Exp $
32  */
33 #ifndef __TR1001_H__
34 #define __TR1001_H__
35 
36 #include "contiki-net.h"
37 #include "dev/radio.h"
38 
39 #include "contiki-conf.h"
40 
41 /**
42  * Radio driver for TR1001
43  */
44 extern const struct radio_driver tr1001_driver;
45 
46 /**
47  * Initialize the radio transceiver.
48  *
49  * Turns on reception of bytes and installs the receive interrupt
50  * handler.
51  */
52 int tr1001_init(void);
53 
54 /**
55  * Set the speed of the TR1001 radio device.
56  *
57  * This function sets the speed of the TR1001 radio transceiver. Both
58  * the sender and the receiver must have the same speed for
59  * communication to work.
60  *
61  * \param speed The speed of the TR1001 radio: TR1001_19200,
62  * TR1001_38400, TR1001_57600 or TR1001_115200.
63  *
64  */
65 void tr1001_set_speed(unsigned char s);
66 #define TR1001_19200 1
67 #define TR1001_38400 2
68 #define TR1001_57600 3
69 #define TR1001_115200 4
70 
71 /**
72  * Set the transmission power of the transceiver.
73  *
74  * The sensor board is equipped with a DS1804 100 position trimmer
75  * potentiometer which is used to set the transmission input current
76  * to the radio transceiver chip, thus setting the transmission power
77  * of the radio transceiver.
78  *
79  * This function sets the trimmer potentiometer to a value between 1
80  * and 100.
81  *
82  * \param p The power of the transceiver, between 1 (lowest) and 100
83  * (highest).
84  */
85 void tr1001_set_txpower(unsigned char p);
86 
87 /**
88  * \brief The highest transmission power
89  */
90 #define TR1001_TXPOWER_HIGHEST 100
91 
92 /**
93  * \brief The lowest transmission power
94  */
95 #define TR1001_TXPOWER_LOWEST 1
96 
97 /**
98  * Send a packet.
99  *
100  * This function causes a packet to be sent out after a small random
101  * delay, but without doing any MAC layer collision detection or
102  * back-offs. The packet is sent with a 4 byte header that contains a
103  * a "type" identifier, an 8-bit packet ID field and the length of the
104  * packet in network byte order.
105  *
106  * This function should normally not be called from user
107  * programs. Rather, the uIP TCP/IP or Rime stack should be used.
108  */
109 int tr1001_send(const void *packet, unsigned short len);
110 
111 /**
112  * Check if an incoming packet has been received.
113  *
114  * This function checks the receive buffer to see if an entire packet
115  * has been received. The actual reception is handled by an interrupt
116  * handler.
117  *
118  * This function should normally not be called from user
119  * programs. Rather, the uIP TCP/IP or Rime stack should be used.
120  *
121  * \return The length of the received packet, or 0 if no packet has
122  * been received.
123  */
124 int tr1001_read(void *buf, unsigned short bufsize);
125 
126 extern unsigned char tr1001_rxbuf[];
127 extern volatile unsigned char tr1001_rxstate;
128 
129 /**
130  * Calculate the signal strength of a received packet.
131  *
132  * This function calculates the received signal strength of the last
133  * received packet. This function typically is called when a packet
134  * has been received.
135  */
136 unsigned short tr1001_sstrength(void);
137 
138 #endif /* __TR1001_H__ */