Project

General

Profile

Statistics
| Revision:

root / trunk / code / projects / libdragonfly / serial.h @ 1461

History | View | Annotate | Download (4.39 KB)

1 8 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 8 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 380 jknichel
  serial.h - Contains definitions and function prototypes for the RS232 serial port
40 8 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 380 jknichel
  usb_*() -> UART0
49
  xbee_*() -> UART1
50 8 bcoltin

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