diff --git a/bacnet-stack/demo/object/av.c b/bacnet-stack/demo/object/av.c
index 665a32d8..78efbf1a 100644
--- a/bacnet-stack/demo/object/av.c
+++ b/bacnet-stack/demo/object/av.c
@@ -34,8 +34,7 @@
#include "bacapp.h"
#include "config.h" /* the custom stuff */
#include "wp.h"
-
-#define MAX_ANALOG_VALUES 4
+#include "av.h"
/* we choose to have a NULL level in our system represented by */
/* a particular value. When the priorities are not in use, they */
diff --git a/bacnet-stack/include/av.h b/bacnet-stack/include/av.h
index d271366a..1b99117e 100644
--- a/bacnet-stack/include/av.h
+++ b/bacnet-stack/include/av.h
@@ -31,6 +31,10 @@
#include "bacerror.h"
#include "wp.h"
+#ifndef MAX_ANALOG_VALUES
+#define MAX_ANALOG_VALUES 4
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
diff --git a/bacnet-stack/ports/atmega168/av.c b/bacnet-stack/ports/atmega168/av.c
index 78b09296..6026382a 100644
--- a/bacnet-stack/ports/atmega168/av.c
+++ b/bacnet-stack/ports/atmega168/av.c
@@ -33,6 +33,7 @@
#include "bacapp.h"
#include "config.h" /* the custom stuff */
#include "wp.h"
+#include "av.h"
#if (MAX_ANALOG_VALUES > 10)
#error Modify the Analog_Value_Name to handle multiple digits
diff --git a/bacnet-stack/ports/atmega168/bacnet.ewp b/bacnet-stack/ports/atmega168/bacnet.ewp
index c569fa46..606ee98e 100644
--- a/bacnet-stack/ports/atmega168/bacnet.ewp
+++ b/bacnet-stack/ports/atmega168/bacnet.ewp
@@ -10,9 +10,9 @@
1
General
- 3
+ 5
- 6
+ 7
1
1
+
ICCAVR
- 3
+ 4
- 12
+ 13
1
1
+
AAVR
- 3
+ 4
- 9
+ 10
1
1
-
-
-
@@ -707,7 +703,7 @@
FormatVariant
- 7
+ 8
2
@@ -1857,7 +1849,7 @@
ExtraFormatVariant
- 7
+ 8
2
@@ -2026,9 +2018,6 @@
$PROJ_DIR$\..\..\demo\handler\txbuf.c
-
- $PROJ_DIR$\..\..\src\version.c
-
$PROJ_DIR$\..\..\src\whois.c
diff --git a/bacnet-stack/ports/atmega168/hardware.h b/bacnet-stack/ports/atmega168/hardware.h
index e096ec22..c04c9199 100644
--- a/bacnet-stack/ports/atmega168/hardware.h
+++ b/bacnet-stack/ports/atmega168/hardware.h
@@ -27,7 +27,7 @@
#if !defined(F_CPU)
/* The processor clock frequency */
-#define F_CPU (7372800)
+#define F_CPU 7372800UL
#endif
#if defined(__IAR_SYSTEMS_ICC__) || defined(__IAR_SYSTEMS_ASM__)
diff --git a/bacnet-stack/ports/atmega168/iar2gcc.h b/bacnet-stack/ports/atmega168/iar2gcc.h
index 7afbfd41..03dcb8ce 100644
--- a/bacnet-stack/ports/atmega168/iar2gcc.h
+++ b/bacnet-stack/ports/atmega168/iar2gcc.h
@@ -34,25 +34,26 @@
#ifndef IAR2GCC_H
#define IAR2GCC_H
+#if !defined(F_CPU)
+#define F_CPU (7372800)
+#endif
+
#if defined(__IAR_SYSTEMS_ICC__) || defined(__IAR_SYSTEMS_ASM__)
#include
#include
#define _BV(bit_num) (1 << (bit_num))
-#define _delay_us(x) \
/* inline function */
-static inline void delay_us(
+static inline void _delay_us(
uint8_t microseconds)
{
do {
- __delay_cycles(F_CPU / 1000000);
+ __delay_cycles(F_CPU / 1000000UL);
} while (microseconds--);
}
#else
-#if !defined(F_CPU)
-#define F_CPU (7372800)
-#endif
+/* GCC */
#include
#include
#include
diff --git a/bacnet-stack/ports/atmega168/main.c b/bacnet-stack/ports/atmega168/main.c
index 41599fdf..bc0febf6 100644
--- a/bacnet-stack/ports/atmega168/main.c
+++ b/bacnet-stack/ports/atmega168/main.c
@@ -33,6 +33,7 @@
#include "txbuf.h"
#include "iam.h"
#include "device.h"
+#include "av.h"
const char *BACnet_Version = "1.0";
diff --git a/bacnet-stack/ports/atmega168/rs485.c b/bacnet-stack/ports/atmega168/rs485.c
index 2d4ea2b3..5946ff15 100644
--- a/bacnet-stack/ports/atmega168/rs485.c
+++ b/bacnet-stack/ports/atmega168/rs485.c
@@ -56,13 +56,6 @@ static uint32_t RS485_Baud = 9600;
#define Tturnaround (40UL)
/* turnaround_time_milliseconds = (Tturnaround*1000UL)/RS485_Baud; */
-/* The maximum time after the end of the stop bit of the final */
-/* octet of a transmitted frame before a node must disable its */
-/* EIA-485 driver: 15 bit times. */
-/* NOTE: AVR lib delay_us limit is 768us; limit is 7bits/9600bps=729us */
-#define Tpostdrive1 (7UL)
-#define Tpostdrive2 (7UL)
-
/****************************************************************************
* DESCRIPTION: Initializes the RS485 hardware and variables, and starts in
* receive mode.
@@ -176,12 +169,6 @@ void RS485_Transmitter_Enable(
if (enable) {
BIT_SET(PORTD, PD2);
} else {
-#if Tpostdrive1
- _delay_us(Tpostdrive1 / RS485_Baud);
-#endif
-#if Tpostdrive2
- _delay_us(Tpostdrive2 / RS485_Baud);
-#endif
BIT_CLEAR(PORTD, PD2);
}
}
@@ -254,15 +241,13 @@ void RS485_Send_Data(
buffer++;
nbytes--;
}
- while (!BIT_CHECK(UCSR0A, UDRE0)) {
- /* do nothing - wait until Tx buffer is empty */
- }
- /* is the frame sent? */
+ /* Clear the Transmit Complete flag by writing a one to it. */
+ BIT_SET(UCSR0A, TXC0);
+ /* was the frame sent? */
while (!BIT_CHECK(UCSR0A, TXC0)) {
- /* do nothing - wait until the entire frame in the
+ /* do nothing - wait until the entire frame in the
Transmit Shift Register has been shifted out */
}
- BIT_CLEAR(UCSR0A, TXC0);
/* per MSTP spec, sort of */
Timer_Silence_Reset();
}
@@ -304,7 +289,7 @@ bool RS485_ReceiveError(
}
/****************************************************************************
-* DESCRIPTION: Return true if data is available
+* DESCRIPTION: Return true if data is available
* RETURN: true if data is available, with the data in the parameter set
* ALGORITHM: none
* NOTES: none