Revision 188
| trunk/common/rs485_poll.h (revision 188) | ||
|---|---|---|
| 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 |
* See rs485_sw.c for more information |
|
| 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 |
/** @brief RX Pin for the RS485 */ |
|
| 39 |
#define RX _BV(PORTD0) |
|
| 40 |
/** @brief TX Pin for the RS485 */ |
|
| 41 |
#define TX _BV(PORTD1) |
|
| 42 |
/** @brief TX Enable Pin for the RS485 */ |
|
| 43 |
#define TX_EN _BV(PORTD5) |
|
| 44 |
|
|
| 45 |
void rs485_init(uint16_t baud); |
|
| 46 |
int8_t rs485_get_byte(uint8_t *output_byte); |
|
| 47 |
void rs485_send_byte(uint8_t data); |
|
| 48 |
#endif |
|
| trunk/bootloader/rs485_poll.h (revision 188) | ||
|---|---|---|
| 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 |
/** @brief RX Pin for the RS485 */ |
|
| 39 |
#define RX _BV(PORTD0) |
|
| 40 |
/** @brief TX Pin for the RS485 */ |
|
| 41 |
#define TX _BV(PORTD1) |
|
| 42 |
/** @brief TX Enable Pin for the RS485 */ |
|
| 43 |
#define TX_EN _BV(PORTD5) |
|
| 44 |
|
|
| 45 |
/** |
|
| 46 |
* @brief Initializes the uart |
|
| 47 |
* @param baud The baudrate. Use the definitions in rs485_sw.h |
|
| 48 |
*/ |
|
| 49 |
void rs485_init(uint16_t baud); |
|
| 50 |
/** |
|
| 51 |
* @brief Non-blocking receive |
|
| 52 |
* |
|
| 53 |
* Receives a byte from the UART if one exists. If none exist the function |
|
| 54 |
* will return an error code immediately. If there is a byte to receive, |
|
| 55 |
* it will be placed in a passed in pointer and return. |
|
| 56 |
* |
|
| 57 |
* @pre The RS485 TXEN line is not enabled |
|
| 58 |
* @param output_byte Byte to store the received message |
|
| 59 |
* @return 0 on success, negative if there is nothing to receive |
|
| 60 |
*/ |
|
| 61 |
int8_t rs485_get_byte(uint8_t *output_byte); |
|
| 62 |
/** |
|
| 63 |
* @brief Blocking send |
|
| 64 |
* |
|
| 65 |
* Sends the byte in data onto the network. The function will block until |
|
| 66 |
* the transmit is complete so that the transmit enable line can be toggled |
|
| 67 |
* safely. It will wait until any current transmission completes before sending |
|
| 68 |
* and will wait until it completes before returning. The RS485 TX enable line |
|
| 69 |
* is automatically toggled by the function and should not be done so |
|
| 70 |
* outside the function. |
|
| 71 |
* |
|
| 72 |
* @param data The byte to send |
|
| 73 |
*/ |
|
| 74 |
void rs485_send_byte(uint8_t data); |
|
| 75 |
#endif |
|
Also available in: Unified diff