Added example project and workspace for IAR for AVR compiler, and fixed compiler errors and warnings after doing such a deed.

This commit is contained in:
skarg
2010-09-07 16:18:55 +00:00
parent e2314f0f5e
commit 21426e12f7
16 changed files with 2359 additions and 34 deletions
+2
View File
@@ -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)
{
+5 -17
View File
@@ -28,11 +28,6 @@
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#if defined(__GNUC__) && (__GNUC__ > 4) && (__GNUC_MINOR__ > 2)
#include <math.h> /* 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;
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<workspace>
<project>
<path>$WS_DIR$\bacnet.ewp</path>
</project>
<batchBuild/>
</workspace>
+8 -5
View File
@@ -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;
}
+10 -2
View File
@@ -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;
}
@@ -234,8 +234,6 @@ typedef struct {
/* watchdog */
#if defined(__ICCAVR__)
#include <intrinsics.h>
#define watchdog_reset __watchdog_reset
#define WDTO_15MS 0
#define WDTO_30MS 1
#define WDTO_60MS 2
+3 -2
View File
@@ -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
}
-4
View File
@@ -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;
}
+3 -2
View File
@@ -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();
@@ -32,6 +32,8 @@
/* me */
#include "rs485.h"
/* forward prototype */
ISR(USART0_RX_vect);
/* baud rate */
static uint32_t Baud_Rate = 9600;
@@ -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];
+25
View File
@@ -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
@@ -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!
@@ -0,0 +1,99 @@
/**************************************************************************
*
* Copyright (C) 2009 Steve Karg <skarg@users.sourceforge.net>
*
* 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 <intrinsics.h>
static inline void wdt_enable(int value)
{
__disable_interrupt();
__watchdog_reset();
/* Start timed equence */
WDTCSR |= (1<<WDCE) | (1<<WDE);
/* Set new prescaler(time-out) value = 64K cycles (~0.5 s) */
WDTCSR = (1<<WDE) | (value);
/* we aren't ready to enable interrupts here
__enable_interrupt(); */
}
static inline void wdt_disable(void)
{
__disable_interrupt();
__watchdog_reset();
/* Clear WDRF in MCUSR */
MCUSR &= ~(1<<WDRF);
/* Write logical one to WDCE and WDE */
/* Keep old prescaler setting to prevent unintentional time-out */
WDTCSR |= (1<<WDCE) | (1<<WDE);
/* Turn off WDT */
WDTCSR = 0x00;
__enable_interrupt();
}
static inline wdt_reset(void)
{
__watchdog_reset();
}
#endif
/*************************************************************************
* Description: Reset the watchdog timer
* Returns: none
* Notes: none
**************************************************************************/
void watchdog_reset(void)
{
wdt_reset();
}
/*************************************************************************
* Description: Initialize the watchdog timer
* Returns: none
* Notes: none
**************************************************************************/
void watchdog_init(unsigned milliseconds)
{
unsigned value = WDTO_15MS;
if (milliseconds) {
if (milliseconds <= 15) {
value = WDTO_15MS;
} else if (milliseconds <= 30) {
value = WDTO_30MS;
} else if (milliseconds <= 60) {
value = WDTO_60MS;
} else if (milliseconds <= 120) {
value = WDTO_120MS;
} else if (milliseconds <= 500) {
value = WDTO_500MS;
} else if (milliseconds <= 1000) {
value = WDTO_1S;
} else {
value = WDTO_2S;
}
wdt_enable(value);
} else {
wdt_disable();
}
}
@@ -0,0 +1,38 @@
/**************************************************************************
*
* Copyright (C) 2009 Steve Karg <skarg@users.sourceforge.net>
*
* 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