start adapting for xmega
This commit is contained in:
@@ -45,7 +45,6 @@ THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include <avr/io.h>
|
||||
#include "yaMBSiavr.h"
|
||||
#include <avr/interrupt.h>
|
||||
#include "aBusIO.h"
|
||||
|
||||
volatile unsigned char BusState = 0;
|
||||
volatile uint16_t modbusTimer = 0;
|
||||
@@ -180,26 +179,27 @@ void modbusTickTimer(void)
|
||||
|
||||
ISR(UART_RECEIVE_INTERRUPT)
|
||||
{
|
||||
unsigned char data;
|
||||
data = UART_DATA;
|
||||
modbusTimer=0; //reset timer
|
||||
if (!(BusState & (1<<ReceiveCompleted)) && !(BusState & (1<<TransmitRequested)) && !(BusState & (1<<Transmitting)) && (BusState & (1<<Receiving)) && !(BusState & (1<<BusTimedOut)))
|
||||
{
|
||||
if (DataPos>MaxFrameIndex) modbusReset();
|
||||
else
|
||||
{
|
||||
rxbuffer[DataPos]=data;
|
||||
DataPos++; //TODO: maybe prevent this from exceeding 255?
|
||||
}
|
||||
} else
|
||||
if (!(BusState & (1<<ReceiveCompleted)) && !(BusState & (1<<TransmitRequested)) && !(BusState & (1<<Transmitting)) && !(BusState & (1<<Receiving)) && (BusState & (1<<BusTimedOut)))
|
||||
{
|
||||
rxbuffer[0]=data;
|
||||
BusState=((1<<Receiving)|(1<<TimerActive));
|
||||
DataPos=1;
|
||||
}
|
||||
unsigned char data;
|
||||
data = UART_DATA;
|
||||
modbusTimer=0; //reset timer
|
||||
if (!(BusState & (1<<ReceiveCompleted)) && !(BusState & (1<<TransmitRequested)) && !(BusState & (1<<Transmitting)) && (BusState & (1<<Receiving)) && !(BusState & (1<<BusTimedOut)))
|
||||
{
|
||||
if (DataPos>MaxFrameIndex) modbusReset();
|
||||
else
|
||||
{
|
||||
rxbuffer[DataPos]=data;
|
||||
DataPos++; //TODO: maybe prevent this from exceeding 255?
|
||||
}
|
||||
} else
|
||||
if (!(BusState & (1<<ReceiveCompleted)) && !(BusState & (1<<TransmitRequested)) && !(BusState & (1<<Transmitting)) && !(BusState & (1<<Receiving)) && (BusState & (1<<BusTimedOut)))
|
||||
{
|
||||
rxbuffer[0]=data;
|
||||
BusState=((1<<Receiving)|(1<<TimerActive));
|
||||
DataPos=1;
|
||||
}
|
||||
}
|
||||
|
||||
//TODO
|
||||
ISR(UART_TRANSMIT_INTERRUPT)
|
||||
{
|
||||
BusState&=~(1<<TransmitRequested);
|
||||
@@ -219,6 +219,7 @@ ISR(UART_TRANSMIT_COMPLETE_INTERRUPT)
|
||||
modbusReset();
|
||||
}
|
||||
|
||||
//TODO
|
||||
void modbusInit(void)
|
||||
{
|
||||
UBRRH = (unsigned char)((UBRR) >> 8);
|
||||
@@ -242,6 +243,7 @@ void modbusInit(void)
|
||||
* Arguments: - packtop: Position of the last byte containing data.
|
||||
* modbusSendException is a good usage example.
|
||||
*/
|
||||
//TODO
|
||||
void modbusSendMessage(unsigned char packtop)
|
||||
{
|
||||
PacketTopIndex=packtop+2;
|
||||
|
||||
@@ -39,7 +39,6 @@ THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
************************************************************************/
|
||||
#include <avr/io.h>
|
||||
#include "aBusIO.h"
|
||||
/**
|
||||
* @code #include <yaMBSIavr.h> @endcode
|
||||
*
|
||||
@@ -179,7 +178,7 @@ THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#define UBRRH UBRR0H
|
||||
#define UBRRL UBRR0L
|
||||
|
||||
#elif defined(__AVR_ATmega8__)|| defined(__AVR_ATmega16__) || defined(__AVR_ATmega32__) || defined(__AVR_ATmega323__)
|
||||
#elif defined(__AVR_ATmega7__)|| defined(__AVR_ATmega16__) || defined(__AVR_ATmega32__) || defined(__AVR_ATmega323__)
|
||||
#define UART_TRANSMIT_COMPLETE_INTERRUPT USART_TXC_vect
|
||||
#define UART_RECEIVE_INTERRUPT USART_RXC_vect
|
||||
#define UART_TRANSMIT_INTERRUPT USART_UDRE_vect
|
||||
@@ -188,6 +187,13 @@ THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#define UART_DATA UDR
|
||||
#define UART_UDRIE UDRIE
|
||||
|
||||
#elif defined(__AVR_ATxmega32A4__)
|
||||
#define UART_TRANSMIT_COMPLETE_INTERRUPT USARTD0_TXC_vect
|
||||
#define UART_RECEIVE_INTERRUPT USARTD0_RXC_vect
|
||||
#define UART_TRANSMIT_INTERRUPT USARTD0_DRE_vect
|
||||
#define UART_DATA USARTD0.DATA
|
||||
|
||||
|
||||
#else
|
||||
#error "no definition available"
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user