Contiki 2.6
|
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 */ 00035 00036 #ifndef __RS232_H__ 00037 #define __RS232_H__ 00038 00039 #include <avr/pgmspace.h> 00040 #include "contiki-conf.h" 00041 00042 #if defined (__AVR_ATmega128__) 00043 #include "dev/rs232_atmega128.h" 00044 #elif defined (__AVR_ATmega1281__) 00045 #include "dev/rs232_atmega1281.h" 00046 #elif defined (__AVR_ATmega1284P__) 00047 #include "dev/rs232_atmega1284.h" 00048 #elif defined (__AVR_AT90USB1287__) 00049 #include "dev/rs232_at90usb1287.h" 00050 #elif defined (__AVR_ATmega128RFA1__) 00051 #include "dev/rs232_atmega128rfa1.h" 00052 #elif defined (__AVR_ATmega644__) || defined (__AVR_ATmega328P__) 00053 #include "dev/rs232_atmega644.h" 00054 #elif defined (__AVR_ATmega8__) || defined (__AVR_ATmega8515__) \ 00055 || defined (__AVR_ATmega16__) || defined (__AVR_ATmega32__) 00056 #include "dev/rs232_atmega32.h" 00057 #else 00058 #error "Please implement a rs232 header for your MCU (or set the MCU type \ 00059 in contiki-conf.h)." 00060 #endif 00061 00062 /******************************************************************************/ 00063 /*** Baud rates */ 00064 /******************************************************************************/ 00065 #define BAUD_RATE(x) (F_CPU/16/x-1) 00066 00067 /** 00068 * \brief Initialize the RS232 module 00069 * 00070 * This function is called from the boot up code to 00071 * initalize the RS232 module. 00072 * \param port The RS232 port to be used. 00073 * \param bd The baud rate of the connection. 00074 * \param ffmt The frame format of the connection, i.e. parity mode, 00075 * number of stop and data bits, ... 00076 */ 00077 void 00078 rs232_init (uint8_t port, uint8_t bd, uint8_t ffmt); 00079 00080 /** 00081 * \brief Set an input handler for incoming RS232 data 00082 * \param port The RS232 port to be used. 00083 * \param f A pointer to a byte input handler 00084 * 00085 * This function sets the input handler for incoming RS232 00086 * data. The input handler function is called for every 00087 * incoming data byte. The function is called from the 00088 * RS232 interrupt handler, so care must be taken when 00089 * implementing the input handler to avoid race 00090 * conditions. 00091 * 00092 * The return value of the input handler affects the sleep 00093 * mode of the CPU: if the input handler returns non-zero 00094 * (true), the CPU is awakened to let other processing 00095 * take place. If the input handler returns zero, the CPU 00096 * is kept sleeping. 00097 */ 00098 void 00099 rs232_set_input(uint8_t port, int (* f)(unsigned char)); 00100 00101 00102 /** 00103 * \brief Print a text string from program memory on RS232 00104 * \param port The RS232 port to be used. 00105 * \param buf A pointer to the string that is to be printed 00106 * 00107 * This function prints a string from program memory to 00108 * RS232. The string must be terminated by a null 00109 * byte. The RS232 module must be correctly initalized and 00110 * configured for this function to work. 00111 */ 00112 void 00113 rs232_print(uint8_t port, char *buf); 00114 00115 /** 00116 * \brief Print a formated string on RS232 00117 * \param port The RS232 port to be used. 00118 * \param fmt The format string that is used to construct the string 00119 * from a variable number of arguments. 00120 * 00121 * This function prints a formated string to RS232. Note 00122 * that this function used snprintf internally and thus cuts 00123 * the resulting string after RS232_PRINTF_BUFFER_LENGTH - 1 00124 * bytes. You can override this buffer lenght with the 00125 * RS232_CONF_PRINTF_BUFFER_LENGTH define. The RS232 module 00126 * must becorrectly initalized and configured for this 00127 * function to work. 00128 */ 00129 void 00130 rs232_printf(uint8_t port, const char *fmt, ...); 00131 00132 /** 00133 * \brief Print a character on RS232 00134 * \param port The RS232 port to be used. 00135 * \param c The character to be printed 00136 * 00137 * This function prints a character to RS232. The RS232 00138 * module must be correctly initalized and configured for 00139 * this function to work. 00140 */ 00141 void 00142 rs232_send(uint8_t port, unsigned char c); 00143 00144 /** 00145 * \brief Redirects stdout to a given RS232 port 00146 * \param port The RS232 port to be used. 00147 * 00148 * This function redirects the stdout channel to a given 00149 * RS232 port. Note that this modfies the global variable 00150 * stdout. If you want to restore the previous behaviour, it 00151 * is your responsibility to backup to old value. The RS232 00152 * module must be correctly initalized and configured for 00153 * the redirection to work. 00154 */ 00155 void 00156 rs232_redirect_stdout (uint8_t port); 00157 00158 #endif /* __RS232_H__ */