Revision 184 trunk/bootloader/uart.h
| uart.h (revision 184) | ||
|---|---|---|
| 16 | 16 |
* Copyright 2009 Kevin Woo <kwoo@2ndt.com> |
| 17 | 17 |
* |
| 18 | 18 |
********/ |
| 19 |
/** @file uart.h |
|
| 19 |
/** @file rs485_sw.h |
|
| 20 | 20 |
* |
| 21 |
* @brief Initializes UART functions using the UART hardware module |
|
| 21 |
* @brief Implements rs485 using the uart hardware module. |
|
| 22 | 22 |
* |
| 23 |
* See rs485_sw.c for more information |
|
| 24 |
* |
|
| 23 | 25 |
* @author Kevin Woo (kwoo) |
| 24 | 26 |
*/ |
| 25 | 27 |
|
| 26 |
#ifndef UART_H |
|
| 27 |
#define UART_H |
|
| 28 |
#ifndef _RS485_SW_H |
|
| 29 |
#define _RS485_SW_H |
|
| 28 | 30 |
|
| 29 | 31 |
#include <avr/io.h> |
| 30 | 32 |
#include <avr/interrupt.h> |
| 31 | 33 |
#include <stdint.h> |
| 32 |
/** **/ |
|
| 33 |
#define UART_TX_OFF 0 |
|
| 34 |
#define UART_TX_ON 1 |
|
| 35 | 34 |
|
| 36 |
/** @brief RX Pin for the UART **/ |
|
| 35 |
#define RS485_TX_OFF 0 |
|
| 36 |
#define RS485_TX_ON 1 |
|
| 37 |
|
|
| 38 |
/** @brief RX Pin for the RS485 */ |
|
| 37 | 39 |
#define RX _BV(PORTD0) |
| 40 |
/** @brief TX Pin for the RS485 */ |
|
| 38 | 41 |
#define TX _BV(PORTD1) |
| 42 |
/** @brief TX Enable Pin for the RS485 */ |
|
| 39 | 43 |
#define TX_EN _BV(PORTD5) |
| 40 | 44 |
|
| 41 |
/** @brief The most recently received byte **/ |
|
| 42 |
extern uint8_t received_byte; |
|
| 43 |
/** @brief If the value in received_byte has been read or not **/ |
|
| 44 |
extern uint8_t byte_ready; |
|
| 45 |
|
|
| 46 |
/** @brief Initializes the UART registers and sets it to the buad rate |
|
| 47 |
* which msut be the value that is defined in the datasheet |
|
| 48 |
* for any particular speed (ie: 51 -> 9600bps) |
|
| 49 |
**/ |
|
| 50 |
void init_uart(uint16_t baud); |
|
| 51 |
/** @brief Gets latest byte and returns it in output_byte. If the byte |
|
| 52 |
* was already read, returns -1 otherwise it returns 0 |
|
| 53 |
**/ |
|
| 45 |
void uart_init(uint16_t baud); |
|
| 54 | 46 |
int8_t uart_get_byte(uint8_t *output_byte); |
| 55 |
/** @brief Sends a character array of size size. If we are currently |
|
| 56 |
* transmitting it will block until the the current transmit |
|
| 57 |
* is done. |
|
| 58 |
**/ |
|
| 59 | 47 |
void uart_send_byte(uint8_t data); |
| 60 |
void uart_toggle_transmit(uint8_t state); |
|
| 48 |
static void uart_toggle_transmit(uint8_t state); |
|
| 61 | 49 |
#endif |
Also available in: Unified diff