diff --git a/bacnet-stack/demo/object/ai.h b/bacnet-stack/demo/object/ai.h
index 0bd3c4fb..fc0e7811 100644
--- a/bacnet-stack/demo/object/ai.h
+++ b/bacnet-stack/demo/object/ai.h
@@ -43,7 +43,7 @@ extern "C" {
#endif /* __cplusplus */
typedef struct analog_input_descr {
- uint8_t Event_State:3;
+ unsigned Event_State:3;
float Present_Value;
BACNET_RELIABILITY Reliability;
bool Out_Of_Service;
@@ -54,9 +54,9 @@ extern "C" {
float High_Limit;
float Low_Limit;
float Deadband;
- uint8_t Limit_Enable:2;
- uint8_t Event_Enable:3;
- uint8_t Notify_Type:1;
+ unsigned Limit_Enable:2;
+ unsigned Event_Enable:3;
+ unsigned Notify_Type:1;
ACKED_INFO Acked_Transitions[MAX_BACNET_EVENT_TRANSITION];
BACNET_DATE_TIME Event_Time_Stamps[MAX_BACNET_EVENT_TRANSITION];
/* time to generate event notification */
diff --git a/bacnet-stack/demo/object/av.h b/bacnet-stack/demo/object/av.h
index 08a62575..1171fd9c 100644
--- a/bacnet-stack/demo/object/av.h
+++ b/bacnet-stack/demo/object/av.h
@@ -44,7 +44,7 @@ extern "C" {
#endif /* __cplusplus */
typedef struct analog_value_descr {
- uint8_t Event_State:3;
+ unsigned Event_State:3;
bool Out_Of_Service;
uint8_t Units;
/* Here is our Priority Array. They are supposed to be Real, but */
@@ -58,9 +58,9 @@ extern "C" {
float High_Limit;
float Low_Limit;
float Deadband;
- uint8_t Limit_Enable:2;
- uint8_t Event_Enable:3;
- uint8_t Notify_Type:1;
+ unsigned Limit_Enable:2;
+ unsigned Event_Enable:3;
+ unsigned Notify_Type:1;
ACKED_INFO Acked_Transitions[MAX_BACNET_EVENT_TRANSITION];
BACNET_DATE_TIME Event_Time_Stamps[MAX_BACNET_EVENT_TRANSITION];
/* time to generate event notification */
diff --git a/bacnet-stack/include/bacenum.h b/bacnet-stack/include/bacenum.h
index 59fab6bb..f6c35d96 100644
--- a/bacnet-stack/include/bacenum.h
+++ b/bacnet-stack/include/bacenum.h
@@ -1243,10 +1243,10 @@ typedef enum {
/* Enumerated values 0-63 are reserved for definition by ASHRAE. */
/* Enumerated values 64-65535 may be used by others subject to */
/* the procedures and constraints described in Clause 23. */
- MAX_BACNET_ABORT_REASON = 5,
- FIRST_PROPRIETARY_ABORT_REASON = 64,
- LAST_PROPRIETARY_ABORT_REASON = 65535
+ MAX_BACNET_ABORT_REASON = 5
} BACNET_ABORT_REASON;
+#define FIRST_PROPRIETARY_ABORT_REASON 64
+#define LAST_PROPRIETARY_ABORT_REASON 65535
typedef enum {
REJECT_REASON_OTHER = 0,
@@ -1262,10 +1262,10 @@ typedef enum {
/* Enumerated values 0-63 are reserved for definition by ASHRAE. */
/* Enumerated values 64-65535 may be used by others subject to */
/* the procedures and constraints described in Clause 23. */
- MAX_BACNET_REJECT_REASON = 10,
- FIRST_PROPRIETARY_REJECT_REASON = 64,
- LAST_PROPRIETARY_REJECT_REASON = 65535
+ MAX_BACNET_REJECT_REASON = 10
} BACNET_REJECT_REASON;
+#define FIRST_PROPRIETARY_REJECT_REASON 64
+#define LAST_PROPRIETARY_REJECT_REASON 65535
typedef enum {
ERROR_CLASS_DEVICE = 0,
@@ -1279,10 +1279,10 @@ typedef enum {
/* Enumerated values 0-63 are reserved for definition by ASHRAE. */
/* Enumerated values 64-65535 may be used by others subject to */
/* the procedures and constraints described in Clause 23. */
- MAX_BACNET_ERROR_CLASS = 8,
- FIRST_PROPRIETARY_ERROR_CLASS = 64,
- LAST_PROPRIETARY_ERROR_CLASS = 65535
+ MAX_BACNET_ERROR_CLASS = 8
} BACNET_ERROR_CLASS;
+#define FIRST_PROPRIETARY_ERROR_CLASS 64
+#define LAST_PROPRIETARY_ERROR_CLASS 65535
/* These are sorted in the order given in
Clause 18. ERROR, REJECT AND ABORT CODES
@@ -1395,14 +1395,14 @@ typedef enum {
ERROR_CODE_UNKNOWN_FILE_SIZE = 81,
ERROR_CODE_BUSY = 82,
ERROR_CODE_COMMUNICATION_DISABLED = 83,
- MAX_BACNET_ERROR_CODE = 84,
+ MAX_BACNET_ERROR_CODE = 84
/* Enumerated values 0-255 are reserved for definition by ASHRAE. */
/* Enumerated values 256-65535 may be used by others subject to */
/* the procedures and constraints described in Clause 23. */
/* The last enumeration used in this version is 50. */
- FIRST_PROPRIETARY_ERROR_CODE = 256,
- LAST_PROPRIETARY_ERROR_CODE = 65535
} BACNET_ERROR_CODE;
+#define FIRST_PROPRIETARY_ERROR_CODE 256
+#define LAST_PROPRIETARY_ERROR_CODE 65535
typedef enum {
BACNET_REINIT_COLDSTART = 0,
diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/adc.c b/bacnet-stack/ports/bdk-atxx4-mstp/adc.c
index 494e90e0..e8b59a6c 100644
--- a/bacnet-stack/ports/bdk-atxx4-mstp/adc.c
+++ b/bacnet-stack/ports/bdk-atxx4-mstp/adc.c
@@ -52,12 +52,11 @@
static volatile uint16_t Sample_Result[ADC_CHANNELS_MAX];
static volatile uint8_t Enabled_Channels;
-/* forward prototype */
-ISR(ADC_vect);
-
ISR(ADC_vect)
{
uint8_t index;
+ uint8_t mask;
+ uint8_t channels;
uint16_t value = 0;
/* determine which conversion finished */
@@ -66,13 +65,18 @@ ISR(ADC_vect)
value = ADCL;
value |= (ADCH << 8);
Sample_Result[index] = value;
+ channels = Enabled_Channels;
__enable_interrupt();
/* clear the mux */
BITMASK_CLEAR(ADMUX, ((1 << MUX2) | (1 << MUX1) | (1 << MUX0)));
- /* find the next channel */
- while (Enabled_Channels) {
- index = (index + 1) % ADC_CHANNELS_MAX;
- if (BIT_CHECK(Enabled_Channels, index)) {
+ /* find the next enabled channel */
+ while (channels) {
+ index++;
+ if (index >= ADC_CHANNELS_MAX) {
+ index = 0;
+ }
+ mask = 1 << index;
+ if (channels & mask) {
break;
}
}
diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/bacnet.hzp b/bacnet-stack/ports/bdk-atxx4-mstp/bacnet.hzp
new file mode 100644
index 00000000..8d9d9479
--- /dev/null
+++ b/bacnet-stack/ports/bdk-atxx4-mstp/bacnet.hzp
@@ -0,0 +1,82 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/crossworks/stdbool.h b/bacnet-stack/ports/bdk-atxx4-mstp/crossworks/stdbool.h
new file mode 100644
index 00000000..03c27cab
--- /dev/null
+++ b/bacnet-stack/ports/bdk-atxx4-mstp/crossworks/stdbool.h
@@ -0,0 +1,20 @@
+#ifndef STDBOOL_H
+#define STDBOOL_H
+
+/* C99 Boolean types for compilers without C99 support */
+
+#ifndef __cplusplus
+typedef char _Bool;
+#ifndef bool
+#define bool _Bool
+#endif
+#ifndef true
+#define true 1
+#endif
+#ifndef false
+#define false 0
+#endif
+#define __bool_true_false_are_defined 1
+#endif
+
+#endif
diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/hardware.h b/bacnet-stack/ports/bdk-atxx4-mstp/hardware.h
index 2a143414..9530469f 100644
--- a/bacnet-stack/ports/bdk-atxx4-mstp/hardware.h
+++ b/bacnet-stack/ports/bdk-atxx4-mstp/hardware.h
@@ -30,16 +30,25 @@
#define F_CPU 18432000UL
#endif
+/* IAR compiler specific configuration */
#if defined(__ICCAVR__)
#include
#endif
+/* AVR-GCC compiler specific configuration */
#if defined(__GNUC__)
+#include
+#include
#if !defined(__AVR_ATmega644P__)
#error Firmware is configured for ATmega644P only (-mmcu=atmega644p)
#endif
- /* GCC specific configuration */
-#include
+#endif
+
+#if defined (__CROSSWORKS_AVR)
+#include
+#if (__TARGET_PROCESSOR != ATmega644P)
+#error Firmware is configured for ATmega644P only
+#endif
#endif
#include "iar2gcc.h"
diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/iar2gcc.h b/bacnet-stack/ports/bdk-atxx4-mstp/iar2gcc.h
index d7d25ec9..f22b3648 100644
--- a/bacnet-stack/ports/bdk-atxx4-mstp/iar2gcc.h
+++ b/bacnet-stack/ports/bdk-atxx4-mstp/iar2gcc.h
@@ -34,13 +34,21 @@
#ifndef IAR2GCC_H
#define IAR2GCC_H
+/* common embedded extensions for different compilers */
+
#if !defined(F_CPU)
#error You must define F_CPU - clock frequency!
#endif
+#if defined (__CROSSWORKS_AVR)
+#include
+#include
+#endif
+
/* IAR */
#if defined(__ICCAVR__)
#include
+#include
#include
/* inline function */
@@ -57,6 +65,52 @@ static inline void _delay_us(
#include
#endif
+/* adjust some definitions to common versions */
+#if defined (__CROSSWORKS_AVR)
+#if (__TARGET_PROCESSOR == ATmega644P)
+#define PRR PRR0
+#define UBRR0 UBRR0W
+#define UBRR1 UBRR1W
+
+#define PA0 PORTA0
+#define PA1 PORTA1
+#define PA2 PORTA2
+#define PA3 PORTA3
+#define PA4 PORTA4
+#define PA5 PORTA5
+#define PA6 PORTA6
+#define PA7 PORTA7
+
+#define PB0 PORTB0
+#define PB1 PORTB1
+#define PB2 PORTB2
+#define PB3 PORTB3
+#define PB4 PORTB4
+#define PB5 PORTB5
+#define PB6 PORTB6
+#define PB7 PORTB7
+
+#define PC0 PORTC0
+#define PC1 PORTC1
+#define PC2 PORTC2
+#define PC3 PORTC3
+#define PC4 PORTC4
+#define PC5 PORTC5
+#define PC6 PORTC6
+#define PC7 PORTC7
+
+#define PD0 PORTD0
+#define PD1 PORTD1
+#define PD2 PORTD2
+#define PD3 PORTD3
+#define PD4 PORTD4
+#define PD5 PORTD5
+#define PD6 PORTD6
+#define PD7 PORTD7
+
+#endif
+#endif
+
/* Input/Output Registers */
#if defined(__GNUC__)
#include
@@ -195,24 +249,27 @@ typedef struct {
#if defined(__ICCAVR__)
#define PRAGMA(x) _Pragma( #x )
#define ISR(vec) PRAGMA( vector=vec ) __interrupt void handler_##vec(void)
-#endif
-#if defined(__GNUC__)
+#elif defined(__GNUC__)
#include
+#elif defined (__CROSSWORKS_AVR)
+#define ISR(vec) void handler_##vec(void) __interrupt[vec]
+#else
+#error ISR() not defined!
#endif
/* Flash */
#if defined(__ICCAVR__)
#define FLASH_DECLARE(x) __flash x
-#endif
-#if defined(__GNUC__)
+#elif defined(__GNUC__)
#define FLASH_DECLARE(x) x __attribute__((__progmem__))
+#elif defined (__CROSSWORKS_AVR)
+#define FLASH_DECLARE (x) const __code x
#endif
/* EEPROM */
#if defined(__ICCAVR__)
#define EEPROM_DECLARE(x) __eeprom x
-#endif
-#if defined(__GNUC__)
+#elif defined(__GNUC__)
#include
#define EEPROM_DECLARE(x) x __attribute__((section (".eeprom")))
#if ((__GNUC__ < 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ < 3)) || \
@@ -221,6 +278,14 @@ typedef struct {
#define __EEPUT _EEPUT
#define __EEGET _EEGET
#endif
+#elif defined (__CROSSWORKS_AVR)
+/* use functions defined in crt0.s to mimic IAR macros */
+void __uint8_eeprom_store(unsigned char byte, unsigned addr);
+unsigned char __uint8_eeprom_load(unsigned addr);
+#define __EEPUT(addr, var) \
+ __uint8_eeprom_store((unsigned char)(var), (unsigned)(addr))
+#define __EEGET(var, addr) \
+ (var) = __uint8_eeprom_load((unsigned)(addr))
#endif
/* IAR intrinsic routines */
@@ -231,9 +296,8 @@ typedef struct {
#define __root
#endif
-
-/* watchdog */
-#if defined(__ICCAVR__)
+/* watchdog defines in GCC */
+#if defined(__ICCAVR__) || defined(__CROSSWORKS_AVR)
#define WDTO_15MS 0
#define WDTO_30MS 1
#define WDTO_60MS 2
@@ -244,4 +308,8 @@ typedef struct {
#define WDTO_2S 7
#endif
+#if defined(__CROSSWORKS_AVR)
+#define inline
+#endif
+
#endif
diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/led.c b/bacnet-stack/ports/bdk-atxx4-mstp/led.c
index 8beabced..a906ace2 100644
--- a/bacnet-stack/ports/bdk-atxx4-mstp/led.c
+++ b/bacnet-stack/ports/bdk-atxx4-mstp/led.c
@@ -96,13 +96,13 @@ bool led_state(
{
switch (index) {
case 0:
- return (BIT_CHECK(PIND, PD7));
+ return (BIT_CHECK(PIND, PIND7));
case 1:
- return (BIT_CHECK(PIND, PD6));
+ return (BIT_CHECK(PIND, PIND6));
case 2:
- return (BIT_CHECK(PINC, PC7));
+ return (BIT_CHECK(PINC, PINC7));
case 3:
- return (BIT_CHECK(PINC, PC6));
+ return (BIT_CHECK(PINC, PINC6));
default:
break;
}
diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/main.c b/bacnet-stack/ports/bdk-atxx4-mstp/main.c
index 5698a050..c45fb2fe 100644
--- a/bacnet-stack/ports/bdk-atxx4-mstp/main.c
+++ b/bacnet-stack/ports/bdk-atxx4-mstp/main.c
@@ -39,9 +39,10 @@
#include "bacnet.h"
#include "test.h"
#include "watchdog.h"
+#include "version.h"
-/* local version override */
-char *BACnet_Version = "1.0";
+/* global - currently the version of the stack */
+char *BACnet_Version = BACNET_VERSION_TEXT;
/* For porting to IAR, see:
http://www.avrfreaks.net/wiki/index.php/Documentation:AVR_GCC/IarToAvrgcc*/
diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/rs485.c b/bacnet-stack/ports/bdk-atxx4-mstp/rs485.c
index a0da5306..d1c68b97 100644
--- a/bacnet-stack/ports/bdk-atxx4-mstp/rs485.c
+++ b/bacnet-stack/ports/bdk-atxx4-mstp/rs485.c
@@ -32,8 +32,6 @@
/* me */
#include "rs485.h"
-/* forward prototype */
-ISR(USART0_RX_vect);
/* baud rate */
static uint32_t Baud_Rate = 9600;
diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/serial.c b/bacnet-stack/ports/bdk-atxx4-mstp/serial.c
index a94610fa..281517e3 100644
--- a/bacnet-stack/ports/bdk-atxx4-mstp/serial.c
+++ b/bacnet-stack/ports/bdk-atxx4-mstp/serial.c
@@ -30,8 +30,6 @@
/* baud rate */
static uint32_t Baud_Rate = 9600;
-/* forward prototype */
-ISR(USART1_RX_vect);
/* buffer for storing received bytes - size must be power of two */
static uint8_t Receive_Buffer_Data[128];
diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/stack.c b/bacnet-stack/ports/bdk-atxx4-mstp/stack.c
index d68e9850..baf0b391 100644
--- a/bacnet-stack/ports/bdk-atxx4-mstp/stack.c
+++ b/bacnet-stack/ports/bdk-atxx4-mstp/stack.c
@@ -26,31 +26,7 @@
/* me */
#include "stack.h"
-#if defined(__ICCAVR__)
-void stack_init(
- void)
-{
-
-}
-
-unsigned stack_size(
- void)
-{
- return 0;
-}
-
-uint8_t stack_byte(
- unsigned offset)
-{
- return 0;
-}
-
-unsigned stack_unused(
- void)
-{
- return 0;
-}
-#else
+#if defined(__GNUC__)
/* stack checking */
extern uint8_t _end;
extern uint8_t __stack;
@@ -105,4 +81,28 @@ unsigned stack_unused(
}
return count;
}
+#else
+void stack_init(
+ void)
+{
+
+}
+
+unsigned stack_size(
+ void)
+{
+ return 0;
+}
+
+uint8_t stack_byte(
+ unsigned offset)
+{
+ return 0;
+}
+
+unsigned stack_unused(
+ void)
+{
+ return 0;
+}
#endif
diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/timer2.c b/bacnet-stack/ports/bdk-atxx4-mstp/timer2.c
index d477d544..47c4032e 100644
--- a/bacnet-stack/ports/bdk-atxx4-mstp/timer2.c
+++ b/bacnet-stack/ports/bdk-atxx4-mstp/timer2.c
@@ -30,9 +30,11 @@
#error "F_CPU must be defined for Timer configuration."
#endif
/* Timer2 Prescaling: 1, 8, 32, 64, 128, 256, or 1024 */
-#define TIMER_MICROSECONDS 1000
-#define TIMER_TICKS(p) ((((F_CPU)/(p)/1000)*(TIMER_MICROSECONDS))/1000)
-#define TIMER_TICKS_MAX 0xff
+#define TIMER_MICROSECONDS 1000UL
+#define TIMER_TICKS(p) \
+ (((((F_CPU)/(p))/1000UL) \
+ *(TIMER_MICROSECONDS))/1000UL)
+#define TIMER_TICKS_MAX 255UL
/* adjust the prescaler for the processor clock */
#if (TIMER_TICKS(1) <= TIMER_TICKS_MAX)
#define TIMER2_PRESCALER 1
@@ -58,8 +60,6 @@
/* counter for the the timer which wraps every 49.7 days */
static volatile uint32_t Millisecond_Counter;
static volatile uint8_t Millisecond_Counter_Byte;
-/* forward prototype */
-ISR(TIMER2_OVF_vect);
/*************************************************************************
* Description: Timer Interrupt Handler
diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/watchdog.c b/bacnet-stack/ports/bdk-atxx4-mstp/watchdog.c
index cca819e4..3ab8e29b 100644
--- a/bacnet-stack/ports/bdk-atxx4-mstp/watchdog.c
+++ b/bacnet-stack/ports/bdk-atxx4-mstp/watchdog.c
@@ -24,8 +24,7 @@
#include "hardware.h"
#include "watchdog.h"
-#if defined(__ICCAVR__)
-#include
+#if !defined(__GNUC__)
static inline void wdt_enable(
int value)
{