Refactoring some BDK code. Updating Skip Data state for AT91 port.
This commit is contained in:
@@ -93,6 +93,10 @@ extern "C" {
|
|||||||
bool Binary_Output_Present_Value_Relinquish(
|
bool Binary_Output_Present_Value_Relinquish(
|
||||||
uint32_t instance,
|
uint32_t instance,
|
||||||
unsigned priority);
|
unsigned priority);
|
||||||
|
BACNET_POLARITY Binary_Output_Polarity(
|
||||||
|
uint32_t instance);
|
||||||
|
bool Binary_Output_Out_Of_Service(
|
||||||
|
uint32_t instance);
|
||||||
|
|
||||||
|
|
||||||
#ifdef TEST
|
#ifdef TEST
|
||||||
|
|||||||
@@ -1181,8 +1181,11 @@ uint16_t dlmstp_receive(
|
|||||||
(MSTP_Flag.ReceivedInvalidFrame == false)) {
|
(MSTP_Flag.ReceivedInvalidFrame == false)) {
|
||||||
MSTP_Receive_Frame_FSM();
|
MSTP_Receive_Frame_FSM();
|
||||||
}
|
}
|
||||||
/* only do master state machine while rx is idle */
|
if (MSTP_Flag.ReceivedValidFrameNotForUs) {
|
||||||
|
MSTP_Flag.ReceivedValidFrameNotForUs = false;
|
||||||
|
}
|
||||||
if (Receive_State == MSTP_RECEIVE_STATE_IDLE) {
|
if (Receive_State == MSTP_RECEIVE_STATE_IDLE) {
|
||||||
|
/* only do master state machine while rx is idle */
|
||||||
while (MSTP_Master_Node_FSM()) {
|
while (MSTP_Master_Node_FSM()) {
|
||||||
/* do nothing while some states fast transition */
|
/* do nothing while some states fast transition */
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -31,10 +31,10 @@ SIZE_OPTIONS = -t
|
|||||||
# avrispmkII = AVR ISP MKII
|
# avrispmkII = AVR ISP MKII
|
||||||
# avr109 = bootloader
|
# avr109 = bootloader
|
||||||
#AVRDUDE_PROGRAMMERID = avr109
|
#AVRDUDE_PROGRAMMERID = avr109
|
||||||
#AVRDUDE_PROGRAMMERID = jtag2fast
|
AVRDUDE_PROGRAMMERID = jtag2fast
|
||||||
#AVRDUDE_PROGRAMMERID = avrispmkII
|
#AVRDUDE_PROGRAMMERID = avrispmkII
|
||||||
#AVRDUDE_PROGRAMMERID = dragon_isp
|
#AVRDUDE_PROGRAMMERID = dragon_isp
|
||||||
AVRDUDE_PROGRAMMERID = dragon_jtag
|
#AVRDUDE_PROGRAMMERID = dragon_jtag
|
||||||
#
|
#
|
||||||
# port--serial or parallel port to which your
|
# port--serial or parallel port to which your
|
||||||
# hardware programmer is attached
|
# hardware programmer is attached
|
||||||
@@ -274,7 +274,7 @@ AVRDUDE_WRITE_FUSES_V2 = -U hfuse:w:0x93:m -U lfuse:w:0xE7:m -U efuse:w:0xFC:m
|
|||||||
|
|
||||||
AVRDUDE_BOOTL_FUSES = -U hfuse:w:0x92:m -U lfuse:w:0xD7:m -U efuse:w:0xFC:m
|
AVRDUDE_BOOTL_FUSES = -U hfuse:w:0x92:m -U lfuse:w:0xD7:m -U efuse:w:0xFC:m
|
||||||
|
|
||||||
AVRDUDE_READ_FUSES = -U lfuse:r:-:h -U hfuse:r:-:h -U efuse:r:-:h
|
AVRDUDE_READ_FUSES = -U hfuse:r:-:h -U lfuse:r:-:h -U efuse:r:-:h
|
||||||
|
|
||||||
AVRDUDE_WRITE_FLASH = -e -U flash:w:$(TARGET).hex
|
AVRDUDE_WRITE_FLASH = -e -U flash:w:$(TARGET).hex
|
||||||
|
|
||||||
|
|||||||
@@ -126,7 +126,8 @@ void bacnet_task(
|
|||||||
bool button_value;
|
bool button_value;
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
BACNET_BINARY_PV binary_value = BINARY_INACTIVE;
|
BACNET_BINARY_PV binary_value = BINARY_INACTIVE;
|
||||||
|
BACNET_POLARITY polarity;
|
||||||
|
bool out_of_service;
|
||||||
|
|
||||||
mstp_mac_address = input_address();
|
mstp_mac_address = input_address();
|
||||||
if (MSTP_MAC_Address != mstp_mac_address) {
|
if (MSTP_MAC_Address != mstp_mac_address) {
|
||||||
@@ -145,15 +146,33 @@ void bacnet_task(
|
|||||||
}
|
}
|
||||||
Binary_Input_Present_Value_Set(i, binary_value);
|
Binary_Input_Present_Value_Set(i, binary_value);
|
||||||
}
|
}
|
||||||
if (Binary_Output_Present_Value(0) == BINARY_ACTIVE) {
|
/* Binary Output */
|
||||||
led_on(LED_3);
|
for (i = 0; i < 2; i++) {
|
||||||
} else {
|
out_of_service = Binary_Output_Out_Of_Service(i);
|
||||||
led_off(LED_3);
|
if (!out_of_service) {
|
||||||
}
|
binary_value = Binary_Output_Present_Value(i);
|
||||||
if (Binary_Output_Present_Value(1) == BINARY_ACTIVE) {
|
polarity = Binary_Output_Polarity(i);
|
||||||
led_on(LED_4);
|
if (polarity != POLARITY_NORMAL) {
|
||||||
} else {
|
if (binary_value == BINARY_ACTIVE) {
|
||||||
led_off(LED_4);
|
binary_value = BINARY_INACTIVE;
|
||||||
|
} else {
|
||||||
|
binary_value = BINARY_ACTIVE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (binary_value == BINARY_ACTIVE) {
|
||||||
|
if (i == 0) {
|
||||||
|
led_on(LED_2);
|
||||||
|
} else {
|
||||||
|
led_on(LED_3);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (i == 0) {
|
||||||
|
led_off(LED_2);
|
||||||
|
} else {
|
||||||
|
led_off(LED_3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* handle the communication timer */
|
/* handle the communication timer */
|
||||||
if (timer_interval_expired(&DCC_Timer)) {
|
if (timer_interval_expired(&DCC_Timer)) {
|
||||||
|
|||||||
@@ -159,44 +159,6 @@ BACNET_BINARY_PV Binary_Output_Present_Value(
|
|||||||
return Present_Value(index);
|
return Present_Value(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Binary_Output_Level_Sync(
|
|
||||||
uint32_t instance)
|
|
||||||
{
|
|
||||||
BACNET_BINARY_PV pv;
|
|
||||||
|
|
||||||
if (instance < MAX_BINARY_OUTPUTS) {
|
|
||||||
if (Out_Of_Service[instance]) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
pv = Present_Value(instance);
|
|
||||||
if (Polarity[instance] == POLARITY_REVERSE) {
|
|
||||||
if (pv == BINARY_INACTIVE) {
|
|
||||||
pv = BINARY_ACTIVE;
|
|
||||||
} else if (pv == BINARY_ACTIVE) {
|
|
||||||
pv = BINARY_INACTIVE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
switch (instance) {
|
|
||||||
case 0:
|
|
||||||
if (pv == BINARY_INACTIVE) {
|
|
||||||
led_off(LED_3);
|
|
||||||
} else if (pv == BINARY_ACTIVE) {
|
|
||||||
led_on(LED_3);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
if (pv == BINARY_INACTIVE) {
|
|
||||||
led_off(LED_4);
|
|
||||||
} else if (pv == BINARY_ACTIVE) {
|
|
||||||
led_on(LED_4);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Binary_Output_Present_Value_Set(
|
bool Binary_Output_Present_Value_Set(
|
||||||
uint32_t instance,
|
uint32_t instance,
|
||||||
BACNET_BINARY_PV binary_value,
|
BACNET_BINARY_PV binary_value,
|
||||||
@@ -210,7 +172,6 @@ bool Binary_Output_Present_Value_Set(
|
|||||||
seeprom_bytes_write(NV_SEEPROM_BINARY_OUTPUT(instance,
|
seeprom_bytes_write(NV_SEEPROM_BINARY_OUTPUT(instance,
|
||||||
NV_SEEPROM_BO_PRIORITY_ARRAY_1 + priority),
|
NV_SEEPROM_BO_PRIORITY_ARRAY_1 + priority),
|
||||||
&Binary_Output_Level[instance][priority], 1);
|
&Binary_Output_Level[instance][priority], 1);
|
||||||
Binary_Output_Level_Sync(instance);
|
|
||||||
status = true;
|
status = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -231,6 +192,18 @@ static void Binary_Output_Polarity_Set(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BACNET_POLARITY Binary_Output_Polarity(
|
||||||
|
uint32_t instance)
|
||||||
|
{
|
||||||
|
BACNET_POLARITY polarity = POLARITY_NORMAL;
|
||||||
|
|
||||||
|
if (instance < MAX_BINARY_OUTPUTS) {
|
||||||
|
polarity = Polarity[instance];
|
||||||
|
}
|
||||||
|
|
||||||
|
return polarity;
|
||||||
|
}
|
||||||
|
|
||||||
static void Binary_Output_Out_Of_Service_Set(
|
static void Binary_Output_Out_Of_Service_Set(
|
||||||
uint32_t instance,
|
uint32_t instance,
|
||||||
bool flag)
|
bool flag)
|
||||||
@@ -242,6 +215,18 @@ static void Binary_Output_Out_Of_Service_Set(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Binary_Output_Out_Of_Service(
|
||||||
|
uint32_t instance)
|
||||||
|
{
|
||||||
|
bool flag = false;
|
||||||
|
|
||||||
|
if (instance < MAX_BINARY_OUTPUTS) {
|
||||||
|
flag = Out_Of_Service[instance];
|
||||||
|
}
|
||||||
|
|
||||||
|
return flag;
|
||||||
|
}
|
||||||
|
|
||||||
/* note: the object name must be unique within this device */
|
/* note: the object name must be unique within this device */
|
||||||
char *Binary_Output_Name(
|
char *Binary_Output_Name(
|
||||||
uint32_t object_instance)
|
uint32_t object_instance)
|
||||||
@@ -470,7 +455,6 @@ bool Binary_Output_Write_Property(
|
|||||||
if (status) {
|
if (status) {
|
||||||
Binary_Output_Out_Of_Service_Set(wp_data->object_instance,
|
Binary_Output_Out_Of_Service_Set(wp_data->object_instance,
|
||||||
value.type.Boolean);
|
value.type.Boolean);
|
||||||
Binary_Output_Level_Sync(wp_data->object_instance);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PROP_POLARITY:
|
case PROP_POLARITY:
|
||||||
@@ -481,7 +465,6 @@ bool Binary_Output_Write_Property(
|
|||||||
if (value.type.Enumerated < MAX_POLARITY) {
|
if (value.type.Enumerated < MAX_POLARITY) {
|
||||||
Binary_Output_Polarity_Set(wp_data->object_instance,
|
Binary_Output_Polarity_Set(wp_data->object_instance,
|
||||||
(BACNET_POLARITY) value.type.Enumerated);
|
(BACNET_POLARITY) value.type.Enumerated);
|
||||||
Binary_Output_Level_Sync(wp_data->object_instance);
|
|
||||||
} else {
|
} else {
|
||||||
status = false;
|
status = false;
|
||||||
wp_data->error_class = ERROR_CLASS_PROPERTY;
|
wp_data->error_class = ERROR_CLASS_PROPERTY;
|
||||||
@@ -522,7 +505,6 @@ void Binary_Output_Init(
|
|||||||
NV_SEEPROM_BO_PRIORITY_ARRAY_1 + j),
|
NV_SEEPROM_BO_PRIORITY_ARRAY_1 + j),
|
||||||
&Binary_Output_Level[i][j], 1);
|
&Binary_Output_Level[i][j], 1);
|
||||||
}
|
}
|
||||||
Binary_Output_Level_Sync(i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -55,4 +55,10 @@
|
|||||||
#define SEEPROM_I2C_ADDRESS 0xA0
|
#define SEEPROM_I2C_ADDRESS 0xA0
|
||||||
#define SEEPROM_I2C_CLOCK 400000L
|
#define SEEPROM_I2C_CLOCK 400000L
|
||||||
|
|
||||||
|
#define LED_2 2
|
||||||
|
#define LED_3 3
|
||||||
|
#define LED_4 1
|
||||||
|
#define LED_5 0
|
||||||
|
#define MAX_LEDS 4
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -37,16 +37,16 @@ void led_on(
|
|||||||
uint8_t index)
|
uint8_t index)
|
||||||
{
|
{
|
||||||
switch (index) {
|
switch (index) {
|
||||||
case LED_1:
|
case 0:
|
||||||
BIT_SET(PORTD, PD7);
|
BIT_SET(PORTD, PD7);
|
||||||
break;
|
break;
|
||||||
case LED_2:
|
case 1:
|
||||||
BIT_SET(PORTD, PD6);
|
BIT_SET(PORTD, PD6);
|
||||||
break;
|
break;
|
||||||
case LED_3:
|
case 2:
|
||||||
BIT_SET(PORTC, PC7);
|
BIT_SET(PORTC, PC7);
|
||||||
break;
|
break;
|
||||||
case LED_4:
|
case 3:
|
||||||
BIT_SET(PORTC, PC6);
|
BIT_SET(PORTC, PC6);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -66,16 +66,16 @@ void led_off(
|
|||||||
uint8_t index)
|
uint8_t index)
|
||||||
{
|
{
|
||||||
switch (index) {
|
switch (index) {
|
||||||
case LED_1:
|
case 0:
|
||||||
BIT_CLEAR(PORTD, PD7);
|
BIT_CLEAR(PORTD, PD7);
|
||||||
break;
|
break;
|
||||||
case LED_2:
|
case 1:
|
||||||
BIT_CLEAR(PORTD, PD6);
|
BIT_CLEAR(PORTD, PD6);
|
||||||
break;
|
break;
|
||||||
case LED_3:
|
case 2:
|
||||||
BIT_CLEAR(PORTC, PC7);
|
BIT_CLEAR(PORTC, PC7);
|
||||||
break;
|
break;
|
||||||
case LED_4:
|
case 3:
|
||||||
BIT_CLEAR(PORTC, PC6);
|
BIT_CLEAR(PORTC, PC6);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -95,13 +95,13 @@ bool led_state(
|
|||||||
uint8_t index)
|
uint8_t index)
|
||||||
{
|
{
|
||||||
switch (index) {
|
switch (index) {
|
||||||
case LED_1:
|
case 0:
|
||||||
return (BIT_CHECK(PIND, PD7));
|
return (BIT_CHECK(PIND, PD7));
|
||||||
case LED_2:
|
case 1:
|
||||||
return (BIT_CHECK(PIND, PD6));
|
return (BIT_CHECK(PIND, PD6));
|
||||||
case LED_3:
|
case 2:
|
||||||
return (BIT_CHECK(PINC, PC7));
|
return (BIT_CHECK(PINC, PC7));
|
||||||
case LED_4:
|
case 3:
|
||||||
return (BIT_CHECK(PINC, PC6));
|
return (BIT_CHECK(PINC, PC6));
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -27,12 +27,6 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#define LED_1 0
|
|
||||||
#define LED_2 1
|
|
||||||
#define LED_3 2
|
|
||||||
#define LED_4 3
|
|
||||||
#define MAX_LEDS 4
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
|||||||
@@ -50,13 +50,13 @@ int main(
|
|||||||
void)
|
void)
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
adc_init();
|
|
||||||
led_init();
|
|
||||||
input_init();
|
|
||||||
timer_init();
|
timer_init();
|
||||||
|
adc_init();
|
||||||
|
input_init();
|
||||||
seeprom_init();
|
seeprom_init();
|
||||||
rs485_init();
|
rs485_init();
|
||||||
serial_init();
|
serial_init();
|
||||||
|
led_init();
|
||||||
bacnet_init();
|
bacnet_init();
|
||||||
test_init();
|
test_init();
|
||||||
/* Enable global interrupts */
|
/* Enable global interrupts */
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ bool rs485_byte_available(
|
|||||||
bool data_available = false; /* return value */
|
bool data_available = false; /* return value */
|
||||||
|
|
||||||
if (!FIFO_Empty(&Receive_Buffer)) {
|
if (!FIFO_Empty(&Receive_Buffer)) {
|
||||||
led_on_interval(LED_1, 1);
|
led_on_interval(LED_4, 1);
|
||||||
*data_register = FIFO_Get(&Receive_Buffer);
|
*data_register = FIFO_Get(&Receive_Buffer);
|
||||||
data_available = true;
|
data_available = true;
|
||||||
}
|
}
|
||||||
@@ -144,7 +144,7 @@ void rs485_bytes_send(
|
|||||||
uint8_t * buffer, /* data to send */
|
uint8_t * buffer, /* data to send */
|
||||||
uint16_t nbytes)
|
uint16_t nbytes)
|
||||||
{ /* number of bytes of data */
|
{ /* number of bytes of data */
|
||||||
led_on(LED_2);
|
led_on(LED_5);
|
||||||
while (!BIT_CHECK(UCSR0A, UDRE0)) {
|
while (!BIT_CHECK(UCSR0A, UDRE0)) {
|
||||||
/* do nothing - wait until Tx buffer is empty */
|
/* do nothing - wait until Tx buffer is empty */
|
||||||
}
|
}
|
||||||
@@ -168,7 +168,7 @@ void rs485_bytes_send(
|
|||||||
/* Clear the Transmit Complete flag by writing a one to it. */
|
/* Clear the Transmit Complete flag by writing a one to it. */
|
||||||
BIT_SET(UCSR0A, TXC0);
|
BIT_SET(UCSR0A, TXC0);
|
||||||
timer_elapsed_start(&Silence_Timer);
|
timer_elapsed_start(&Silence_Timer);
|
||||||
led_off_delay(LED_2, 1);
|
led_off_delay(LED_5, 1);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,7 @@
|
|||||||
#include "rs485.h"
|
#include "rs485.h"
|
||||||
#include "npdu.h"
|
#include "npdu.h"
|
||||||
#include "bits.h"
|
#include "bits.h"
|
||||||
|
#include "ringbuf.h"
|
||||||
|
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#define STRICT 1
|
#define STRICT 1
|
||||||
|
|||||||
Reference in New Issue
Block a user