Project

General

Profile

Statistics
| Revision:

root / trunk / code / lib / include / libdragonfly / serial.h @ 1155

History | View | Annotate | Download (4.26 KB)

1 7 bcoltin
/**
2 241 bcoltin
 * 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 7 bcoltin
 * @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 437 kwoo
  serial.h - Contains definitions and function prototypes for the RS232 serial port
40 7 bcoltin
  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 437 kwoo
  usb_*() -> UART0
49
  xbee_*() -> UART1
50 7 bcoltin

51
  Options: (Add the following defines to your code to configure this library)
52 437 kwoo
  #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 7 bcoltin

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 1155 deffi
#include <inttypes.h>
72
73 7 bcoltin
/**
74
 * @defgroup usb USB Input / Output
75
 * @brief Functions for USB input / output
76
 *
77
 * Low level functions for USB input and output.
78
 *
79
 * @{
80
 **/
81
82
// if no baud rate is defined for usb, default is set here
83
#ifndef USB_BAUD
84
/** @brief the USB baud rate **/
85
#define USB_BAUD 115200
86
#endif
87
88
/** @brief Initialize the USB **/
89
void usb_init(void);
90
/** @brief Print a character to USB **/
91
int usb_putc(char c);
92
/** @brief Read a character from USB **/
93
int usb_getc(void);
94
/** @brief Read a character from USB without blocking **/
95
int usb_getc_nb(char *c);
96
/** @brief Print a string to USB **/
97
int usb_puts(char *s);
98
/** @brief Print an integer to USB **/
99
int usb_puti(int value);
100 1143 deffi
/** @brief Determine a hexadecimal digit **/
101
uint8_t hex_digit (uint8_t value);
102
/** @brief Print a fixed width hexadecimal representation to USB **/
103
void usb_puth16 (uint16_t value);
104
/** @brief Print a fixed width hexadecimal representation to USB **/
105
void usb_puth8(uint8_t value);
106
/** @brief Alias for usb_puth16 **/
107
static inline void usb_puth (uint16_t value) { usb_puth16 (value); };
108 7 bcoltin
109 1143 deffi
110 7 bcoltin
/** @} **/ //end addtogroup
111
112
/**
113
 * @defgroup xbee XBee Input / Output
114
 * @brief Functions for XBee input / output
115
 *
116
 * Low level functions for XBee input and output.
117
 *
118
 * @{
119
 **/
120
121
// if no baud rate is defined for usb, default is set here
122
123
// if no baud rate is defined for xbee, default is set here
124
#ifndef XBEE_BAUD
125
/** @brief the XBee baud rate **/
126
#define XBEE_BAUD 9600
127
#endif
128
129
/** @brief Initialize the XBee **/
130
void xbee_init(void);
131
/** @brief Print a character to the XBee **/
132
int xbee_putc(char c);
133
/** @brief Read a character from the XBee **/
134
int xbee_getc(void);
135
/** @brief Read a character from the XBee without blocking **/
136
int xbee_getc_nb(char *c);
137
138 1143 deffi
139
140 7 bcoltin
/** @} **/ //end addtogroup
141
142
#endif