Add stk500 platform and changes suggested by Daniel Willmann
This commit is contained in:
parent
e953b66f78
commit
e2ad2acde4
16 changed files with 945 additions and 45 deletions
|
@ -42,6 +42,14 @@
|
|||
#include "dev/slip.h"
|
||||
#include "dev/rs232.h"
|
||||
|
||||
/*ATmega32 and smaller have UBRRH/UCSRC at the same I/O address.
|
||||
*USART_UCSRC_SEL (bit7) selects writing to UBRHH(0) or UCSRC(1).
|
||||
*It is OR'd in below so if not defined we can just set it to zero.
|
||||
*/
|
||||
#ifndef USART_UCSRC_SEL
|
||||
#define USART_UCSRC_SEL 0x00
|
||||
#endif
|
||||
|
||||
#ifdef RS232_CONF_PRINTF_BUFFER_LENGTH
|
||||
#define RS232_PRINTF_BUFFER_LENGTH RS232_CONF_PRINTF_BUFFER_LENGTH
|
||||
#else
|
||||
|
@ -52,17 +60,17 @@
|
|||
#define ADD_CARRAGE_RETURNS_TO_SERIAL_OUTPUT 1
|
||||
#endif
|
||||
|
||||
#if defined (__AVR_ATmega128__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega128RFA1__)
|
||||
typedef struct {
|
||||
volatile uint8_t * UDR;
|
||||
volatile uint8_t * UBRRH;
|
||||
volatile uint8_t * UBRRL;
|
||||
volatile uint8_t * UCSRB;
|
||||
volatile uint8_t * UCSRC;
|
||||
volatile uint8_t * udr;
|
||||
volatile uint8_t * ubrrh;
|
||||
volatile uint8_t * ubrrl;
|
||||
volatile uint8_t * ucsrb;
|
||||
volatile uint8_t * ucsrc;
|
||||
volatile uint8_t txwait;
|
||||
int (* input_handler)(unsigned char);
|
||||
} rs232_t;
|
||||
|
||||
#if defined (__AVR_ATmega128__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega128RFA1__)
|
||||
static rs232_t rs232_ports[2] = {
|
||||
{ // UART0
|
||||
&UDR0,
|
||||
|
@ -84,6 +92,49 @@ static rs232_t rs232_ports[2] = {
|
|||
NULL
|
||||
}
|
||||
};
|
||||
#elif defined (__AVR_AT90USB1287__)
|
||||
/* Has only UART1, map it to port 0 */
|
||||
static rs232_t rs232_ports[1] = {
|
||||
{ // UART1
|
||||
&UDR1,
|
||||
&UBRR1H,
|
||||
&UBRR1L,
|
||||
&UCSR1B,
|
||||
&UCSR1C,
|
||||
0,
|
||||
NULL
|
||||
}
|
||||
};
|
||||
#elif defined (__AVR_ATmega8__) || defined (__AVR_ATmega8515__) \
|
||||
|| defined (__AVR_ATmega16__) || defined (__AVR_ATmega32__)
|
||||
static rs232_t rs232_ports[1] = {
|
||||
{ // UART0
|
||||
&UDR,
|
||||
&UBRRH,
|
||||
&UBRRL,
|
||||
&UCSRB,
|
||||
&UCSRC,
|
||||
0,
|
||||
NULL
|
||||
}
|
||||
};
|
||||
#elif defined (__AVR_ATmega644__) || defined (__AVR_ATmega328P__)
|
||||
static rs232_t rs232_ports[1] = {
|
||||
{ // UART0
|
||||
&UDR0,
|
||||
&UBRR0H,
|
||||
&UBRR0L,
|
||||
&UCSR0B,
|
||||
&UCSR0C,
|
||||
0,
|
||||
NULL
|
||||
}
|
||||
};
|
||||
#else
|
||||
#error Please define the UART registers for your MCU!
|
||||
#endif
|
||||
|
||||
#if defined (__AVR_ATmega128__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega128RFA1__)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
ISR(USART0_TX_vect)
|
||||
{
|
||||
|
@ -95,7 +146,7 @@ ISR(USART0_RX_vect)
|
|||
{
|
||||
unsigned char c;
|
||||
|
||||
c = *(rs232_ports[RS232_PORT_0].UDR);
|
||||
c = *(rs232_ports[RS232_PORT_0].udr);
|
||||
|
||||
if(rs232_ports[RS232_PORT_0].input_handler != NULL) {
|
||||
rs232_ports[RS232_PORT_0].input_handler(c);
|
||||
|
@ -112,25 +163,68 @@ ISR(USART1_RX_vect)
|
|||
{
|
||||
unsigned char c;
|
||||
|
||||
c = *(rs232_ports[RS232_PORT_1].UDR);
|
||||
c = *(rs232_ports[RS232_PORT_1].udr);
|
||||
|
||||
if(rs232_ports[RS232_PORT_1].input_handler != NULL) {
|
||||
rs232_ports[RS232_PORT_1].input_handler(c);
|
||||
}
|
||||
}
|
||||
|
||||
#elif defined (__AVR_AT90USB1287__)
|
||||
/* Has only UART1, map it to port 0 */
|
||||
typedef struct {
|
||||
volatile uint8_t * UDR;
|
||||
volatile uint8_t * UBRRH;
|
||||
volatile uint8_t * UBRRL;
|
||||
volatile uint8_t * UCSRB;
|
||||
volatile uint8_t * UCSRC;
|
||||
volatile uint8_t txwait;
|
||||
int (* input_handler)(unsigned char);
|
||||
} rs232_t;
|
||||
#elif defined (__AVR_ATmega644__)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
ISR(USART0_TX_vect)
|
||||
{
|
||||
rs232_ports[RS232_PORT_0].txwait = 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
ISR(USART0_RX_vect)
|
||||
{
|
||||
unsigned char c;
|
||||
|
||||
c = *(rs232_ports[RS232_PORT_0].udr);
|
||||
|
||||
if(rs232_ports[RS232_PORT_0].input_handler != NULL) {
|
||||
rs232_ports[RS232_PORT_0].input_handler(c);
|
||||
}
|
||||
}
|
||||
#elif defined (__AVR_ATmega8__) || defined (__AVR_ATmega16__) || defined (__AVR_ATmega32__)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
ISR(USART_TXC_vect)
|
||||
{
|
||||
rs232_ports[RS232_PORT_0].txwait = 0;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
ISR(USART_RXC_vect)
|
||||
{
|
||||
unsigned char c;
|
||||
|
||||
c = *(rs232_ports[RS232_PORT_0].udr);
|
||||
|
||||
if(rs232_ports[RS232_PORT_0].input_handler != NULL) {
|
||||
rs232_ports[RS232_PORT_0].input_handler(c);
|
||||
}
|
||||
}
|
||||
|
||||
#elif defined (__AVR_ATmega8515__) || defined (__AVR_ATmega328P__)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
ISR(USART_TX_vect)
|
||||
{
|
||||
rs232_ports[RS232_PORT_0].txwait = 0;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
ISR(USART_RX_vect)
|
||||
{
|
||||
unsigned char c;
|
||||
|
||||
c = *(rs232_ports[RS232_PORT_0].udr);
|
||||
|
||||
if(rs232_ports[RS232_PORT_0].input_handler != NULL) {
|
||||
rs232_ports[RS232_PORT_0].input_handler(c);
|
||||
}
|
||||
}
|
||||
#elif defined (__AVR_AT90USB1287__)
|
||||
static rs232_t rs232_ports[1] = {
|
||||
{ // UART1
|
||||
&UDR1,
|
||||
|
@ -153,7 +247,7 @@ ISR(USART1_RX_vect)
|
|||
{
|
||||
unsigned char c;
|
||||
|
||||
c = *(rs232_ports[RS232_PORT_0].UDR);
|
||||
c = *(rs232_ports[RS232_PORT_0].udr);
|
||||
|
||||
if(rs232_ports[RS232_PORT_0].input_handler != NULL) {
|
||||
rs232_ports[RS232_PORT_0].input_handler(c);
|
||||
|
@ -167,14 +261,14 @@ ISR(USART1_RX_vect)
|
|||
void
|
||||
rs232_init (uint8_t port, uint8_t bd, uint8_t ffmt)
|
||||
{
|
||||
*(rs232_ports[port].UBRRH) = (uint8_t)(bd>>8);
|
||||
*(rs232_ports[port].UBRRL) = (uint8_t)bd;
|
||||
*(rs232_ports[port].ubrrh) = (uint8_t)(bd>>8);
|
||||
*(rs232_ports[port].ubrrl) = (uint8_t)bd;
|
||||
|
||||
/*
|
||||
* - Enable receiver and transmitter,
|
||||
* - Enable interrupts for receiver and transmitter
|
||||
*/
|
||||
*(rs232_ports[port].UCSRB) = USART_INTERRUPT_RX_COMPLETE | USART_INTERRUPT_TX_COMPLETE | \
|
||||
*(rs232_ports[port].ucsrb) = USART_INTERRUPT_RX_COMPLETE | USART_INTERRUPT_TX_COMPLETE | \
|
||||
USART_RECEIVER_ENABLE | USART_TRANSMITTER_ENABLE;
|
||||
|
||||
/*
|
||||
|
@ -184,7 +278,7 @@ rs232_init (uint8_t port, uint8_t bd, uint8_t ffmt)
|
|||
* - charater size (9 bits are currently not supported)
|
||||
* - clock polarity
|
||||
*/
|
||||
*(rs232_ports[port].UCSRC) = ffmt;
|
||||
*(rs232_ports[port].ucsrc) = USART_UCSRC_SEL | ffmt;
|
||||
|
||||
rs232_ports[port].txwait = 0;
|
||||
|
||||
|
@ -230,7 +324,7 @@ void
|
|||
rs232_send(uint8_t port, unsigned char c)
|
||||
{
|
||||
rs232_ports[port].txwait = 1;
|
||||
*(rs232_ports[port].UDR) = c;
|
||||
*(rs232_ports[port].udr) = c;
|
||||
while(rs232_ports[port].txwait);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue