Corrected at91sam7s port MS/TP code where APDU size > 255 caused APDU layer to not process packets.
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
#define Board_h
|
#define Board_h
|
||||||
|
|
||||||
#include "AT91SAM7S256.h"
|
#include "AT91SAM7S256.h"
|
||||||
|
#include "isr.h"
|
||||||
#define __inline inline
|
#define __inline inline
|
||||||
|
|
||||||
//-----------------------------------------------
|
//-----------------------------------------------
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ static uint8_t FrameType;
|
|||||||
and microcontroller architectures have limits as to places to
|
and microcontroller architectures have limits as to places to
|
||||||
hold contiguous memory. */
|
hold contiguous memory. */
|
||||||
static uint8_t *InputBuffer;
|
static uint8_t *InputBuffer;
|
||||||
static uint8_t InputBufferSize;
|
static uint16_t InputBufferSize;
|
||||||
/* Used to store the Source Address of a received frame. */
|
/* Used to store the Source Address of a received frame. */
|
||||||
static uint8_t SourceAddress;
|
static uint8_t SourceAddress;
|
||||||
/* "This Station," the MAC address of this node. TS is generally read from a */
|
/* "This Station," the MAC address of this node. TS is generally read from a */
|
||||||
|
|||||||
@@ -55,11 +55,8 @@ extern unsigned enableIRQ(
|
|||||||
extern unsigned enableFIQ(
|
extern unsigned enableFIQ(
|
||||||
void);
|
void);
|
||||||
|
|
||||||
// *******************************************************
|
/* used by crt.s file */
|
||||||
// FIXME: use header files? Global Variables
|
unsigned FiqCount = 0;
|
||||||
// *******************************************************
|
|
||||||
unsigned int FiqCount = 0;
|
|
||||||
|
|
||||||
|
|
||||||
static unsigned long LED_Timer_1 = 0;
|
static unsigned long LED_Timer_1 = 0;
|
||||||
static unsigned long LED_Timer_2 = 0;
|
static unsigned long LED_Timer_2 = 0;
|
||||||
@@ -67,7 +64,7 @@ static unsigned long LED_Timer_3 = 0;
|
|||||||
static unsigned long LED_Timer_4 = 1000;
|
static unsigned long LED_Timer_4 = 1000;
|
||||||
static unsigned long DCC_Timer = 1000;
|
static unsigned long DCC_Timer = 1000;
|
||||||
|
|
||||||
static void millisecond_timer(
|
static inline void millisecond_timer(
|
||||||
void)
|
void)
|
||||||
{
|
{
|
||||||
while (Timer_Milliseconds) {
|
while (Timer_Milliseconds) {
|
||||||
@@ -91,7 +88,7 @@ static void millisecond_timer(
|
|||||||
/* note: MS/TP silence timer is updated in ISR */
|
/* note: MS/TP silence timer is updated in ISR */
|
||||||
}
|
}
|
||||||
|
|
||||||
static void init(
|
static inline void init(
|
||||||
void)
|
void)
|
||||||
{
|
{
|
||||||
/* Initialize the Parallel I/O Controller A Peripheral Clock */
|
/* Initialize the Parallel I/O Controller A Peripheral Clock */
|
||||||
@@ -132,18 +129,19 @@ static void init(
|
|||||||
pAIC->AIC_IECR = (1 << AT91C_ID_FIQ);
|
pAIC->AIC_IECR = (1 << AT91C_ID_FIQ);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bacnet_init(
|
static inline void bacnet_init(
|
||||||
void)
|
void)
|
||||||
{
|
{
|
||||||
#if defined(BACDL_MSTP)
|
#if defined(BACDL_MSTP)
|
||||||
|
uint8_t MAC_Address = 0x55;
|
||||||
|
|
||||||
RS485_Set_Baud_Rate(38400);
|
RS485_Set_Baud_Rate(38400);
|
||||||
dlmstp_set_mac_address(55);
|
dlmstp_set_mac_address(MAC_Address);
|
||||||
dlmstp_set_max_master(127);
|
dlmstp_set_max_master(127);
|
||||||
dlmstp_set_max_info_frames(1);
|
dlmstp_set_max_info_frames(1);
|
||||||
dlmstp_init(NULL);
|
dlmstp_init(NULL);
|
||||||
#endif
|
#endif
|
||||||
Device_Set_Object_Instance_Number(22222);
|
Device_Set_Object_Instance_Number(22222);
|
||||||
#ifndef DLMSTP_TEST
|
|
||||||
/* we need to handle who-is to support dynamic device binding */
|
/* we need to handle who-is to support dynamic device binding */
|
||||||
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is);
|
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is);
|
||||||
/* Set the handlers for any confirmed services that we support. */
|
/* Set the handlers for any confirmed services that we support. */
|
||||||
@@ -157,9 +155,9 @@ static void bacnet_init(
|
|||||||
/* handle communication so we can shutup when asked */
|
/* handle communication so we can shutup when asked */
|
||||||
apdu_set_confirmed_handler(SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL,
|
apdu_set_confirmed_handler(SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL,
|
||||||
handler_device_communication_control);
|
handler_device_communication_control);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint8_t Receive_PDU[MAX_MPDU]; /* PDU data */
|
||||||
int main(
|
int main(
|
||||||
void)
|
void)
|
||||||
{
|
{
|
||||||
@@ -169,7 +167,6 @@ int main(
|
|||||||
bool LED3_Off_Enabled = true;
|
bool LED3_Off_Enabled = true;
|
||||||
uint16_t pdu_len = 0;
|
uint16_t pdu_len = 0;
|
||||||
BACNET_ADDRESS src; /* source address */
|
BACNET_ADDRESS src; /* source address */
|
||||||
uint8_t pdu[MAX_MPDU]; /* PDU data */
|
|
||||||
// Set up the LEDs (PA0 - PA3)
|
// Set up the LEDs (PA0 - PA3)
|
||||||
volatile AT91PS_PIO pPIO = AT91C_BASE_PIOA;
|
volatile AT91PS_PIO pPIO = AT91C_BASE_PIOA;
|
||||||
|
|
||||||
@@ -239,12 +236,11 @@ int main(
|
|||||||
// count # of times through the idle loop
|
// count # of times through the idle loop
|
||||||
IdleCount++;
|
IdleCount++;
|
||||||
/* BACnet handling */
|
/* BACnet handling */
|
||||||
pdu_len = datalink_receive(&src, &pdu[0], MAX_MPDU, 0);
|
pdu_len = datalink_receive(&src,
|
||||||
|
&Receive_PDU[0], sizeof(Receive_PDU), 0);
|
||||||
if (pdu_len) {
|
if (pdu_len) {
|
||||||
pPIO->PIO_CODR = LED3;
|
pPIO->PIO_CODR = LED3;
|
||||||
#ifndef DLMSTP_TEST
|
npdu_handler(&src, &Receive_PDU[0], pdu_len);
|
||||||
npdu_handler(&src, &pdu[0], pdu_len);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,9 @@ The dlmstp is the datalink layer for MS/TP over RS-485.
|
|||||||
|
|
||||||
I used the makefile from the command line on Windows, and
|
I used the makefile from the command line on Windows, and
|
||||||
then used the SAM-BA to send the resulting .bin file to the
|
then used the SAM-BA to send the resulting .bin file to the
|
||||||
board using a J-Link.
|
board using a J-Link. To debug the code from flash, run the
|
||||||
|
J-Link GDB Server and then:
|
||||||
|
> arm-elf-gdb bacnet.elf
|
||||||
|
|
||||||
I got the crt.s, at91sam7s256.ld, blinker.c, init.c, isr.c, and
|
I got the crt.s, at91sam7s256.ld, blinker.c, init.c, isr.c, and
|
||||||
timer.c from James P Lynch. I created the rs485.c based on the
|
timer.c from James P Lynch. I created the rs485.c based on the
|
||||||
|
|||||||
@@ -326,7 +326,6 @@ void Timer_Silence_Reset(
|
|||||||
SilenceTime = 0;
|
SilenceTime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// *****************************************************************************
|
// *****************************************************************************
|
||||||
//
|
//
|
||||||
// Timer 0 Initialization
|
// Timer 0 Initialization
|
||||||
|
|||||||
Reference in New Issue
Block a user