Project

General

Profile

Statistics
| Revision:

root / branches / library_refactor / projects / libdragonfly / serial.h @ 1084

History | View | Annotate | Download (4.24 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
/** @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
/** @brief Determine a hexadecimal digit **/
99
uint8_t hex_digit (uint8_t value);
100
/** @brief Print a fixed width hexadecimal representation to USB **/
101
void usb_puth16 (uint16_t value);
102
/** @brief Print a fixed width hexadecimal representation to USB **/
103
void usb_puth8(uint8_t value);
104
/** @brief Alias for usb_puth16 **/
105
static inline void usb_puth (uint16_t value) { usb_puth16 (value); };
106

    
107

    
108
/** @} **/ //end addtogroup
109

    
110
/**
111
 * @defgroup xbee XBee Input / Output
112
 * @brief Functions for XBee input / output
113
 *
114
 * Low level functions for XBee input and output.
115
 *
116
 * @{
117
 **/
118

    
119
// if no baud rate is defined for usb, default is set here
120

    
121
// if no baud rate is defined for xbee, default is set here
122
#ifndef XBEE_BAUD
123
/** @brief the XBee baud rate **/
124
#define XBEE_BAUD 9600
125
#endif
126

    
127
/** @brief Initialize the XBee **/
128
void xbee_init(void);
129
/** @brief Print a character to the XBee **/
130
int xbee_putc(char c);
131
/** @brief Read a character from the XBee **/
132
int xbee_getc(void);
133
/** @brief Read a character from the XBee without blocking **/
134
int xbee_getc_nb(char *c);
135

    
136

    
137

    
138
/** @} **/ //end addtogroup
139

    
140
#endif
141