* Addition of Meshnetics Zigbig platform by Frederic Thepaut <frederic.thepaut@inooi...
[contiki-2.x.git] / cpu / avr / dev / rs232.h
blobb8491e93a67e277a0525c2a0d43509b8d9cb6f38
1 /*
2 * Copyright (c) 2005, Swedish Institute of Computer Science
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the Institute nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
29 * This file is part of the Contiki operating system.
31 * Author: Adam Dunkels <adam@sics.se>
32 * Simon Barner <barner@in.tum.de>
34 * @(#)$Id: rs232.h,v 1.5 2008/11/29 15:55:02 c_oflynn Exp $
37 #ifndef __RS232_H__
38 #define __RS232_H__
40 #include <avr/pgmspace.h>
41 #include "contiki-conf.h"
43 #if defined (__AVR_ATmega128__)
44 #include "dev/rs232_atmega128.h"
45 #elif defined (__AVR_ATmega1281__)
46 #include "dev/rs232_atmega1281.h"
47 #elif defined (__AVR_ATmega1284P__)
48 #include "dev/rs232_atmega1284.h"
49 #elif defined (__AVR_AT90USB1287__)
50 #include "dev/rs232_at90usb1287.h"
51 #elif defined (__AVR_ATmega1281__)
52 #include "dev/rs232_atmega1281.h"
53 #else
54 #error "Please implement a rs232 header for your MCU (or set the MCU type \
55 in contiki-conf.h)."
56 #endif
58 /**
59 * \brief Initialize the RS232 module
61 * This function is called from the boot up code to
62 * initalize the RS232 module.
63 * \param port The RS232 port to be used.
64 * \param bd The baud rate of the connection.
65 * \param ffmt The frame format of the connection, i.e. parity mode,
66 * number of stop and data bits, ...
68 void
69 rs232_init (uint8_t port, uint8_t bd, uint8_t ffmt);
71 /**
72 * \brief Set an input handler for incoming RS232 data
73 * \param port The RS232 port to be used.
74 * \param f A pointer to a byte input handler
76 * This function sets the input handler for incoming RS232
77 * data. The input handler function is called for every
78 * incoming data byte. The function is called from the
79 * RS232 interrupt handler, so care must be taken when
80 * implementing the input handler to avoid race
81 * conditions.
83 * The return value of the input handler affects the sleep
84 * mode of the CPU: if the input handler returns non-zero
85 * (true), the CPU is awakened to let other processing
86 * take place. If the input handler returns zero, the CPU
87 * is kept sleeping.
89 void
90 rs232_set_input(uint8_t port, int (* f)(unsigned char));
93 /**
94 * \brief Print a text string from program memory on RS232
95 * \param port The RS232 port to be used.
96 * \param buf A pointer to the string that is to be printed
98 * This function prints a string from program memory to
99 * RS232. The string must be terminated by a null
100 * byte. The RS232 module must be correctly initalized and
101 * configured for this function to work.
103 void
104 rs232_print_p(uint8_t port, prog_char *buf);
107 * \brief Print a text string on RS232
108 * \param port The RS232 port to be used.
109 * \param str A pointer to the string that is to be printed
111 * This function prints a string to RS232. The string must
112 * be terminated by a null byte. The RS232 module must be
113 * correctly initalized and configured for this function
114 * to work.
116 void
117 rs232_print(uint8_t port, char *buf);
120 * \brief Print a formated string on RS232
121 * \param port The RS232 port to be used.
122 * \param fmt The format string that is used to construct the string
123 * from a variable number of arguments.
125 * This function prints a formated string to RS232. Note
126 * that this function used snprintf internally and thus cuts
127 * the resulting string after RS232_PRINTF_BUFFER_LENGTH - 1
128 * bytes. You can override this buffer lenght with the
129 * RS232_CONF_PRINTF_BUFFER_LENGTH define. The RS232 module
130 * must becorrectly initalized and configured for this
131 * function to work.
133 void
134 rs232_printf(uint8_t port, const char *fmt, ...);
137 * \brief Print a character on RS232
138 * \param port The RS232 port to be used.
139 * \param c The character to be printed
141 * This function prints a character to RS232. The RS232
142 * module must be correctly initalized and configured for
143 * this function to work.
145 void
146 rs232_send(uint8_t port, unsigned char c);
149 * \brief Redirects stdout to a given RS232 port
150 * \param port The RS232 port to be used.
152 * This function redirects the stdout channel to a given
153 * RS232 port. Note that this modfies the global variable
154 * stdout. If you want to restore the previous behaviour, it
155 * is your responsibility to backup to old value. The RS232
156 * module must be correctly initalized and configured for
157 * the redirection to work.
159 void
160 rs232_redirect_stdout (uint8_t port);
162 #endif /* __RS232_H__ */