rs232.h

00001 /*
00002  * Copyright (c) 2005, Swedish Institute of Computer Science
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the Institute nor the names of its contributors
00014  *    may be used to endorse or promote products derived from this software
00015  *    without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00027  * SUCH DAMAGE.
00028  *
00029  * This file is part of the Contiki operating system.
00030  *
00031  * Author:   Adam Dunkels <adam@sics.se>
00032  *           Simon Barner <barner@in.tum.de>
00033  *
00034  * @(#)$Id: rs232.h,v 1.6 2008/11/29 18:36:12 c_oflynn Exp $
00035  */
00036 
00037 #ifndef __RS232_H__
00038 #define __RS232_H__
00039 
00040 #include <avr/pgmspace.h>
00041 #include "contiki-conf.h"
00042 
00043 #if defined (__AVR_ATmega128__)
00044 #include "dev/rs232_atmega128.h"
00045 #elif defined (__AVR_ATmega1281__)
00046 #include "dev/rs232_atmega1281.h"
00047 #elif defined (__AVR_ATmega1284P__)
00048 #include "dev/rs232_atmega1284.h"
00049 #elif defined (__AVR_AT90USB1287__)
00050 #include "dev/rs232_at90usb1287.h"
00051 #elif defined (__AVR_ATmega128RFA1__)
00052 #include "dev/rs232_atmega128rfa1.h"
00053 #else
00054 #error "Please implement a rs232 header for your MCU (or set the MCU type \
00055 in contiki-conf.h)."
00056 #endif
00057 
00058 /**
00059  * \brief      Initialize the RS232 module
00060  *
00061  *             This function is called from the boot up code to
00062  *             initalize the RS232 module.
00063  * \param port The RS232 port to be used.
00064  * \param bd   The baud rate of the connection.
00065  * \param ffmt The frame format of the connection, i.e. parity mode,
00066  *             number of stop and data bits, ...
00067  */
00068 void
00069 rs232_init (uint8_t port, uint8_t bd, uint8_t ffmt);
00070 
00071 /**
00072  * \brief      Set an input handler for incoming RS232 data
00073  * \param port The RS232 port to be used.
00074  * \param f    A pointer to a byte input handler
00075  *
00076  *             This function sets the input handler for incoming RS232
00077  *             data. The input handler function is called for every
00078  *             incoming data byte. The function is called from the
00079  *             RS232 interrupt handler, so care must be taken when
00080  *             implementing the input handler to avoid race
00081  *             conditions.
00082  *
00083  *             The return value of the input handler affects the sleep
00084  *             mode of the CPU: if the input handler returns non-zero
00085  *             (true), the CPU is awakened to let other processing
00086  *             take place. If the input handler returns zero, the CPU
00087  *             is kept sleeping.
00088  */
00089 void
00090 rs232_set_input(uint8_t port, int (* f)(unsigned char));
00091 
00092 
00093 /**
00094  * \brief      Print a text string from program memory on RS232
00095  * \param port The RS232 port to be used.
00096  * \param buf  A pointer to the string that is to be printed
00097  *
00098  *             This function prints a string from program memory to
00099  *             RS232. The string must be terminated by a null
00100  *             byte. The RS232 module must be correctly initalized and
00101  *             configured for this function to work.
00102  */
00103 void
00104 rs232_print_p(uint8_t port, prog_char *buf);
00105 
00106 /**
00107  * \brief      Print a text string on RS232
00108  * \param port The RS232 port to be used.
00109  * \param str  A pointer to the string that is to be printed
00110  *
00111  *             This function prints a string to RS232. The string must
00112  *             be terminated by a null byte. The RS232 module must be
00113  *             correctly initalized and configured for this function
00114  *             to work.
00115  */
00116 void
00117 rs232_print(uint8_t port, char *buf);
00118 
00119 /**
00120  * \brief      Print a formated string on RS232
00121  * \param port The RS232 port to be used.
00122  * \param fmt  The format string that is used to construct the string
00123  *             from a variable number of arguments.
00124  *
00125  *             This function prints a formated string to RS232. Note
00126  *             that this function used snprintf internally and thus cuts
00127  *             the resulting string after RS232_PRINTF_BUFFER_LENGTH - 1
00128  *             bytes. You can override this buffer lenght with the
00129  *             RS232_CONF_PRINTF_BUFFER_LENGTH define. The RS232 module
00130  *             must becorrectly initalized and configured for this
00131  *             function to work.
00132  */
00133 void
00134 rs232_printf(uint8_t port, const char *fmt, ...);
00135 
00136 /**
00137  * \brief      Print a character on RS232
00138  * \param port The RS232 port to be used.
00139  * \param c    The character to be printed
00140  *
00141  *             This function prints a character to RS232. The RS232
00142  *             module must be correctly initalized and configured for
00143  *             this function to work.
00144  */
00145 void
00146 rs232_send(uint8_t port, unsigned char c);
00147 
00148 /**
00149  * \brief      Redirects stdout to a given RS232 port
00150  * \param port The RS232 port to be used.
00151  *
00152  *             This function redirects the stdout channel to a given
00153  *             RS232 port. Note that this modfies the global variable
00154  *             stdout. If you want to restore the previous behaviour, it
00155  *             is your responsibility to backup to old value. The RS232
00156  *             module must be correctly initalized and configured for
00157  *             the redirection to work.
00158  */
00159 void
00160 rs232_redirect_stdout (uint8_t port);
00161 
00162 #endif /* __RS232_H__ */

Generated on Mon Apr 11 14:23:36 2011 for Contiki 2.5 by  doxygen 1.6.1