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