Project

General

Profile

Revision 881

Moved headers to include directory.

View differences:

branches/simulator/projects/libdragonfly/bom.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 bom.h
29
 * @brief Definitions for using the BOM
30
 * 
31
 * This file contains definitions for using the Bearing and 
32
 * Orientation Module (BOM).
33
 *
34
 * @author Colony Project, CMU Robotics Club
35
 *
36
 **/
37

  
38
#ifndef _BOM_H
39
#define _BOM_H
40

  
41
/**
42
 * @addtogroup bom
43
 * @{
44
 **/
45
 
46
/** @brief Include all elements in the 16-bit bitfield **/
47
#define BOM_ALL 0xFFFF
48
/** @brief Original BOM - No Range, No Individual LED control **/
49
#define BOM     0
50
/** @brief BOM 1.5 - No Range, Individual LED control **/
51
#define BOM15   1
52
/** @brief RBOM - Range, Individual LED control **/
53
#define RBOM    2
54
 
55
/** @brief Initialize the bom according to bom type **/
56
void bom_init(char type);
57
/** @brief Refresh bom_val[] with new values from analog8.  analog_init and bom_init must be called for this to work. **/
58
void bom_refresh(int bit_field);
59
/** @brief Gets the bom reading from bom_val[which].  Call bom_refresh beforehand to read new bom values. **/
60
int bom_get(int which);
61
/** @brief Compares all the values in bom_val[] and returns the index to the highest value element. **/
62
int bom_get_max(void);
63
/** @brief Turns on the selected bom leds. Only works with BOM_ALL if using the original bom. **/
64
void bom_leds_on(int bit_field);
65
/** @brief Turns off the selected bom leds. Only works with BOM_ALL if using the original bom. **/
66
void bom_leds_off(int bit_field);
67

  
68
/** @brief (DEPRECATED) Wrapper function. See bom_refresh and bom_get_max **/
69
int get_max_bom(void);
70
/** @brief (DEPRECATED) Wrapper function. See bom_leds_on. **/
71
void bom_on(void);
72
/** @brief (DEPRECATED) Wrapper function. See bom_leds_off. **/
73
void bom_off(void);
74

  
75
/** @} **/
76

  
77
#endif
78

  
branches/simulator/projects/libdragonfly/time.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 time.h
29
 * @brief Contains time-related functions and definitions
30
 *
31
 * Contains functions and definitions for dealing with time,
32
 * namely delay_ms and the realtime clock.
33
 *
34
 * @author Colony Project, CMU Robotics Club
35
 **/
36

  
37
#ifndef _TIME_H_
38
#define _TIME_H_
39

  
40
/*	Predefined times for prescale_opt in time.c.
41
	To make you own, know that a pulse is 1/16th of a second. You cannot get less than this. To get more, you need
42
	to know how many 16ths of a second are in the time you want. (Time_desired * 16 = prescaler_opt)
43
*/
44
/**
45
 * @addtogroup time
46
 * @{
47
 **/
48
/** @brief A sixteenth of a second **/
49
#define SIXTEENTH_SECOND 1
50
/** @brief An eighth of a second **/
51
#define EIGTH_SECOND 2
52
/** @brief A quarter of a second **/
53
#define QUARTER_SECOND 4
54
/** @brief Half of a second **/
55
#define HALF_SECOND	8
56
/** @brief One second **/
57
#define SECOND 16
58
/** @brief Two seconds **/
59
#define TWO_SECOND 32
60
/** @brief Four seconds **/
61
#define FOUR_SECOND 64
62

  
63
/** @brief Delay execution for the specified time **/
64
void delay_ms(int ms) ;
65
/** @brief Enable the realtime clock **/
66
void rtc_init(int prescale_opt, void (*rtc_func)(void));
67
/** @brief Reset the counter of the realtime clock **/
68
void rtc_reset(void);
69
/** @brief Get the value of the realtime clock. **/
70
int rtc_get(void);
71

  
72
/** @} **/
73

  
74
#endif
75

  
branches/simulator/projects/libdragonfly/i2c.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 i2c.h
28
 *  @brief Header file for I2C
29
 *
30
 *  Contains functions for I2C.
31
 *
32
 *  @author Kevin Woo and Suresh Nidhiry, Colony Project, CMU Robotics Club
33
 **/
34

  
35

  
36
#ifndef _I2C_H_
37
#define _I2C_H_
38

  
39
#include <stddef.h>
40

  
41
/** @brief Address of slave receive handler function **/
42
typedef void (*fun_srecv_t)(char);
43

  
44
/** @brief Address of master receive handler function**/
45
typedef int (*fun_mrecv_t)(char);
46

  
47
/** @brief Address of slave send handler function**/
48
typedef char (*fun_send_t)(void);
49

  
50
int i2c_init(char addr, fun_mrecv_t master_recv, fun_srecv_t slave_recv, fun_send_t slave_send);
51
int i2c_send(char dest, char* data, size_t bytes);
52
int i2c_request(char dest);
53

  
54
void i2c_packet_rec (char i2c_byte);
55
void i2c_packet_sniff(char data);
56
#endif
57

  
branches/simulator/projects/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/simulator/projects/libdragonfly/lcd.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 lcd.h
29
 * @brief Contains definitions for dealing with the LCD screen.
30
 * 
31
 * Contains definitions and functions for dealing with the 
32
 * LCD screen.
33
 *
34
 * @author Colony Project, CMU Robotics Club
35
 **/
36

  
37
#ifndef _LCD_H_
38
#define _LCD_H_
39

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

  
45
/** @brief Initialize the LCD screen **/
46
void lcd_init(void);
47
/** @brief Clear the LCD screen **/
48
void lcd_clear_screen( void );
49
/** @brief Print a char to the LCD screen **/
50
void lcd_putc(char c);
51
/** @brief Print a string to the LCD screen **/
52
void lcd_puts(char *s);
53
/** @brief Print an int to the LCD screen **/
54
void lcd_puti(int value);
55
/** @brief Set the current cursor position **/
56
void lcd_gotoxy(int x, int y);
57

  
58
/** @} **/
59

  
60
#endif
61

  
branches/simulator/projects/libdragonfly/encoders.h
1
/**
2
 * 
3
 * @file encoders.h
4
 * @brief Contains functions for reading encoder values.
5
 *
6
 * Contains high and low level functions for reading encoders
7
 * including reading out total distance covered, and 
8
 * eventually velocity.
9
 *	
10
 * @author Colony Project, CMU Robotics Club
11
*/
12

  
13
/**
14
 * @addtogroup encoders
15
 * @{
16
 **/
17

  
18
#ifndef __ENCODERS_H__
19
#define __ENCODERS_H__
20

  
21

  
22
#ifndef LEFT
23
	#define LEFT 0
24
#endif
25
#ifndef RIGHT
26
	#define RIGHT 1
27
#endif
28

  
29
/** @brief Magnet misaligned - likely distance from encoder problem. **/
30
#define ENCODER_MAGNET_FAILURE 1025
31
/** @brief Encoder misaligned - likely on XY plane. **/
32
#define ENCODER_MISALIGNED 1027
33
/** @brief Not enough time has passed - encoders not initialized in hardware. **/
34
#define ENCODER_DATA_NOT_READY 1026
35

  
36
//delay_ms argument after a full read is complete
37
#define ENCODER_DELAY 20
38

  
39
#define MIN_V (-100)
40
#define MAX_V 100
41

  
42
//Data invalid flags (hardware failure):
43
#define OCF _BV(4)
44
#define COF _BV(3)
45

  
46
//Data invalid alarm (May be invalid):
47
#define LIN _BV(2)
48

  
49
#define MagINCn _BV(1)
50
#define MagDECn _BV(0)
51

  
52
#define BUFFER_SIZE 23
53

  
54
/** @brief Initialize encoders. **/
55
void encoders_init(void);
56
/** @brief Read instantaneous encoder value. **/
57
int encoder_read(char encoder);
58

  
59
/** @brief Get total distance traveled. **/
60
int encoder_get_dx(char encoder);
61
/** @brief Reset distance counter. **/
62
void encoder_rst_dx(char encoder);
63
/** @brief Get time count: The number of encoder reads that have occurred. **/
64
int encoder_get_tc(void);
65
/** @brief Reset the time count. **/
66
void encoder_rst_tc(void);
67

  
68
/** @brief Waits for the next n encoder reading, then returns. **/
69
void encoder_wait( int nReadings );
70

  
71
/**@}**/ //end group
72

  
73
#endif
branches/simulator/projects/libdragonfly/motor.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 motor.h
29
 * @brief Contains definitions for controlling the motors
30
 *
31
 * Contains definitions and functions for controlling
32
 * the motors.
33
 *
34
 * @author Colony Project, CMU Robotics Club
35
 * Based on Tom Lauwer's Firefly Library
36
 **/
37

  
38
#ifndef _MOTOR_H
39
#define _MOTOR_H
40

  
41
#include <avr/io.h>
42
/**
43
 * @addtogroup motors
44
 * @{
45
 **/
46

  
47
/** @brief make the motors go forwards **/
48
#define FORWARD 1
49
/** @brief make the motors go backwards **/
50
#define BACKWARD 0
51

  
52
/** @brief Initialize the motors **/
53
void motors_init(void);
54
/** @brief Set speed and direction of motor1 **/
55
void motor1_set(int direction, int speed);
56
/** @brief Set speed and direction of motor2 **/
57
void motor2_set(int direction, int speed);
58
/** @brief Turn the motors off **/
59
void motors_off(void);
60

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

  
63
#endif
64

  
branches/simulator/projects/libdragonfly/reset.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
 * 
29
 * @file reset.h
30
 * @brief Contains function(s) for resetting the robots
31
 * 
32
 * @author Colony Project, CMU Robotics Club, James Kong
33
 */
34

  
35
#ifndef _RESET_H_
36
#define _RESET_H_
37

  
38
/**
39
 * @addtogroup reset
40
 * @{
41
 **/
42
 
43
/** @brief Reset the robot **/
44
void reset(void);
45

  
46
/**@}**/ //end group
47

  
48
#endif
49

  
branches/simulator/projects/libdragonfly/analog.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 analog.h
29
 * @brief Contains functions and definitions for using the ADC
30
 * 
31
 * Contains definitions and function prototypes for using the
32
 * ADC to detect analog signals on pins AN0 - AN7.
33
 * AN6 and AN7 are used for the wheel and battery.
34
	
35
 * The pins labeled E6 and E7 are external interrupt pins and are not related 
36
 * to analog.
37
	
38
 * @author Colony Project, CMU Robotics Club, based on firefly
39
 * code by Tom Lauwers
40
 */
41

  
42
#ifndef _ANALOG_H
43
#define _ANALOG_H
44

  
45
#include <inttypes.h>
46

  
47
/**
48
 * @addtogroup analog
49
 * @{
50
 **/
51

  
52
/** @brief Analog port 0 **/
53
#define AN0 0x00
54
/** @brief Analog port 1 **/
55
#define AN1 0x01
56
/** @brief Analog port 2 **/
57
#define AN2 0x02
58
/** @brief Analog port 3 **/
59
#define AN3 0x03
60
/** @brief Analog port 4 **/
61
#define AN4 0x04
62
/** @brief Analog port 5 **/
63
#define AN5 0x05
64
/** @brief Analog port 6 **/
65
#define AN6 0x06
66
/** @brief Analog port 7 **/
67
#define AN7 0x07
68
/** @brief Analog port 8 **/
69
#define AN8 0x08
70
/** @brief Analog port 9 **/
71
#define AN9 0x09
72
/** @brief Analog port 10 **/
73
#define AN10 0x0A
74
/** @brief Analog port 11 **/
75
#define AN11 0x0B
76
/** @brief Analog port 12 **/
77
#define AN12 0x0C
78
/** @brief Analog port 13 **/
79
#define AN13 0x0D
80
/** @brief Analog port 14 **/
81
#define AN14 0x0E
82
/** @brief Analog port 15 **/
83
#define AN15 0x0F
84

  
85
/** @brief BOM_PORT analog port for BOM **/
86
#define BOM_PORT AN0
87
/** @brief EXT_MUX analog port **/
88
#define EXT_MUX AN7
89
/** @brief Analog port for the wheel **/
90
#define WHEEL_PORT AN10
91
/** @brief Analog port for the battery voltage detector **/
92
#define BATT_PORT  AN11
93

  
94
#define ADC_START 1
95
#define ADC_STOP 0
96

  
97
#define ADMUX_OPT 0x60
98

  
99
/** @brief Struct to hold the value of a particular analog port **/
100
typedef struct {
101
  uint8_t adc8;
102
  uint16_t adc10;
103
} adc_t;
104

  
105

  
106
/** @brief Initialize analog ports. Will start running a loop
107
    if start_conversion is ADC_START.**/
108
void analog_init(int start_conversion);
109
/** @brief starts the analog loop. Doesn't do anything if the loop is already running. **/
110
void analog_start_loop(void);
111
/** @brief Stops the analog loop. Doesn't do anything if the loop is already stopped. **/
112
void analog_stop_loop(void);
113
/** @brief Returns an 8-bit analog value from the look up table. Use this instead of analog_get8. **/
114
unsigned int analog8(int which);
115
/** @brief Returns an 10-bit analog value from the look up table. Use this instead of analog_get10. **/
116
unsigned int analog10(int which);
117
/** @brief Read the position of the wheel. **/
118
int wheel(void);
119
/** @brief Read an 8-bit number from an analog port. Loop must be stopped for this to work. **/
120
unsigned int analog_get8(int which);
121
/** @brief Read a 10-bit number from an analog port. Loop must be stopped for this to work. **/
122
unsigned int analog_get10(int which);
123

  
124

  
125
/**@}**/ //end group
126

  
127
#endif
128

  
branches/simulator/projects/libdragonfly/buzzer.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 buzzer.h
29
 * @brief Contains definitions for using the buzzer.
30
 *
31
 * Contains definitions for using the buzzer built into
32
 * the colony robots.
33
 *
34
 * @author Colony Project, CMU Robotics Club
35
 **/
36

  
37
#ifndef _BUZZER_H_
38
#define _BUZZER_H_
39

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

  
45
//Musical note definitions
46
//Source: http://www.answers.com/topic/piano-key-frequencies
47
/** @brief Middle C **/
48
#define	C4	260 //Middle C
49
/** @brief C# **/
50
#define	C4s	277 //C sharp
51
/** @brief D **/
52
#define	D4	294
53
/** @brief D# **/
54
#define	D4s	311
55
/** @brief E **/
56
#define	E4	330
57
/** @brief F **/
58
#define	F4	349
59
/** @brief F# **/
60
#define	F4s	370
61
/** @brief G **/
62
#define	G4	392
63
/** @brief G# **/
64
#define	G4s	415
65
/** @brief A **/
66
#define	A4	440
67
/** @brief A# **/
68
#define	A4s	466
69
/** @brief B **/
70
#define	B4	494
71
/** @brief C **/
72
#define	C5	523
73

  
74
/** @brief Initialize the buzzer. **/
75
void buzzer_init(void);
76
/** @brief Set the value the buzzer plays. **/
77
void buzzer_set_val(unsigned int buzz_value);
78
/** @brief Set the frequency the buzzer plays. **/
79
void buzzer_set_freq(unsigned int buzz_freq);
80
/** @brief Play a frequency for a specified time. **/
81
void buzzer_chirp(unsigned int ms, unsigned int buzz_freq);
82
/** @brief Turn the buzzer off. **/
83
void buzzer_off(void); 
84

  
85
/** @} **/ //end addtogroup
86

  
87
#endif
88

  
branches/simulator/projects/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/simulator/projects/libdragonfly/eeprom.h
1
/**
2
 * @file eeprom.h
3
 * @brief handles eeprom storage for persistent data
4
 *
5
 * Contains functions and definitions for reading and writing to eeprom
6
 *
7
 * @author Colony Project, Brad Neuman
8
 */
9
 
10
 #ifndef _EEPROM_H_
11
 #define _EEPROM_H_
12
 
13
 #define EEPROM_ROBOT_ID_ADDR 0x0b
14
 
15
 /** @brief store a byte to eeproem
16
  *  @return 0 if success, nonzero on failure
17
  */
18
 int eeprom_put_byte(unsigned int addr, unsigned char byte);
19
 
20
 /** @brief reads a byte from eeprom
21
  *
22
  *  Pass it thge address and a pointer to a byte where the byte at the
23
  *  address will be stored
24
  *
25
  *  @return 0 if successful (byte is set to the eeprom value at addr), 
26
  *  nonzero if there was a problem
27
   */
28
 int eeprom_get_byte(unsigned int addr, unsigned char *byte);
29
 
30
 /** @brief get stored robot ID
31
  *
32
  *  returnes the value of eerpom at EEPROM_ROBOT_ID_ADDR
33
  *
34
  *  @return the robot id, if it is stored. If it returns 0xff it is probably invalid
35
  */
36
  unsigned char get_robotid(void);
37
 
38
 #endif
39
 
branches/simulator/projects/libdragonfly/serial.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 serial.h
29
 * @brief Contains declarations for serial input and output
30
 *
31
 * Contains definitions for serial input and output.
32
 *
33
 * @author Colony Project, CMU Robotics Club
34
 * Based on Tom Lauwer's Firefly Library
35
 *
36
 **/
37

  
38
/*
39
  serial.h - Contains definitions and function prototypes for the RS232 serial port
40
  author(s): pkv
41
  
42
  Directions:
43
  Call the initialization function for the serial port you wish to use.  Then, use
44
  either the provided functions or the stdio functions (fprintf, etc) to read and
45
  write characters to the serial ports.
46
  
47
  UART Mapping:
48
  usb_*() -> UART0
49
  xbee_*() -> UART1
50
  
51
  Options: (Add the following defines to your code to configure this library)
52
  #define USB_BAUD { 115200 | 9600 } <= pick ONE value from in here
53
  #define XBEE_BAUD { 115200 | 9600 } <= pick ONE value from in here
54
  #define USE_STDIO
55
  
56
  Note: If you enable USE_STDIO, the first init function that is called will 
57
  automatically be linked to stdin, stdout, and stderr.  To use the baud rate 
58
  commands, add something like the following to your code:
59
  
60
  #define FOO_BAUD 9600
61
  
62
  **UNLESS YOU KNOW WHAT YOU ARE DOING, PLEASE DO NOT CHANGE THIS FILE**
63
  Many, many other people use this file in their code.  If you change it, you will
64
  probably break all of their nice code.  You should not need to change anything in
65
  here, except to accomodate new hardware.
66
*/
67

  
68
#ifndef _SERIAL_H
69
#define _SERIAL_H
70

  
71
/**
72
 * @defgroup usb USB Input / Output
73
 * @brief Functions for USB input / output
74
 *
75
 * Low level functions for USB input and output.
76
 *
77
 * @{
78
 **/
79

  
80
// if no baud rate is defined for usb, default is set here
81
#ifndef USB_BAUD
82
/** @brief the USB baud rate **/
83
#define USB_BAUD 115200
84
#endif
85

  
86
/** @brief Initialize the USB **/
87
void usb_init(void);
88
/** @brief Print a character to USB **/
89
int usb_putc(char c);
90
/** @brief Read a character from USB **/
91
int usb_getc(void);
92
/** @brief Read a character from USB without blocking **/
93
int usb_getc_nb(char *c);
94
/** @brief Print a string to USB **/
95
int usb_puts(char *s);
96
/** @brief Print an integer to USB **/
97
int usb_puti(int value);
98

  
99
/** @} **/ //end addtogroup
100

  
101
/**
102
 * @defgroup xbee XBee Input / Output
103
 * @brief Functions for XBee input / output
104
 *
105
 * Low level functions for XBee input and output.
106
 *
107
 * @{
108
 **/
109

  
110
// if no baud rate is defined for usb, default is set here
111

  
112
// if no baud rate is defined for xbee, default is set here
113
#ifndef XBEE_BAUD
114
/** @brief the XBee baud rate **/
115
#define XBEE_BAUD 9600
116
#endif
117

  
118
/** @brief Initialize the XBee **/
119
void xbee_init(void);
120
/** @brief Print a character to the XBee **/
121
int xbee_putc(char c);
122
/** @brief Read a character from the XBee **/
123
int xbee_getc(void);
124
/** @brief Read a character from the XBee without blocking **/
125
int xbee_getc_nb(char *c);
126

  
127
/** @} **/ //end addtogroup
128

  
129
#endif
130

  
branches/simulator/projects/libdragonfly/rangefinder.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 rangefinder.h
29
 * @brief Contains rangefinder declarations and functions
30
 * 
31
 * Contains functions and definitions for the use of
32
 * IR rangefinders.
33
 *
34
 * @author Colony Project, CMU Robotics Club
35
 **/
36

  
37
#ifndef _RANGEFINDER_H_
38
#define _RANGEFINDER_H_
39

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

  
45
/** @brief IR Rangefinder 1 **/
46
#define IR1 6
47
/** @brief IR Rangefinder 2 **/
48
#define IR2 5
49
/** @brief IR Rangefinder 3 **/
50
#define IR3 4
51
/** @brief IR Rangefinder 4 **/
52
#define IR4 3
53
/** @brief IR Rangefinder 5 **/
54
#define IR5 2
55

  
56
/** @brief Initialize the rangefinders **/
57
void range_init(void);
58
/** @brief Read the distance from a rangefinder **/
59
int range_read_distance(int range_id);
60

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

  
63
#endif
64

  
branches/simulator/projects/libdragonfly/ring_buffer.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 ring_buffer.h
28
 * @brief Ring Buffer
29
 *
30
 * Include macros to create a ring buffer. Originally written for 15-410.
31
 * Modified for use in ATMega128 serial driver
32
 *
33
 * @author Cornell Wright (cgwright)
34
 * @author Jason P. Winters (jpwinter)
35
 *
36
 **/
37

  
38
#ifndef _RING_BUFFER_H
39
#define _RING_BUFFER_H
40

  
41
/** @brief Creates the struct for a new ring buffer. This just expands to a
42
 *	structure definition and thus should be invoked in the global context.
43
 *
44
 *	@param struct_name Name of the ring buffer struct.
45
 *
46
 *	@param size The size of the buffer to create.
47
 *
48
 *	@param type The type of object that the queue is to hold.
49
 *
50
 *	@param ... Name or names of the instance or instances of the ring buffer(s)
51
 *	to be created.
52
 */
53
#define RING_BUFFER_NEW(struct_name, size, type, ...)	\
54
	struct struct_name {	\
55
		type queue[size];	\
56
		uint8_t start;			\
57
		uint8_t end;			\
58
		uint8_t buffer_size;			\
59
	} __VA_ARGS__
60

  
61

  
62
/** @brief Initializes the ring buffer, setting its size to the correct value
63
 *
64
 *	@param buf The ring buffer to initialize.
65
 *
66
 *  @param size The size of the ring buffer (in array elements)
67
 */
68
#define RING_BUFFER_INIT(buf, size) 			\
69
	do {										\
70
		(buf).buffer_size = size;				\
71
	} while(0)
72

  
73

  
74
/** @brief Sets the specified ring buffer to be empty.
75
 *
76
 *	@param buf The ring buffer to make empty.
77
 */
78
#define RING_BUFFER_CLEAR(buf)	\
79
	do {						\
80
		(buf).start = 0;		\
81
		(buf).end = 0;			\
82
	} while (0)
83

  
84
/** @brief Returns true if the ring buffer specified is empty.
85
 *
86
 *	@param buf The buffer to check emptiness of.
87
 */
88
#define RING_BUFFER_EMPTY(buf) ((buf).start == (buf).end)
89

  
90

  
91
/** @brief Returns true if the ring buffer specified is full.
92
 *
93
 *	@param buf The buffer to check fullness of.
94
 */
95
#define RING_BUFFER_FULL(buf)	\
96
		(((buf).end + 1) % (buf).buffer_size == (buf).start)
97

  
98

  
99
/** @brief Adds val to ring buffer buf. Note that val must be of the type
100
 *	used in creating the ring buffer to prevent the compiler from spewing
101
 *	confusing errors. Also, this assumes that the ring buffer is not full.
102
 *
103
 *	@param buf The ring buffer to add to.
104
 *	@param val The value to add.
105
 */
106
#define RING_BUFFER_ADD(buf, val)		\
107
	do {								\
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff