Revision 1566

View differences:

branches/ir_branch/lib/include/libwireless/wl_error_group.h
1
/**
2
 * Copyright (c) 2007 Colony Project
3
 * 
4
 * Permission is hereby granted, free of charge, to any person
5
 * obtaining a copy of this software and associated documentation
6
 * files (the "Software"), to deal in the Software without
7
 * restriction, including without limitation the rights to use,
8
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the
10
 * Software is furnished to do so, subject to the following
11
 * conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be
14
 * included in all copies or substantial portions of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
 * OTHER DEALINGS IN THE SOFTWARE.
24
 **/
25

  
26
/**
27
 * @file wl_error_group.h
28
 * @brief Error Packets
29
 *
30
 * A packet group for sending error packets.
31
 *
32
 * @author Brian Coltin, Colony Project, CMU Robotics Club
33
 **/
34

  
35
#ifndef WL_ERROR_GROUP_H
36
#define WL_ERROR_GROUP_H
37

  
38
/**
39
 * @file wl_error_group.h
40
 * @brief A packet group for error messages.
41
 *
42
 * A packet group for sending and receiving error
43
 * messages.
44
 *
45
 * @author Brian Coltin, Colony Project, CMU Robotics Club
46
 **/
47

  
48
/**
49
 * @defgroup wlerror Error Packets
50
 * @brief Functions for sending and receiving error packets
51
 * 
52
 * Functions for sending and receiving error packets.
53
 * 
54
 * @{
55
 **/
56

  
57
/**@brief Register this packet group with the wireless library **/
58
void wl_error_register(void);
59
/**@brief Unregister this packet group with the wireless library **/
60
void wl_error_unregister(void);
61
/**@brief Send a string in an error packet **/
62
void wl_error_send_string(char* str);
63

  
64
/** @} **/ // end defgroup
65

  
66
#endif
branches/ir_branch/lib/include/libwireless/sensor_matrix.h
1
/**
2
 * Copyright (c) 2007 Colony Project
3
 *
4
 * Permission is hereby granted, free of charge, to any person
5
 * obtaining a copy of this software and associated documentation
6
 * files (the "Software"), to deal in the Software without
7
 * restriction, including without limitation the rights to use,
8
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the
10
 * Software is furnished to do so, subject to the following
11
 * conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be
14
 * included in all copies or substantial portions of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
 * OTHER DEALINGS IN THE SOFTWARE.
24
 **/
25

  
26
/**
27
 * @file sensor_matrix.h
28
 * @brief Definitions for sensor matrices
29
 *
30
 * Contains functions and declarations for using sensor matrices.
31
 *
32
 * @author Brian Coltin, Colony Project, CMU Robotics Club
33
 **/
34

  
35
#ifndef SENSOR_MATRIX_H
36
#define SENSOR_MATRIX_H
37

  
38

  
39
/**
40
 * @defgroup sensormatrix Sensor Matrix
41
 * @brief the robot sensor matrix
42
 *
43
 * These functions and structures are used for localization
44
 * to determine the relative directions of robots.
45
 *
46
 * @{
47
 **/
48

  
49
#define MAXIMUM_XBEE_ID		0x10
50
#define READING_UNKNOWN		0xFF
51

  
52
/**
53
 * @struct SensorMatrix
54
 *
55
 * A sensor matrix.
56
 **/
57
//TODO: the order of member variables in this struct should be changed in case the compile packs the struct
58
// In order to achieve the best packing, the variables should be listed in order of decreasing memory size.
59
// Thus, pointers should be first, followed by int, followed by char.
60
typedef struct
61
{
62
	/**
63
	 * The number of robots in the token ring.
64
	 **/
65
	int numJoined;
66
	/**
67
	 * The element representing a robot is true if that robot
68
	 * is in the token ring and false otherwise.
69
	 **/
70
	unsigned char joined[MAXIMUM_XBEE_ID];
71

  
72
	// on the bayboard, we don't include the matrix to save memory.
73
#ifndef BAYBOARD
74
	/**
75
	 * The matrix. Each row represents the readings of one
76
	 * robot.
77
	 **/
78
	unsigned char matrix[MAXIMUM_XBEE_ID][MAXIMUM_XBEE_ID];
79
#endif
80
} SensorMatrix;
81

  
82
/**@brief Create a sensor matrix **/
83
void sensor_matrix_create(void);
84
/**@brief Set a reading in a sensor matrix **/
85
void sensor_matrix_set_reading(int observer, int robot, int reading);
86
/**@brief Get a reading in a sensor matrix **/
87
int sensor_matrix_get_reading(int observer, int robot);
88
/**@brief Set whether the robot is in the token ring **/
89
void sensor_matrix_set_in_ring(int robot, int in);
90
/**@brief Get whether the robot is in the sensor ring **/
91
int sensor_matrix_get_in_ring(int robot);
92
/**@brief Get the number of robots which have joined the token ring **/
93
int sensor_matrix_get_joined(void);
94
/**@brief Get the maximum size of the sensor matrix **/
95
int sensor_matrix_get_size(void);
96

  
97
/** @} **/ //end defgroup
98

  
99

  
100
#endif
101

  
branches/ir_branch/lib/include/libwireless/wireless.h
1
/**
2
 * Copyright (c) 2007 Colony Project
3
 *
4
 * Permission is hereby granted, free of charge, to any person
5
 * obtaining a copy of this software and associated documentation
6
 * files (the "Software"), to deal in the Software without
7
 * restriction, including without limitation the rights to use,
8
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the
10
 * Software is furnished to do so, subject to the following
11
 * conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be
14
 * included in all copies or substantial portions of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
 * OTHER DEALINGS IN THE SOFTWARE.
24
 **/
25

  
26
/**
27
 * @file wireless.h
28
 * @brief Contains definitions for the wireless library.
29
 *
30
 * Contains functions for the wireless library.
31
 *
32
 * @author Brian Coltin, Colony Project, CMU Robotics Club
33
 **/
34

  
35
#ifndef WIRELESS_H
36
#define WIRELESS_H
37

  
38
//Note: If this is raised above 16, we will need to do
39
//something about frame numbers for TX Status packets.
40
/**
41
 * The maximum number of packet groups.
42
 **/
43
//TODO: a PacketGroupHandler is at least 10 bytes (I don't know if function pointers are 2 bytes
44
// or 4 bytes).  That means that in the c file, your array of packet groups is at least 160 bytes.
45
// Normally that might be fine (the robot's avr chips have 4k SRAM), but austin's chip only has
46
// 1k SRAM, so if this number can be reduced or if the size of the struct could be reduced, that would be a plus.
47
#define WL_MAX_PACKET_GROUPS 16
48

  
49
/**
50
 * @defgroup wireless Wireless
51
 * @brief Wireless definitions.
52
 *
53
 * Contains functions and definitions for dealing with wireless functionality.<br><br>
54
 *
55
 * The wireless library provides a modular method for dealing with
56
 * wireless packets, by allowing packet groups to be registered.
57
 * A packet group is a collection of packets which share a packet
58
 * group code. Each packet in the group also has a type. A packet
59
 * group code and type are sent with each packet. When a packet
60
 * with a group code registered in the wireless library is
61
 * received, the corresponding event handler is called. The
62
 * event handler uses the packet type and other information
63
 * stored in the packet to respond.<br><br>
64
 *
65
 * This architecture allows different wireless functionality to be
66
 * defined and handled separately, making it simpler and more
67
 * efficient to take advantage of the XBee's wireless functionality.
68
 *
69
 * @{
70
 **/
71

  
72
/**
73
 * @struct PacketGroupHandler
74
 * A PacketGroupHandler represents a packet group, and is used to
75
 * register a packet group with the wireless library. It contains
76
 * handlers for various events which can occur related to a packet
77
 * group.
78
 **/
79
//TODO: the order of member variables in this struct should be changed in case the compile packs the struct
80
// In order to achieve the best packing, the variables should be listed in order of decreasing memory size.
81
// Thus, pointers should be first, followed by int, followed by char.
82
typedef struct
83
{
84
	/**
85
	 * The group code for this packet group. This number
86
	 * must be unique. The maximum number of packet groups
87
	 * is defined by WL_MAX_PACKET_GROUPS.
88
	 **/
89
  //TODO: if this number must be less than or equal to WL_MAX_PACKET_GROUPS, don't you only need
90
  // one byte for it and it can be made an unsigned char?
91
	unsigned int groupCode;
92

  
93
	/**
94
	 * Called every half second (not in interrupt,
95
	 * but in wl_do).
96
	 **/
97
	void (*timeout_handler) (void);
98

  
99
	/**
100
	 * Called when a transmit status packet is received
101
	 * from the XBee where the first four bits of the frame
102
	 * are  the group code.
103
	 *
104
	 * @param frame the last four bits of the frame
105
	 * @param received is true if we received an ack, 0 if
106
	 * we did not.
107
	 **/
108
	void (*handle_response) (int frame, int received);
109

  
110
	/**
111
	 * Called when we receive a packet from this group.
112
	 *
113
	 * @param type the packet type
114
	 * @param source the 16-bit address of the XBee this
115
	 * packet was sent from
116
	 * @param packet the packet received
117
	 * @param length the length of the packet
118
	 **/
119
	void (*handle_receive) (char type, int source, unsigned char* packet, int length);
120

  
121
	/**
122
	 * Called for any cleanup when the network is turned off.
123
	 **/
124
	void (*unregister) (void);
125

  
126
} PacketGroupHandler;
127

  
128
/**@brief Initialize the wireless library **/
129
int wl_init(void);
130
/**@brief Uninitialize the wireless library **/
131
void wl_terminate(void);
132
/**@brief Perform wireless library functionality **/
133
void wl_do(void);
134
/**@brief Register a packet group with the wireless library **/
135
void wl_register_packet_group(PacketGroupHandler* h);
136
/**@brief Unregister a packet group with the wireless library **/
137
void wl_unregister_packet_group(PacketGroupHandler* h);
138

  
139
/**@brief Send a packet to a specific robot in any PAN **/
140
int wl_send_robot_to_robot_global_packet(char group, char type, char* data, int len, int dest, char frame);
141
/**@brief Send a packet to a specific robot in our PAN **/
142
int wl_send_robot_to_robot_packet(char group, char type, char* data, int len, int dest, char frame);
143
/**@brief Send a packet to all robots **/
144
int wl_send_global_packet(char group, char type, char* data, int len, char frame);
145
/**@brief Send a packet to all robots in our PAN **/
146
void wl_send_pan_packet(char group, char type, char* data, int len, char frame);
147

  
148
/**@brief Set the PAN we are using **/
149
int wl_set_pan(int pan);
150
/**@brief Get the PAN we are using **/
151
int wl_get_pan(void);
152
/**@brief Set the channel we are using **/
153
int wl_set_channel(int channel);
154
/**@brief Get the channel we are using **/
155
int wl_get_channel(void);
156
/**@brief Get the 16-bit address of the XBee module **/
157
int wl_get_xbee_id(void);
158
/**@brief Set the com port on a computer, undefined on the robot.**/
159
void wl_set_com_port(char* port);
160

  
161
/** @} **/ // end defgroup
162

  
163
#endif
164

  
branches/ir_branch/lib/include/libwireless/wl_token_ring.h
1
/**
2
 * Copyright (c) 2007 Colony Project
3
 * 
4
 * Permission is hereby granted, free of charge, to any person
5
 * obtaining a copy of this software and associated documentation
6
 * files (the "Software"), to deal in the Software without
7
 * restriction, including without limitation the rights to use,
8
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the
10
 * Software is furnished to do so, subject to the following
11
 * conditions:
12
 * 
13
 * The above copyright notice and this permission notice shall be
14
 * included in all copies or substantial portions of the Software.
15
 * 
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
 * OTHER DEALINGS IN THE SOFTWARE.
24
 **/
25

  
26
/**
27
 * @file wl_token_ring.h
28
 * @brief Declarations for the token ring packet group
29
 * 
30
 * Contains declarations for the token ring packet group.
31
 *
32
 * @author Brian Coltin, Colony Project, CMU Robotics Club
33
 **/
34

  
35
#ifndef WL_TOKEN_RING_H
36
#define WL_TOKEN_RING_H
37

  
38
/**
39
 * @defgroup tokenring Token Ring
40
 * @brief Wireless library token ring implementation
41
 *
42
 * This packet group is used to form a token ring, which
43
 * keeps track of the relative directions of the robots
44
 * from one another.
45
 *
46
 * @{
47
 **/
48

  
49
/**@brief Register the token ring group with the wireless library.**/
50
int wl_token_ring_register(void);
51
/**@brief Unregister the token ring group with the wirelss library.**/
52
void wl_token_ring_unregister(void);
53
/**@brief Set the functions called to turn the bom on and off.**/
54
void wl_token_ring_set_bom_functions(void (*on_function) (void), void (*off_function) (void),
55
  int (*max_bom_function) (void));
56

  
57
/**@brief Join the token ring **/
58
int wl_token_ring_join(void);
59
/**@brief Leave the token ring **/
60
void wl_token_ring_leave(void);
61

  
62
/**@brief Return the number of robots in the token ring **/
63
int wl_token_get_robots_in_ring(void);
64
/**@brief Return whether a given robot is in the token ring **/
65
int wl_token_is_robot_in_ring(int robot);
66

  
67
/**@brief Begin iterating through robots in the token ring **/
68
void wl_token_iterator_begin(void);
69
/**@brief Returns whether there are more robots to iterate through **/
70
int wl_token_iterator_has_next(void);
71
/**@brief Returns the ID of the next robot in the token ring **/
72
int wl_token_iterator_next(void);
73

  
74
/**@brief Return the latest BOM reading between two robots **/
75
int wl_token_get_sensor_reading(int source, int dest);
76
/**@brief Return the latest BOM reading between us and another robot **/
77
int wl_token_get_my_sensor_reading(int dest);
78
/**@brief Return the number of robots in the sensor matrix.*/
79
int wl_token_get_num_robots(void);
80
/**@brief Return the number of non-null elements in the sensor matrix*/
81
int wl_token_get_matrix_size(void);
82

  
83
/** @} **/ //end token ring group
84

  
85
#endif
branches/ir_branch/lib/include/libwireless/wl_basic.h
1
/**
2
 * @file wl_basic.h
3
 * @brief High Level Wireless Packet Sending-Receiving Functions
4
 *
5
 * Abstracted wireless functionality for sending and receiving packets
6
 *
7
 * @author Christopher Mar, Colony Project, CMU Robotics Club
8
 **/
9

  
10
/**
11
 * @defgroup wl_basic Wireless Basic
12
 * @brief Wireless abstraction for easily sending and receing packets.
13
 *
14
 * A high level abstraction of the wireless library.
15
 *
16
 * This will allow you to easily send and receive packets.
17
 *
18
 * @{
19
 **/
20

  
21
#ifndef WL_BASIC_H
22
#define WL_BASIC_H
23

  
24
#include "wireless.h"
25

  
26
/** @brief default wireless group for basic sending and receiving packets **/
27
#define WL_BASIC_GROUP 8
28

  
29
/** @brief PacketGroupHandler struct for Basic Group **/
30
PacketGroupHandler wl_basic_group_handler;
31

  
32
/**
33
 * @brief struct that contains relevant packet information
34
 **/
35
struct PacketInfo {
36
    char new_flag;
37
    char type;
38
    int source;
39
    unsigned char* data;
40
    int length;
41
};
42

  
43
/**
44
 * @brief current packet information, correct after wl_basic_do()
45
 **/
46
struct PacketInfo current_packet;
47

  
48
/** @brief init wireless for Basic Group **/
49
int wl_basic_init( void (*handle_receive) (char type, int source, unsigned char* packet, int length) );
50
/** @brief init wireless for Basic Group with default packet handling **/
51
int wl_basic_init_default( void );
52
/** @brief internal function to register a packet handler function **/
53
void wl_basic_register_handler( void (*handle_receive) (char type, int source, unsigned char* packet, int length) );
54
/** @brief send a packet to a single robot in Basic Group **/
55
void wl_basic_send_robot_packet( char type, char* data, int len, int dest );
56
/** @brief send a packet to all robots in Basic Group **/
57
void wl_basic_send_global_packet( char type, char* data, int len );
58
/** @brief internal default packet handler if none is specified on init **/
59
void wl_basic_packet_receive_handler( char type, int source, unsigned char* packet, int length );
60
/** @brief wrapper for wl_do() to return packet data buffer **/
61
unsigned char* wl_basic_do_default( int *length );
62
/** @} **/ // end defgroup
63

  
64
#endif
65

  
branches/ir_branch/lib/include/libwireless/wl_defs.h
1
/**
2
 * Copyright (c) 2007 Colony Project
3
 * 
4
 * Permission is hereby granted, free of charge, to any person
5
 * obtaining a copy of this software and associated documentation
6
 * files (the "Software"), to deal in the Software without
7
 * restriction, including without limitation the rights to use,
8
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the
10
 * Software is furnished to do so, subject to the following
11
 * conditions:
12
 * 
13
 * The above copyright notice and this permission notice shall be
14
 * included in all copies or substantial portions of the Software.
15
 * 
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
 * OTHER DEALINGS IN THE SOFTWARE.
24
 **/
25

  
26
/**
27
 * @file wl_defs.h
28
 * @brief Definitions for Wireless
29
 *
30
 * Contains definitions for wireless packet groups, packet types,
31
 * debugging information, etc.
32
 *
33
 * @author Brian Coltin, Colony Project, CMU Robotics Club
34
 **/
35

  
36
#ifndef WL_DEFS_H
37
#define WL_DEFS_H
38

  
39
//comment out this line if using a computer hooked up to an xbee
40
//#define ROBOT
41

  
42
//uncomment this line for debug information
43
//#define WL_DEBUG
44

  
45
// Packet Groups and Types
46

  
47
// Error group
48
#define WL_ERROR_GROUP 1
49

  
50
#define WL_ERROR_STRING_TYPE 1
51

  
52
// Token Ring group
53
#define WL_TOKEN_RING_GROUP 2
54

  
55
#define WL_TOKEN_PASS 1
56
#define WL_TOKEN_SENSOR_MATRIX 2
57
#define WL_TOKEN_BOM_ON 3
58
#define WL_TOKEN_JOIN 4
59
#define WL_TOKEN_JOIN_ACCEPT 5
60

  
61
// timing constants
62
#ifndef FIREFLY
63
#define BOM_DELAY 100
64
#else
65
#define BOM_DELAY 200
66
#endif
67

  
68
#define DEATH_DELAY 4
69
#define JOIN_DELAY 8
70

  
71
#ifdef WL_DEBUG
72

  
73
#ifdef ROBOT
74
#include <serial.h>
75
#endif
76

  
77
#ifdef ROBOT
78
#define WL_DEBUG_PRINT( s ) usb_puts( s )
79
#else
80
#define WL_DEBUG_PRINT( s ) printf( s )
81
#endif
82

  
83
#ifdef ROBOT
84
#define WL_DEBUG_PRINT_INT( i ) usb_puti(i)
85
#else
86
#define WL_DEBUG_PRINT_INT( i ) printf("%i", i)
87
#endif
88

  
89
#else
90

  
91
#define WL_DEBUG_PRINT( s )
92
#define WL_DEBUG_PRINT_INT( i )
93

  
94
#endif
95

  
96
#endif
97

  
branches/ir_branch/lib/include/libwireless/xbee.h
1
/**
2
 * Copyright (c) 2007 Colony Project
3
 * 
4
 * Permission is hereby granted, free of charge, to any person
5
 * obtaining a copy of this software and associated documentation
6
 * files (the "Software"), to deal in the Software without
7
 * restriction, including without limitation the rights to use,
8
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the
10
 * Software is furnished to do so, subject to the following
11
 * conditions:
12
 * 
13
 * The above copyright notice and this permission notice shall be
14
 * included in all copies or substantial portions of the Software.
15
 * 
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
 * OTHER DEALINGS IN THE SOFTWARE.
24
 **/
25

  
26
/**
27
 * @file xbee.h
28
 * @brief Contains definitions for using the XBee
29
 *
30
 * Contains definitions for interfacing with the 
31
 * XBee module, from either a robot or a computer.
32
 * To use a robot, define ROBOT in wl_defs.h, and
33
 * to use a computer, don't define ROBOT.
34
 *
35
 * @author Brian Coltin, Colony Project, CMU Robotics Club
36
 **/
37

  
38
#ifndef XBEE_H
39
#define XBEE_H
40

  
41
/**
42
 * The port to use the XBee from on the computer.
43
 * Also, a backup port if the other is used.
44
 **/
45
#ifndef ROBOT
46
#define XBEE_PORT_DEFAULT "/dev/ttyUSB1"
47
#endif
48

  
49
/**
50
 * @defgroup xbee XBee
51
 * @brief Interface with the XBee module
52
 *
53
 * Interface with the XBee module.
54
 *
55
 * @{
56
 **/
57

  
58
/*Definitions*/
59
/**@brief Unset PAN, uses XBee default **/
60
#define XBEE_PAN_DEFAULT 0xFFFF
61
/**@brief Unset channel, uses XBee default **/
62
#define XBEE_CHANNEL_DEFAULT 0
63
/**@brief Broadcast to all robots in the PAN **/
64
#define XBEE_BROADCAST 0xFFFF
65
/**@brief No special options **/
66
#define XBEE_OPTIONS_NONE 0x00
67
/**@brief Do not receive a TX_STATUS message from this packet **/
68
#define XBEE_OPTIONS_DISABLE_RESPONSE 0x01
69
/**@brief Send the packet to all PANS **/
70
#define XBEE_OPTIONS_BROADCAST_ALL_PANS 0x04
71
/**@brief A transmit status packet **/
72
#define XBEE_TX_STATUS 0x89
73
/**@brief A packet received from another XBee **/
74
#define XBEE_RX 0x81
75

  
76
/**@brief Initialize the XBee library **/
77
int xbee_lib_init(void);
78
/**@brief Uninitialize the XBee library **/
79
void xbee_terminate(void);
80
/**@brief Get a packet from the XBee **/
81
int xbee_get_packet(unsigned char* packet);
82
/**@brief Send a packet to the XBee **/
83
int xbee_send_packet(char* packet, int len, int dest, char options, char frame);
84
/**@brief Set the PAN ID for the XBee **/
85
int xbee_set_pan_id(int id);
86
/**@brief Get the XBee's PAN ID **/
87
unsigned int xbee_get_pan_id(void);
88
/**@brief Set the channel the XBee is currently using **/
89
int xbee_set_channel(int channel);
90
/**@brief Get the channel the XBee is currently using **/
91
int xbee_get_channel(void);
92
/**@brief Get the XBee's 16-bit address **/
93
unsigned int xbee_get_address(void);
94
/**@brief Set the com port on a computer, undefined on the robot**/
95
void xbee_set_com_port(char* port);
96
/**@brief Reset XBee **/
97
int xbee_reset(void);
98

  
99
/**@}**/ //end defgroup
100

  
101
#endif
branches/ir_branch/lib/include/libwireless/queue.h
1
/**
2
 * Copyright (c) 2007 Colony Project
3
 * 
4
 * Permission is hereby granted, free of charge, to any person
5
 * obtaining a copy of this software and associated documentation
6
 * files (the "Software"), to deal in the Software without
7
 * restriction, including without limitation the rights to use,
8
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the
10
 * Software is furnished to do so, subject to the following
11
 * conditions:
12
 * 
13
 * The above copyright notice and this permission notice shall be
14
 * included in all copies or substantial portions of the Software.
15
 * 
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
 * OTHER DEALINGS IN THE SOFTWARE.
24
 **/
25

  
26
/**
27
 * @file queue.h
28
 * @brief A queue implementation
29
 * 
30
 * Implements a queue, a first in, first out data structure.
31
 *
32
 * @author Brian Coltin, Colony Project, CMU Robotics Club
33
 **/
34

  
35
#ifndef WIRELESS_QUEUE_H
36
#define WIRELESS_QUEUE_H
37

  
38
#ifndef ROBOT
39
#include <pthread.h>
40
#endif
41

  
42
struct node_def;
43

  
44
/**
45
 * @defgroup queue Queue
46
 * @brief A queue implementation
47
 * 
48
 * A queue implementation.
49
 *
50
 * @{
51
 **/
52

  
53
/**
54
 * @struct Queue
55
 * Represents a queue, a first in, first out data structure.
56
 **/
57
typedef struct
58
{
59
	/**
60
	 * The head of the queue, the next item to be removed.
61
	 **/
62
	struct node_def* head;
63
	/**
64
	 * The tail of the queue, the last item added.
65
	 **/
66
	struct node_def* tail;
67
	/**
68
	 * The number of elements in the queue.
69
	 **/
70
	int size;
71
	
72
#ifndef ROBOT
73
	pthread_mutex_t lock;
74
#endif
75
} Queue;
76

  
77
/** @brief Create a new queue **/
78
Queue* queue_create(void);
79
/** @brief Destroy a queue **/
80
void queue_destroy(Queue* q);
81
/** @brief Add an element to a queue **/
82
int queue_add(Queue* q, void* item);
83
/** @brief Remove an element from a queue **/
84
void* queue_remove(Queue* q);
85
/** @brief Remove all instances of a given element from a queue **/
86
void queue_remove_all(Queue* q, void* item);
87
/** @brief Get the size of a queue **/
88
int queue_size(Queue* q);
89
/** @brief Check if the queue is empty **/
90
int queue_is_empty(Queue* q);
91

  
92
/** @} **/
93

  
94

  
95
#endif
branches/ir_branch/lib/include/libdragonfly/battery.h
1
/**
2
 * Copyright (c) 2007 Colony Project
3
 * 
4
 * Permission is hereby granted, free of charge, to any person
5
 * obtaining a copy of this software and associated documentation
6
 * files (the "Software"), to deal in the Software without
7
 * restriction, including without limitation the rights to use,
8
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the
10
 * Software is furnished to do so, subject to the following
11
 * conditions:
12
 * 
13
 * The above copyright notice and this permission notice shall be
14
 * included in all copies or substantial portions of the Software.
15
 * 
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
 * OTHER DEALINGS IN THE SOFTWARE.
24
 **/
25

  
26

  
27
/**
28
 * @file battery.h
29
 * @brief Definitions for checking battery voltage.
30
 * 
31
 * Contains definitions for checking the voltage of the 
32
 * battery.
33
 *
34
 * @author Colony Project, CMU Robotics Club
35
 **/
36

  
37
#ifndef _BATTERY_H_
38
#define _BATTERY_H_
39

  
40
/**
41
 * @addtogroup battery
42
 * @{
43
 **/
44

  
45
/** @brief Normal battery voltage. (6 V) **/
46
#define BATTERY_NORMALV 154
47
/** @brief Charging battery voltage. (7 V) **/
48
#define BATTERY_CHARINGV 179
49
/** @brief Low battery voltage. ( < 6 V) **/
50
#define BATTERY_LOWV 152
51

  
52
/** @brief Read the battery voltage. **/
53
int battery8(void);
54
/** @brief Read the battery voltage in deciVolts. **/
55
int battery(void);
56
/** @brief Check if the battery is low. **/
57
char battery_low(void);
58
/** @brief Get an average battery voltage reading. **/
59
int battery8_avg(int n_samples);
60

  
61
/** @} **/ //end addtogroup
62

  
63
#endif
64

  
branches/ir_branch/lib/include/libdragonfly/dio.h
1
/**
2
 * Copyright (c) 2007 Colony Project
3
 * 
4
 * Permission is hereby granted, free of charge, to any person
5
 * obtaining a copy of this software and associated documentation
6
 * files (the "Software"), to deal in the Software without
7
 * restriction, including without limitation the rights to use,
8
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the
10
 * Software is furnished to do so, subject to the following
11
 * conditions:
12
 * 
13
 * The above copyright notice and this permission notice shall be
14
 * included in all copies or substantial portions of the Software.
15
 * 
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
 * OTHER DEALINGS IN THE SOFTWARE.
24
 **/
25

  
26

  
27
/**
28
 * @file dio.h
29
 * @brief Definitions for digital input / output
30
 *
31
 * This file contains definitions and functions for dealing
32
 * with digital input and output.
33
 *
34
 * @author Colony Project, CMU Robotics Club
35
 * Based on Tom Lauwer's Firefly Library
36
 **/
37

  
38
#ifndef _DIO_H
39
#define _DIO_H
40

  
41
/*
42
  these are ALL the pins
43
  don't use unless you know what you're doing
44
*/
45

  
46
/*
47
  DIO pins on new dragonfly boards are shown below:
48
  -----------------------------------------------
49
  | _PIN_E6 | _PIN_E7 | _PIN_D2 | _PIN_D3 | VCC |
50
  -----------------------------------------------
51
  | _PIN_E2 | _PIN_E3 | _PIN_E4 | _PIN_E5 | GND |
52
  -----------------------------------------------
53
*/
54

  
55
/** @brief Port A **/
56
#define _PORT_A 1
57
/** @brief Port B **/
58
#define _PORT_B 2
59
/** @brief Port C **/
60
#define _PORT_C 3
61
/** @brief Port D **/
62
#define _PORT_D 4
63
/** @brief Port E **/
64
#define _PORT_E 5
65
/** @brief Port F **/
66
#define _PORT_F 6
67
/** @brief Port G **/
68
#define _PORT_G 7
69

  
70
/** @brief Pin A0 **/
71
#define _PIN_A0 8
72
/** @brief Pin A1 **/
73
#define _PIN_A1 9
74
/** @brief Pin A2 **/
75
#define _PIN_A2 10
76
/** @brief Pin A3 **/
77
#define _PIN_A3 11
78
/** @brief Pin A4 **/
79
#define _PIN_A4 12
80
/** @brief Pin A5 **/
81
#define _PIN_A5 13
82
/** @brief Pin A6 **/
83
#define _PIN_A6 14 
84
/** @brief Pin A7 **/
85
#define _PIN_A7 15
86

  
87
/** @brief Pin B0 **/
88
#define _PIN_B0 16
89
/** @brief Pin B1 **/
90
#define _PIN_B1 17
91
/** @brief Pin B2 **/
92
#define _PIN_B2 18
93
/** @brief Pin B3 **/
94
#define _PIN_B3 19
95
/** @brief Pin B4 **/
96
#define _PIN_B4 20
97
/** @brief Pin B5 **/
98
#define _PIN_B5 21
99
/** @brief Pin B6 **/
100
#define _PIN_B6 22
101
/** @brief Pin B7 **/
102
#define _PIN_B7 23
103

  
104
/** @brief Pin C0 **/
105
#define _PIN_C0 24
106
/** @brief Pin C1 **/
107
#define _PIN_C1 25
108
/** @brief Pin C2 **/
109
#define _PIN_C2 26
110
/** @brief Pin C3 **/
111
#define _PIN_C3 27
112
/** @brief Pin C4 **/
113
#define _PIN_C4 28
114
/** @brief Pin C5 **/
115
#define _PIN_C5 29
116
/** @brief Pin C6 **/
117
#define _PIN_C6 30
118
/** @brief Pin C7 **/
119
#define _PIN_C7 31
120

  
121
/** @brief Pin D0 **/
122
#define _PIN_D0 32  // pin DIO6 on new dragonfly boards
123
/** @brief Pin D1 **/
124
#define _PIN_D1 33  // pin DIO7
125
/** @brief Pin D2 **/
126
#define _PIN_D2 34
127
/** @brief Pin D3 **/
128
#define _PIN_D3 35
129
/** @brief Pin D4 **/
130
#define _PIN_D4 36
131
/** @brief Pin D5 **/
132
#define _PIN_D5 37
133
/** @brief Pin D6 **/
134
#define _PIN_D6 38
135
/** @brief Pin D7 **/
136
#define _PIN_D7 39
137

  
138
/** @brief Pin E0 **/
139
#define _PIN_E0 40
140
/** @brief Pin E1 **/
141
#define _PIN_E1 41
142
/** @brief Pin E2 **/
143
#define _PIN_E2 42  // pin DIO0
144
/** @brief Pin E3 **/
145
#define _PIN_E3 43  // pin DIO1
146
/** @brief Pin E4 **/
147
#define _PIN_E4 44  // pin DIO2
148
/** @brief Pin E5 **/
149
#define _PIN_E5 45  // pin DIO3
150
/** @brief Pin E6 **/
151
#define _PIN_E6 46  // pin DIO4
152
/** @brief Pin E7 **/
153
#define _PIN_E7 47  // pin DIO5
154

  
155
/** @brief Pin F0 **/
156
#define _PIN_F0 48
157
/** @brief Pin F1 **/
158
#define _PIN_F1 49
159
/** @brief Pin F2 **/
160
#define _PIN_F2 50
161
/** @brief Pin F3 **/
162
#define _PIN_F3 51
163
/** @brief Pin F4 **/
164
#define _PIN_F4 52
165
/** @brief Pin F5 **/
166
#define _PIN_F5 53
167
/** @brief Pin F6 **/
168
#define _PIN_F6 54
169
/** @brief Pin F7 **/
170
#define _PIN_F7 55
171

  
172
/** @brief Pin G0 **/
173
#define _PIN_G0 56
174
/** @brief Pin WR **/
175
#define _PIN_WR 56
176
/** @brief Pin G1 **/
177
#define _PIN_G1 57
178
/** @brief Pin RD **/
179
#define _PIN_RD 57
180
/** @brief Pin G2 **/
181
#define _PIN_G2 58
182
/** @brief Pin ALE **/
183
#define _PIN_ALE 58
184
/** @brief Pin G3 **/
185
#define _PIN_G3 59
186
/** @brief Pin TOSC2 **/
187
#define _PIN_TOSC2 59
188
/** @brief Pin G4 **/
189
#define _PIN_G4 60
190
/** @brief Pin TOSC1 **/
191
#define _PIN_TOSC1 60
192
//#define _PIN_G5 61
193
//#define _PIN_G6 62
194
//#define _PIN_G7 63
195

  
196
/*
197
  These are the header pins (the ones you can connect things to)
198
  Feel free to use these
199
*/
200

  
201
/**
202
 * @addtogroup dio
203
 * @{
204
 **/
205
/** @brief Pin A0 **/
206
#define PIN_A0 8
207
/** @brief Pin A1 **/
208
#define PIN_A1 9
209
/** @brief Pin A2 **/
210
#define PIN_A2 10
211
/** @brief Pin A3 **/
212
#define PIN_A3 11
213
/** @brief Pin A4 **/
214
#define PIN_A4 12
215
/** @brief Pin A5 **/
216
#define PIN_A5 13
217
/** @brief Pin A6 **/
218
#define PIN_A6 14 
219
/** @brief Pin A7 **/
220
#define PIN_A7 15
221

  
222
/** @brief Pin SS **/
223
#define PIN_SS 16
224
/** @brief Pin SCK **/
225
#define PIN_SCK 17
226
/** @brief Pin MOSI **/
227
#define PIN_MOSI 18
228
/** @brief Pin MISO **/
229
#define PIN_MISO 19
230
/** @brief LCD Command Pin **/
231
#define PIN_LCD_COMMAND 20
232

  
233
/** @brief Pin C0 **/
234
#define PIN_C0 24
235
/** @brief Pin C1 **/
236
#define PIN_C1 25
237
/** @brief Pin C2 **/
238
#define PIN_C2 26
239
/** @brief Pin C3 **/
240
#define PIN_C3 27
241
/** @brief Pin C4 **/
242
#define PIN_C4 28
243
/** @brief Pin C5 **/
244
#define PIN_C5 29
245
/** @brief Pin C6 **/
246
#define PIN_C6 30
247
/** @brief Pin C7 **/
248
#define PIN_C7 31
249

  
250
/** @brief Pin SCL **/
251
#define PIN_SCL 32
252
/** @brief Pin SDA **/
253
#define PIN_SDA 33
254

  
255
/** @brief Pin RX0 **/
256
#define PIN_RX0 40
257
/** @brief Pin TX0 **/
258
#define PIN_TX0 41
259
/** @brief LCD Reset Pin **/
260
#define PIN_LCD_RESET 42
261
/** @brief Pin E6 **/
262
#define PIN_E6 46
263
/** @brief Pin EXT_DIO1 **/
264
#define PIN_EXT_DIO1 46
265
/** @brief Pin E7 **/
266
#define PIN_E7 47
267
/** @brief Pin EXT_DIO2 **/
268
#define PIN_EXT_DIO2 48
269

  
270
/** @brief Pin AN0 **/
271
#define PIN_AN0 48
272
/** @brief Pin ADC0 **/
273
#define PIN_ADC0 48
274
/** @brief Pin AN1 **/
275
#define PIN_AN1 49
276
/** @brief Pin ADC1 **/
277
#define PIN_ADC1 49
278
/** @brief Pin AN2 **/
279
#define PIN_AN2 50
280
/** @brief Pin ADC2 **/
281
#define PIN_ADC2 50
282
/** @brief Pin AN3 **/
283
#define PIN_AN3 51
284
/** @brief Pin ADC3 **/
285
#define PIN_ADC3 51
286
/** @brief Pin AN4 **/
287
#define PIN_AN4 52
288
/** @brief Pin ADC4 **/
289
#define PIN_ADC4 52
290
/** @brief Pin AN5 **/
291
#define PIN_AN5 53
292
/** @brief Pin ADC5 **/
293
#define PIN_ADC5 53
294
/** @brief Pin AN6 **/
295
#define PIN_AN6 54
296
/** @brief Pin ADC6 **/
297
#define PIN_ADC6 54
298
/** @brief Pin AN7 **/
299
#define PIN_AN7 55
300
/** @brief Pin ADC7 **/
301
#define PIN_ADC7 55
302

  
303
/** @brief Wheel Pin **/
304
#define PIN_WHEEL 54
305
/** @brief Battery Voltage Monitor Pin **/
306
#define PIN_BATT 55
307

  
308
/** @brief button1 Pin **/
309
#define PIN_BTN1 56
310
/** @brief button2 Pin **/
311
#define PIN_BTN2 57
312

  
313
/** @brief LED1 Pin **/
314
#define PIN_LED1 58
315

  
316
/* Buttons */
317
/** @brief Button Pin **/
318
#define PIN_BTN PING
319
/** @brief button2 Pin **/
320
#define BTN2 PING1
321
/** @brief button1 Pin **/
322
#define BTN1 PING0
323

  
324
/** @brief Read a portpin. **/
325
int digital_input(int);
326
/** @brief Output to a portpin. **/
327
void digital_output(int bit, int val);
328
/** @brief Pullup a portpin. **/
329
void digital_pull_up(int);
330

  
331
/** @brief Check if button1 is pressed. **/
332
int button1_read( void );
333
/** @brief Check if button1 is clicked. **/
334
int button1_click( void );
335
/** @brief Wait until button1 is pressed. **/
336
void button1_wait( void );
337

  
338
/** @brief Check if button2 is pressed. **/
339
int button2_read( void );
340
/** @brief Check if button2 is clicked. **/
341
int button2_click( void );
342
/** @brief Wait until button2 is pressed. **/
343
void button2_wait( void );
344

  
345
/** @} **/ // end addtogroup
346

  
347
#endif
348

  
branches/ir_branch/lib/include/libdragonfly/dragonfly_lib.h
1
/**
2
 * Copyright (c) 2007 Colony Project
3
 * 
4
 * Permission is hereby granted, free of charge, to any person
5
 * obtaining a copy of this software and associated documentation
6
 * files (the "Software"), to deal in the Software without
7
 * restriction, including without limitation the rights to use,
8
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the
10
 * Software is furnished to do so, subject to the following
11
 * conditions:
12
 * 
13
 * The above copyright notice and this permission notice shall be
14
 * included in all copies or substantial portions of the Software.
15
 * 
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
 * OTHER DEALINGS IN THE SOFTWARE.
24
 **/
25

  
26

  
27
/**
28
 * @file dragonfly_lib.h
29
 * @brief Contains other include files
30
 * 
31
 * Include this file for all the functionality of libdragonfly.
32
 *
33
 * @author Colony Project, CMU Robotics Club
34
 **/
35

  
36
#ifndef _DRAGONFLY_LIB_H_
37
#define _DRAGONFLY_LIB_H_
38

  
39
/**
40
 * @addtogroup dragonfly
41
 * @{
42
 **/
43

  
44
// Configuration definitions
45
/** @brief Initialize analog **/
46
#define ANALOG 0x01
47
/** @brief Initialize serial communications **/
48
#define SERIAL 0x02
49
/** @brief Initialize USB communications **/
50
#define USB    0x02
51
/** @brief Initialize communications **/
52
#define COMM   0x02
53
/** @brief Initialize the orb **/
54
#define ORB    0x04
55
/** @brief Initialize the motors **/
56
#define MOTORS 0x08
57
/** @brief Initialize I2C **/
58
#define I2C    0x20
59
/** @brief Initialize the buzzer **/
60
#define BUZZER 0x40
61
/** @brief Initialize the LCD screen **/
62
#define LCD    0x80
63
/** @brief Initialize the rangefinders **/
64
#define RANGE  0x0100
65
/** @brief Initialize the BOM **/
66
#define BOM  0x0200
67
/** @brief Initilize encoders **/
68
#define ENCODERS 0x400
69
/** @brief Initialize everything  **/
70
#define ALL_ON 0x07FF
71

  
72
/** @brief Initialize the board **/
73
void dragonfly_init(int config);
74

  
75
/** @} **/ //end addtogroup
76

  
77
#include <inttypes.h>
78
#include <avr/io.h>
79
#include <avr/interrupt.h>
80
#include <util/delay.h>
81
#include <util/twi.h>
82

  
83
// This file is included from the libdragonfly directory because it seems to be
84
// missing from the AVR libc distribution.
85
#include "atomic.h"
86

  
87
#include "analog.h"
88
#include "dio.h"
89
#include "time.h"
90
#include "lcd.h"
91
#include "lights.h"
92
#include "motor.h"
93
#include "serial.h"
94
#include "buzzer.h"
95
#include "rangefinder.h"
96
#include "bom.h"
97
#include "encoders.h"
98
#include "move.h"
99
#include "reset.h"
100
#include "math.h"
101
#include "eeprom.h"
102

  
103
#include <stddef.h>
104
#include <stdbool.h>
105

  
106
/** @brief shortcut for ATOMIC_BLOCK(ATOMIC_RESTORESTATE) **/
107
#define SYNC ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
108

  
109
/** @brief atomically grab a lock if it is free, return otherwise **/
110
#define REQUIRE_LOCK_OR_RETURN(LOCK) do { SYNC { if (LOCK) return; LOCK=1; } } while (0)
111

  
112
/** @brief atomically release a lock **/
113
#define RELEASE_LOCK(LOCK) do { LOCK=0; } while (0)
114

  
115

  
116

  
117
#endif
118

  
branches/ir_branch/lib/include/libdragonfly/atomic.h
1
/* This file is in the dragonfly library directory because it seems to be
2
   missing from the AVR libc distribution */
3
   
4
/* Copyright (c) 2007 Dean Camera
5
   All rights reserved.
6

  
7
   Redistribution and use in source and binary forms, with or without
8
   modification, are permitted provided that the following conditions are met:
9

  
10
   * Redistributions of source code must retain the above copyright
11
     notice, this list of conditions and the following disclaimer.
12

  
13
   * Redistributions in binary form must reproduce the above copyright
14
     notice, this list of conditions and the following disclaimer in
15
     the documentation and/or other materials provided with the
16
     distribution.
17

  
18
   * Neither the name of the copyright holders nor the names of
19
     contributors may be used to endorse or promote products derived
20
     from this software without specific prior written permission.
21

  
22
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26
  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27
  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
  POSSIBILITY OF SUCH DAMAGE.
33
*/
34

  
35
/* $Id: atomic.h,v 1.3 2007/12/20 14:17:56 joerg_wunsch Exp $ */
36

  
37
#ifndef _UTIL_ATOMIC_H_
38
#define _UTIL_ATOMIC_H_ 1
39

  
40
#include <avr/io.h>
41
#include <avr/interrupt.h>
42

  
43
#if !defined(__DOXYGEN__)
44
/* Internal helper functions. */
45
static __inline__ uint8_t __iSeiRetVal(void)
46
{
47
    sei();
48
    return 1;
49
}
50

  
51
static __inline__ uint8_t __iCliRetVal(void)
52
{
53
    cli();
54
    return 1;
55
}
56

  
57
static __inline__ void __iSeiParam(const uint8_t *__s)
58
{
59
    sei();
60
    __asm__ volatile ("" ::: "memory");
61
    (void)__s;
62
}
63

  
64
static __inline__ void __iCliParam(const uint8_t *__s)
65
{
66
    cli();
67
    __asm__ volatile ("" ::: "memory");
68
    (void)__s;
69
}
70

  
71
static __inline__ void __iRestore(const  uint8_t *__s)
72
{
73
    SREG = *__s;
74
    __asm__ volatile ("" ::: "memory");
75
}
76
#endif	/* !__DOXYGEN__ */
77

  
78
/** \file */
79
/** \defgroup util_atomic <util/atomic.h> Atomically and Non-Atomically Executed Code Blocks
80

  
81
    \code
82
    #include <util/atomic.h>
83
    \endcode
84

  
85
    \note The macros in this header file require the ISO/IEC 9899:1999
86
    ("ISO C99") feature of for loop variables that are declared inside
87
    the for loop itself.  For that reason, this header file can only
88
    be used if the standard level of the compiler (option --std=) is
89
    set to either \c c99 or \c gnu99.
90

  
91
    The macros in this header file deal with code blocks that are
92
    guaranteed to be excuted Atomically or Non-Atmomically.  The term
93
    "Atomic" in this context refers to the unability of the respective
94
    code to be interrupted.
95

  
96
    These macros operate via automatic manipulation of the Global
97
    Interrupt Status (I) bit of the SREG register. Exit paths from
98
    both block types are all managed automatically without the need
99
    for special considerations, i. e. the interrupt status will be
100
    restored to the same value it has been when entering the
101
    respective block.
102

  
103
    A typical example that requires atomic access is a 16 (or more)
104
    bit variable that is shared between the main execution path and an
105
    ISR.  While declaring such a variable as volatile ensures that the
106
    compiler will not optimize accesses to it away, it does not
107
    guarantee atomic access to it.  Assuming the following example:
108

  
109
    \code
110
#include <inttypes.h>
111
#include <avr/interrupt.h>
112
#include <avr/io.h>
113

  
114
volatile uint16_t ctr;
115

  
116
ISR(TIMER1_OVF_vect)
117
{
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff