Contiki 3.x
rs232.h
1 /*
2  * Copyright (c) 2005, Swedish Institute of Computer Science
3  * All rights reserved.
4  *
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.
16  *
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.
28  *
29  * This file is part of the Contiki operating system.
30  *
31  * Author: Adam Dunkels <adam@sics.se>
32  * Simon Barner <barner@in.tum.de>
33  *
34  */
35 
36 #ifndef RS232_H_
37 #define RS232_H_
38 
39 #include <avr/pgmspace.h>
40 #include "contiki-conf.h"
41 
42 #if defined (__AVR_ATmega128__)
43 #include "dev/rs232_atmega128.h"
44 #elif defined (__AVR_ATmega1281__)
45 #include "dev/rs232_atmega1281.h"
46 #elif defined (__AVR_ATmega1284P__)
47 #include "dev/rs232_atmega1284.h"
48 #elif defined (__AVR_AT90USB1287__)
49 #include "dev/rs232_at90usb1287.h"
50 #elif defined (__AVR_ATmega128RFA1__)
52 #elif defined (__AVR_ATmega128RFR2__)
54 #elif defined (__AVR_ATmega256RFR2__)
56 #elif defined (__AVR_ATmega644__) || defined (__AVR_ATmega328P__)
57 #include "dev/rs232_atmega644.h"
58 #elif defined (__AVR_ATmega8__) || defined (__AVR_ATmega8515__) \
59  || defined (__AVR_ATmega16__) || defined (__AVR_ATmega32__)
60 #include "dev/rs232_atmega32.h"
61 #else
62 #error "Please implement a rs232 header for your MCU (or set the MCU type \
63 in contiki-conf.h)."
64 #endif
65 
66 /******************************************************************************/
67 /*** Baud rates */
68 /******************************************************************************/
69 #define BAUD_RATE(x) (F_CPU/16/x-1)
70 
71 /**
72  * \brief Initialize the RS232 module
73  *
74  * This function is called from the boot up code to
75  * initalize the RS232 module.
76  * \param port The RS232 port to be used.
77  * \param bd The baud rate of the connection.
78  * \param ffmt The frame format of the connection, i.e. parity mode,
79  * number of stop and data bits, ...
80  */
81 void
82 rs232_init (uint8_t port, uint8_t bd, uint8_t ffmt);
83 
84 /**
85  * \brief Set an input handler for incoming RS232 data
86  * \param port The RS232 port to be used.
87  * \param f A pointer to a byte input handler
88  *
89  * This function sets the input handler for incoming RS232
90  * data. The input handler function is called for every
91  * incoming data byte. The function is called from the
92  * RS232 interrupt handler, so care must be taken when
93  * implementing the input handler to avoid race
94  * conditions.
95  *
96  * The return value of the input handler affects the sleep
97  * mode of the CPU: if the input handler returns non-zero
98  * (true), the CPU is awakened to let other processing
99  * take place. If the input handler returns zero, the CPU
100  * is kept sleeping.
101  */
102 void
103 rs232_set_input(uint8_t port, int (* f)(unsigned char));
104 
105 
106 /**
107  * \brief Print a text string from program memory on RS232
108  * \param port The RS232 port to be used.
109  * \param buf A pointer to the string that is to be printed
110  *
111  * This function prints a string from program memory to
112  * RS232. The string must be terminated by a null
113  * byte. The RS232 module must be correctly initalized and
114  * configured for this function to work.
115  */
116 void
117 rs232_print(uint8_t port, char *buf);
118 
119 /**
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.
124  *
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.
132  */
133 void
134 rs232_printf(uint8_t port, const char *fmt, ...);
135 
136 /**
137  * \brief Print a character on RS232
138  * \param port The RS232 port to be used.
139  * \param c The character to be printed
140  *
141  * This function prints a character to RS232. The RS232
142  * module must be correctly initalized and configured for
143  * this function to work.
144  */
145 void
146 rs232_send(uint8_t port, unsigned char c);
147 
148 /**
149  * \brief Redirects stdout to a given RS232 port
150  * \param port The RS232 port to be used.
151  *
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.
158  */
159 void
160 rs232_redirect_stdout (uint8_t port);
161 
162 #endif /* RS232_H_ */
AVR specific definitions for the rs232 port.
void rs232_send(char c)
Print a character on RS232.
Definition: rs232.c:61
void rs232_print(char *text)
Print a text string on RS232.
Definition: rs232.c:66
AVR specific definitions for the rs232 port.
AVR specific definitions for the rs232 port.
AVR specific definitions for the rs232 port.
void rs232_init(void)
Initialize the RS232 module.
Definition: rs232.c:51
AVR specific definitions for the rs232 port.
AVR specific definitions for the rs232 port.
void rs232_set_input(int(*f)(unsigned char))
Set an input handler for incoming RS232 data.
Definition: rs232.c:56
AVR specific definitions for the rs232 port.