root / branches / simulator / projects / libdragonfly / include / serial.h @ 891
History | View | Annotate | Download (6.03 KB)
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 |
/**
|
87 |
* @brief Initialize the USB
|
88 |
*
|
89 |
* Initializes communication over the USB serial port.
|
90 |
* This must be called before any other usb function
|
91 |
* may be used.
|
92 |
**/
|
93 |
void usb_init(void); |
94 |
/**
|
95 |
* @brief Print a character to USB
|
96 |
*
|
97 |
* Sends a character over USB.
|
98 |
*
|
99 |
* @param c the character to send
|
100 |
* @return 0 for success, nonzero for failure
|
101 |
**/
|
102 |
int usb_putc(char c); |
103 |
/**
|
104 |
* @brief Read a character from USB
|
105 |
*
|
106 |
* Returns the first character in the buffer received from USB.
|
107 |
* This function blocks execution until a character has been received.
|
108 |
* usb_init must be called before this function may be used.
|
109 |
*
|
110 |
* @return the first character in the usb buffer
|
111 |
*
|
112 |
* @see usb_init, usb_getc_nb
|
113 |
**/
|
114 |
int usb_getc(void); |
115 |
/**
|
116 |
* @brief Read a character from USB without blocking
|
117 |
*
|
118 |
* Non blocking version of usb_getc. If a character is present in the buffer,
|
119 |
* it is returned, otherwise -1 is returned immediately. usb_init must be
|
120 |
* called before this function can be used.
|
121 |
*
|
122 |
* @param c the received character. This will be set if a character has
|
123 |
* been received.
|
124 |
*
|
125 |
* @return -1 if no character is available, 0 otherwise
|
126 |
*
|
127 |
* @see usb_init, usb_getc
|
128 |
**/
|
129 |
int usb_getc_nb(char *c); |
130 |
/**
|
131 |
* @brief Print a string to USB
|
132 |
*
|
133 |
* Sends a sequence of characters over USB.
|
134 |
*
|
135 |
* @param s the string to send
|
136 |
* @return 0 for success, nonzero for failure
|
137 |
**/
|
138 |
int usb_puts(char *s); |
139 |
/**
|
140 |
* @brief Print an integer to USB
|
141 |
*
|
142 |
* Prints an integer, converted to ASCII, to usb. usb_init must be called
|
143 |
* before this function can be used.
|
144 |
*
|
145 |
* @param value the integer to print
|
146 |
*
|
147 |
* @return 0 if successful, nonzero otherwise
|
148 |
*
|
149 |
* @see usb_init, usb_putc
|
150 |
**/
|
151 |
int usb_puti(int value); |
152 |
|
153 |
/** @} **/ //end addtogroup |
154 |
|
155 |
/**
|
156 |
* @defgroup xbee XBee Input / Output
|
157 |
* @brief Functions for XBee input / output
|
158 |
*
|
159 |
* Low level functions for XBee input and output.
|
160 |
*
|
161 |
* @{
|
162 |
**/
|
163 |
|
164 |
// if no baud rate is defined for usb, default is set here
|
165 |
|
166 |
// if no baud rate is defined for xbee, default is set here
|
167 |
#ifndef XBEE_BAUD
|
168 |
/** @brief the XBee baud rate **/
|
169 |
#define XBEE_BAUD 9600 |
170 |
#endif
|
171 |
|
172 |
/**
|
173 |
* @brief Initialize the XBee
|
174 |
*
|
175 |
* Initializes communication over the XBee.
|
176 |
* This must be called before any other xbee function
|
177 |
* may be used.
|
178 |
**/
|
179 |
void xbee_init(void); |
180 |
/**
|
181 |
* @brief Print a character to the XBee
|
182 |
*
|
183 |
* Sends a character to the XBee.
|
184 |
*
|
185 |
* @param c the character to send
|
186 |
* @return 0 for success, nonzero for failure
|
187 |
**/
|
188 |
int xbee_putc(char c); |
189 |
/**
|
190 |
* @brief Read a character from the XBee
|
191 |
*
|
192 |
* Returns the first character in the buffer received from USB.
|
193 |
* This function blocks execution until a character has been
|
194 |
* received. xbee_init must be called before this function
|
195 |
* may be used.
|
196 |
*
|
197 |
* @return the first character in the xbee buffer
|
198 |
*
|
199 |
* @see xbee_init, xbee_getc_nb
|
200 |
**/
|
201 |
int xbee_getc(void); |
202 |
/**
|
203 |
* @brief Read a character from the XBee without blocking
|
204 |
*
|
205 |
* Non blocking version of xbee_getc. If a character is present in the buffer,
|
206 |
* it is returned, otherwise -1 is returned immediately. xbee_init
|
207 |
* must be called before this function can be used.
|
208 |
*
|
209 |
* @param c the received character. This will be set if a character has
|
210 |
* been received.
|
211 |
*
|
212 |
* @return -1 if no character is available, 0 otherwise
|
213 |
*
|
214 |
* @see xbee_init, xbee_getc
|
215 |
**/
|
216 |
int xbee_getc_nb(char *c); |
217 |
|
218 |
/** @} **/ //end addtogroup |
219 |
|
220 |
#endif
|
221 |
|