root / trunk / bootloader / rs485_poll.h @ 258
History | View | Annotate | Download (2.49 KB)
1 |
/********
|
---|---|
2 |
* This file is part of Tooltron.
|
3 |
*
|
4 |
* Tooltron is free software: you can redistribute it and/or modify
|
5 |
* it under the terms of the Lesser GNU General Public License as published by
|
6 |
* the Free Software Foundation, either version 3 of the License, or
|
7 |
* (at your option) any later version.
|
8 |
*
|
9 |
* Tooltron is distributed in the hope that it will be useful,
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
* Lesser GNU General Public License for more details.
|
13 |
* You should have received a copy of the Lesser GNU General Public License
|
14 |
* along with Tooltron. If not, see <http://www.gnu.org/licenses/>.
|
15 |
*
|
16 |
* Copyright 2009 Kevin Woo <kwoo@2ndt.com>
|
17 |
*
|
18 |
********/
|
19 |
/**
|
20 |
* @file rs485_poll.h
|
21 |
* @brief Implements rs485 using the uart hardware module.
|
22 |
*
|
23 |
* This is compiled for the bootloader so this is just a header file
|
24 |
*
|
25 |
* @author Kevin Woo (kwoo)
|
26 |
*/
|
27 |
|
28 |
#ifndef _RS485_SW_H
|
29 |
#define _RS485_SW_H
|
30 |
|
31 |
#include <avr/io.h> |
32 |
#include <avr/interrupt.h> |
33 |
#include <stdint.h> |
34 |
|
35 |
#define RS485_TX_OFF 0 |
36 |
#define RS485_TX_ON 1 |
37 |
|
38 |
/**
|
39 |
* @brief This is the value to pass into UBRR to set the baudrate.
|
40 |
* @note this assumes an 8MHz system clock
|
41 |
*/
|
42 |
#define BAUD9600 51 |
43 |
|
44 |
/** @brief RX Pin for the RS485 */
|
45 |
#define RX _BV(PORTD0)
|
46 |
/** @brief TX Pin for the RS485 */
|
47 |
#define TX _BV(PORTD1)
|
48 |
/** @brief TX Enable Pin for the RS485 */
|
49 |
#define TX_EN _BV(PORTD5)
|
50 |
|
51 |
/**
|
52 |
* @brief Initializes the uart
|
53 |
* @param baud The baudrate. Use the definitions in rs485_sw.h
|
54 |
*/
|
55 |
void rs485_init(uint16_t baud);
|
56 |
/**
|
57 |
* @brief Non-blocking receive
|
58 |
*
|
59 |
* Receives a byte from the UART if one exists. If none exist the function
|
60 |
* will return an error code immediately. If there is a byte to receive,
|
61 |
* it will be placed in a passed in pointer and return.
|
62 |
*
|
63 |
* @pre The RS485 TXEN line is not enabled
|
64 |
* @param output_byte Byte to store the received message
|
65 |
* @return 0 on success, negative if there is nothing to receive
|
66 |
*/
|
67 |
int8_t rs485_get_byte(uint8_t *output_byte); |
68 |
/**
|
69 |
* @brief Blocking send
|
70 |
*
|
71 |
* Sends the byte in data onto the network. The function will block until
|
72 |
* the transmit is complete so that the transmit enable line can be toggled
|
73 |
* safely. It will wait until any current transmission completes before sending
|
74 |
* and will wait until it completes before returning. The RS485 TX enable line
|
75 |
* is automatically toggled by the function and should not be done so
|
76 |
* outside the function.
|
77 |
*
|
78 |
* @param data The byte to send
|
79 |
*/
|
80 |
void rs485_send_byte(uint8_t data);
|
81 |
#endif
|