From 21426e12f73ab6b1c1e0617d422c8d4c79b9d2fc Mon Sep 17 00:00:00 2001 From: skarg Date: Tue, 7 Sep 2010 16:18:55 +0000 Subject: [PATCH] Added example project and workspace for IAR for AVR compiler, and fixed compiler errors and warnings after doing such a deed. --- bacnet-stack/ports/bdk-atxx4-mstp/adc.c | 2 + bacnet-stack/ports/bdk-atxx4-mstp/av.c | 22 +- bacnet-stack/ports/bdk-atxx4-mstp/bacnet.ewp | 2150 ++++++++++++++++++ bacnet-stack/ports/bdk-atxx4-mstp/bacnet.eww | 10 + bacnet-stack/ports/bdk-atxx4-mstp/bo.c | 13 +- bacnet-stack/ports/bdk-atxx4-mstp/device.c | 12 +- bacnet-stack/ports/bdk-atxx4-mstp/iar2gcc.h | 2 - bacnet-stack/ports/bdk-atxx4-mstp/init.c | 5 +- bacnet-stack/ports/bdk-atxx4-mstp/led.c | 4 - bacnet-stack/ports/bdk-atxx4-mstp/main.c | 5 +- bacnet-stack/ports/bdk-atxx4-mstp/rs485.c | 2 + bacnet-stack/ports/bdk-atxx4-mstp/serial.c | 2 + bacnet-stack/ports/bdk-atxx4-mstp/stack.c | 25 + bacnet-stack/ports/bdk-atxx4-mstp/timer2.c | 2 + bacnet-stack/ports/bdk-atxx4-mstp/watchdog.c | 99 + bacnet-stack/ports/bdk-atxx4-mstp/watchdog.h | 38 + 16 files changed, 2359 insertions(+), 34 deletions(-) create mode 100644 bacnet-stack/ports/bdk-atxx4-mstp/bacnet.ewp create mode 100644 bacnet-stack/ports/bdk-atxx4-mstp/bacnet.eww create mode 100644 bacnet-stack/ports/bdk-atxx4-mstp/watchdog.c create mode 100644 bacnet-stack/ports/bdk-atxx4-mstp/watchdog.h diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/adc.c b/bacnet-stack/ports/bdk-atxx4-mstp/adc.c index 8120e192..ce5b29fc 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/adc.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/adc.c @@ -49,6 +49,8 @@ /* we could have array of ADC results */ static volatile uint8_t Sample_Result; +/* forward prototype */ +ISR(ADC_vect); ISR(ADC_vect) { diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/av.c b/bacnet-stack/ports/bdk-atxx4-mstp/av.c index c10468ed..493228bd 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/av.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/av.c @@ -28,11 +28,6 @@ #include #include #include -#if defined(__GNUC__) && (__GNUC__ > 4) && (__GNUC_MINOR__ > 2) -#include /* for NAN */ -#else -#define NAN __builtin_nan("") -#endif #include "bacdef.h" #include "bacdcode.h" @@ -42,6 +37,7 @@ #include "wp.h" #include "av.h" #include "handlers.h" +#include "hardware.h" #ifndef MAX_ANALOG_VALUES #define MAX_ANALOG_VALUES 2 @@ -141,7 +137,7 @@ unsigned Analog_Value_Instance_To_Index( float Analog_Value_Present_Value( uint32_t object_instance) { - float value = NAN; + float value = 0; unsigned index = 0; index = Analog_Value_Instance_To_Index(object_instance); @@ -328,8 +324,8 @@ bool Analog_Value_Write_Property( unsigned int object_index = 0; unsigned int priority = 0; #endif - int len = 0; BACNET_APPLICATION_DATA_VALUE value; + int len = 0; /* decode the some of the request */ len = @@ -358,16 +354,6 @@ bool Analog_Value_Write_Property( wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; } } -#if 0 - } else if (value.tag == BACNET_APPLICATION_TAG_NULL) { - if (Analog_Value_Present_Value_Set(wp_data->object_instance, - NAN, wp_data->priority)) { - status = true; - } else { - wp_data->error_class = ERROR_CLASS_PROPERTY; - wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; - } -#endif } break; #if 0 @@ -387,6 +373,8 @@ bool Analog_Value_Write_Property( wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED; break; } + /* not using len at this time */ + len = len; return status; } diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/bacnet.ewp b/bacnet-stack/ports/bdk-atxx4-mstp/bacnet.ewp new file mode 100644 index 00000000..0191c708 --- /dev/null +++ b/bacnet-stack/ports/bdk-atxx4-mstp/bacnet.ewp @@ -0,0 +1,2150 @@ + + + + 2 + + Debug + + AVR + + 1 + + General + 9 + + 8 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ICCAVR + 5 + + 14 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + AAVR + 4 + + 10 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + CUSTOM + 3 + + + + + + + BICOMP + 0 + + + + BUILDACTION + 1 + + + + + + + XLINK + 2 + + 13 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + XAR + 2 + + 0 + 1 + 1 + + + + + + + BILINK + 0 + + + + + Release + + AVR + + 0 + + General + 9 + + 8 + 1 + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ICCAVR + 5 + + 14 + 1 + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + AAVR + 4 + + 10 + 1 + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + CUSTOM + 3 + + + + + + + BICOMP + 0 + + + + BUILDACTION + 1 + + + + + + + XLINK + 2 + + 13 + 1 + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + XAR + 2 + + 0 + 1 + 0 + + + + + + + BILINK + 0 + + + + + BACnet-Core + + $PROJ_DIR$\..\..\src\abort.c + + + $PROJ_DIR$\..\..\src\apdu.c + + + $PROJ_DIR$\..\..\src\bacaddr.c + + + $PROJ_DIR$\..\..\src\bacapp.c + + + $PROJ_DIR$\..\..\src\bacdcode.c + + + $PROJ_DIR$\..\..\src\bacerror.c + + + $PROJ_DIR$\..\..\src\bacint.c + + + $PROJ_DIR$\..\..\src\bacreal.c + + + $PROJ_DIR$\..\..\src\bacstr.c + + + $PROJ_DIR$\..\..\src\crc.c + + + $PROJ_DIR$\..\..\src\dcc.c + + + $PROJ_DIR$\..\..\src\fifo.c + + + $PROJ_DIR$\..\..\src\iam.c + + + $PROJ_DIR$\..\..\src\ihave.c + + + $PROJ_DIR$\..\..\src\memcopy.c + + + $PROJ_DIR$\..\..\src\npdu.c + + + $PROJ_DIR$\..\..\src\rd.c + + + $PROJ_DIR$\..\..\src\reject.c + + + $PROJ_DIR$\..\..\src\rp.c + + + $PROJ_DIR$\..\..\src\rpm.c + + + $PROJ_DIR$\..\..\src\whohas.c + + + $PROJ_DIR$\..\..\src\whois.c + + + $PROJ_DIR$\..\..\src\wp.c + + + + BACnet-Demo + + $PROJ_DIR$\..\..\demo\handler\h_dcc.c + + + $PROJ_DIR$\..\..\demo\handler\h_npdu.c + + + $PROJ_DIR$\..\..\demo\handler\h_rd.c + + + $PROJ_DIR$\..\..\demo\handler\h_rp.c + + + $PROJ_DIR$\..\..\demo\handler\h_rpm.c + + + $PROJ_DIR$\..\..\demo\handler\h_whohas.c + + + $PROJ_DIR$\..\..\demo\handler\h_whois.c + + + $PROJ_DIR$\..\..\demo\handler\h_wp.c + + + $PROJ_DIR$\..\..\demo\handler\noserv.c + + + $PROJ_DIR$\..\..\demo\handler\s_iam.c + + + $PROJ_DIR$\..\..\demo\handler\s_ihave.c + + + $PROJ_DIR$\..\..\demo\handler\txbuf.c + + + + $PROJ_DIR$\adc.c + + + $PROJ_DIR$\ai.c + + + $PROJ_DIR$\av.c + + + $PROJ_DIR$\bacnet.c + + + $PROJ_DIR$\bi.c + + + $PROJ_DIR$\bo.c + + + $PROJ_DIR$\device.c + + + $PROJ_DIR$\dlmstp.c + + + $PROJ_DIR$\eeprom.c + + + $PROJ_DIR$\fuses.c + + + $PROJ_DIR$\init.c + + + $PROJ_DIR$\input.c + + + $PROJ_DIR$\led.c + + + $PROJ_DIR$\main.c + + + $PROJ_DIR$\rs485.c + + + $PROJ_DIR$\seeprom.c + + + $PROJ_DIR$\serial.c + + + $PROJ_DIR$\stack.c + + + $PROJ_DIR$\test.c + + + $PROJ_DIR$\timer.c + + + $PROJ_DIR$\timer2.c + + + $PROJ_DIR$\watchdog.c + + + + diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/bacnet.eww b/bacnet-stack/ports/bdk-atxx4-mstp/bacnet.eww new file mode 100644 index 00000000..7a4cd894 --- /dev/null +++ b/bacnet-stack/ports/bdk-atxx4-mstp/bacnet.eww @@ -0,0 +1,10 @@ + + + + + $WS_DIR$\bacnet.ewp + + + + + diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/bo.c b/bacnet-stack/ports/bdk-atxx4-mstp/bo.c index c02c1ddc..e2835b22 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/bo.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/bo.c @@ -138,9 +138,9 @@ static BACNET_BINARY_PV Present_Value( if (index < MAX_BINARY_OUTPUTS) { for (i = 0; i < BACNET_MAX_PRIORITY; i++) { - current_value = Binary_Output_Level[index][i]; + current_value = (BACNET_BINARY_PV)Binary_Output_Level[index][i]; if (current_value != BINARY_NULL) { - value = Binary_Output_Level[index][i]; + value = (BACNET_BINARY_PV)Binary_Output_Level[index][i]; break; } } @@ -321,7 +321,8 @@ int Binary_Output_Read_Property( Binary_Output_Instance_To_Index(rpdata->object_instance); for (i = 0; i < BACNET_MAX_PRIORITY; i++) { /* FIXME: check if we have room before adding it to APDU */ - present_value = Binary_Output_Level[object_index][i]; + present_value = (BACNET_BINARY_PV) + Binary_Output_Level[object_index][i]; if (present_value == BINARY_NULL) { len = encode_application_null(&apdu[apdu_len]); } else { @@ -343,7 +344,7 @@ int Binary_Output_Read_Property( object_index = Binary_Output_Instance_To_Index(rpdata->object_instance); if (rpdata->array_index <= BACNET_MAX_PRIORITY) { - present_value = + present_value = (BACNET_BINARY_PV) Binary_Output_Level[object_index][rpdata->array_index - 1]; if (present_value == BINARY_NULL) { @@ -479,7 +480,7 @@ bool Binary_Output_Write_Property( if (status) { if (value.type.Enumerated < MAX_POLARITY) { Binary_Output_Polarity_Set(wp_data->object_instance, - value.type.Enumerated); + (BACNET_POLARITY)value.type.Enumerated); Binary_Output_Level_Sync(wp_data->object_instance); } else { status = false; @@ -493,6 +494,8 @@ bool Binary_Output_Write_Property( wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED; break; } + /* not using len at this time */ + len = len; return status; } diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/device.c b/bacnet-stack/ports/bdk-atxx4-mstp/device.c index e49fc550..81321f7e 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/device.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/device.c @@ -389,6 +389,12 @@ bool Device_Reinitialize( return status; } +BACNET_REINITIALIZED_STATE Device_Reinitialized_State( + void) +{ + return Reinitialize_State; +} + void Device_Init( void) { @@ -579,7 +585,7 @@ char *Device_Valid_Object_Id( char *name = NULL; /* return value */ struct object_functions *pObject = NULL; - pObject = Device_Objects_Find_Functions(object_type); + pObject = Device_Objects_Find_Functions((BACNET_OBJECT_TYPE)object_type); if ((pObject) && (pObject->Object_Name)) { name = pObject->Object_Name(object_instance); } @@ -656,7 +662,7 @@ int Device_Read_Property_Local( for (i = 0; i < MAX_BACNET_SERVICES_SUPPORTED; i++) { /* automatic lookup based on handlers set */ bitstring_set_bit(&bit_string, (uint8_t) i, - apdu_service_supported(i)); + apdu_service_supported((BACNET_SERVICES_SUPPORTED)i)); } apdu_len = encode_application_bitstring(&apdu[0], &bit_string); break; @@ -902,6 +908,8 @@ bool Device_Write_Property_Local( wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED; break; } + /* not using len at this time */ + len = len; return status; } diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/iar2gcc.h b/bacnet-stack/ports/bdk-atxx4-mstp/iar2gcc.h index 5cf55264..22ecddee 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/iar2gcc.h +++ b/bacnet-stack/ports/bdk-atxx4-mstp/iar2gcc.h @@ -234,8 +234,6 @@ typedef struct { /* watchdog */ #if defined(__ICCAVR__) -#include -#define watchdog_reset __watchdog_reset #define WDTO_15MS 0 #define WDTO_30MS 1 #define WDTO_60MS 2 diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/init.c b/bacnet-stack/ports/bdk-atxx4-mstp/init.c index f1f8bd22..ace93ec6 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/init.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/init.c @@ -23,6 +23,7 @@ * *********************************************************************/ #include "hardware.h" +#include "watchdog.h" /* me */ #include "init.h" @@ -61,8 +62,8 @@ void init( PORTD = 0; /* Configure the watchdog timer - Disabled for debugging */ #ifdef NDEBUG - wdt_enable(WDTO_2S); + watchdog_init(WDTO_2S); #else - wdt_disable(); + watchdog_init(0); #endif } diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/led.c b/bacnet-stack/ports/bdk-atxx4-mstp/led.c index b7513b09..cfa50a2e 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/led.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/led.c @@ -97,16 +97,12 @@ bool led_state( switch (index) { case LED_1: return (BIT_CHECK(PIND, PD7)); - break; case LED_2: return (BIT_CHECK(PIND, PD6)); - break; case LED_3: return (BIT_CHECK(PINC, PC7)); - break; case LED_4: return (BIT_CHECK(PINC, PC6)); - break; default: break; } diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/main.c b/bacnet-stack/ports/bdk-atxx4-mstp/main.c index f1350ab7..b3ffc0c4 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/main.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/main.c @@ -38,9 +38,10 @@ #include "serial.h" #include "bacnet.h" #include "test.h" +#include "watchdog.h" /* local version override */ -const char *BACnet_Version = "1.0"; +char *BACnet_Version = "1.0"; /* For porting to IAR, see: http://www.avrfreaks.net/wiki/index.php/Documentation:AVR_GCC/IarToAvrgcc*/ @@ -61,7 +62,7 @@ int main( /* Enable global interrupts */ __enable_interrupt(); for (;;) { - wdt_reset(); + watchdog_reset(); input_task(); bacnet_task(); led_task(); diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/rs485.c b/bacnet-stack/ports/bdk-atxx4-mstp/rs485.c index 44032e76..59f7c8fa 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/rs485.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/rs485.c @@ -32,6 +32,8 @@ /* 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 281517e3..a94610fa 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/serial.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/serial.c @@ -30,6 +30,8 @@ /* 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 29c247b5..3de8bed3 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/stack.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/stack.c @@ -26,6 +26,30 @@ /* 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 /* stack checking */ extern uint8_t _end; extern uint8_t __stack; @@ -80,3 +104,4 @@ unsigned stack_unused( } return count; } +#endif \ No newline at end of file diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/timer2.c b/bacnet-stack/ports/bdk-atxx4-mstp/timer2.c index 89b0efbf..c6dca7d1 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/timer2.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/timer2.c @@ -56,6 +56,8 @@ /* counter for the the timer which wraps every 49.7 days */ static volatile uint32_t Millisecond_Counter; +/* forward prototype */ +ISR(TIMER2_OVF_vect); /************************************************************************* * Description: Timer Interrupt Service Routine - Timer Overflowed! diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/watchdog.c b/bacnet-stack/ports/bdk-atxx4-mstp/watchdog.c new file mode 100644 index 00000000..f7febec9 --- /dev/null +++ b/bacnet-stack/ports/bdk-atxx4-mstp/watchdog.c @@ -0,0 +1,99 @@ +/************************************************************************** +* +* Copyright (C) 2009 Steve Karg +* +* Permission is hereby granted, free of charge, to any person obtaining +* a copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*********************************************************************/ +#include "hardware.h" +#include "watchdog.h" + +#if defined(__ICCAVR__) +#include +static inline void wdt_enable(int value) +{ + __disable_interrupt(); + __watchdog_reset(); + /* Start timed equence */ + WDTCSR |= (1< +* +* Permission is hereby granted, free of charge, to any person obtaining +* a copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*********************************************************************/ +#ifndef WATCHDOG_H +#define WATCHDOG_H + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +void watchdog_reset(void); +void watchdog_init(unsigned milliseconds); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif