From a8e679f8d7418c2c7837402d18e83618500a8dbb Mon Sep 17 00:00:00 2001 From: skarg Date: Mon, 7 Jan 2008 21:41:15 +0000 Subject: [PATCH] Compiled ATmega16 port example project with IAR Embedded workbench. --- bacnet-stack/ports/atmega168/bacnet.ewp | 2037 +++++++++++++++++++++++ bacnet-stack/ports/atmega168/bacnet.eww | 10 + bacnet-stack/ports/atmega168/device.c | 2 +- bacnet-stack/ports/atmega168/hardware.h | 21 +- bacnet-stack/ports/atmega168/iar2gcc.h | 196 +++ bacnet-stack/ports/atmega168/main.c | 7 +- bacnet-stack/ports/atmega168/readme.txt | 76 +- bacnet-stack/ports/atmega168/stdbool.h | 28 + bacnet-stack/ports/atmega168/stdint.h | 15 + bacnet-stack/ports/atmega168/timer.c | 13 +- 10 files changed, 2381 insertions(+), 24 deletions(-) create mode 100644 bacnet-stack/ports/atmega168/bacnet.ewp create mode 100644 bacnet-stack/ports/atmega168/bacnet.eww create mode 100644 bacnet-stack/ports/atmega168/iar2gcc.h create mode 100644 bacnet-stack/ports/atmega168/stdbool.h create mode 100644 bacnet-stack/ports/atmega168/stdint.h diff --git a/bacnet-stack/ports/atmega168/bacnet.ewp b/bacnet-stack/ports/atmega168/bacnet.ewp new file mode 100644 index 00000000..c569fa46 --- /dev/null +++ b/bacnet-stack/ports/atmega168/bacnet.ewp @@ -0,0 +1,2037 @@ + + + + 1 + + Debug + + AVR + + 1 + + General + 3 + + 6 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ICCAVR + 3 + + 12 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + AAVR + 3 + + 9 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + CUSTOM + 3 + + + + + + + BICOMP + 0 + + + + BUILDACTION + 1 + + + + + + + XLINK + 2 + + 13 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + XAR + 2 + + 0 + 1 + 1 + + + + + + + BILINK + 0 + + + + + Release + + AVR + + 0 + + General + 3 + + 6 + 1 + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ICCAVR + 3 + + 12 + 1 + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + AAVR + 3 + + 9 + 1 + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + CUSTOM + 3 + + + + + + + BICOMP + 0 + + + + BUILDACTION + 1 + + + + + + + XLINK + 2 + + 13 + 1 + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + XAR + 2 + + 0 + 1 + 0 + + + + + + + BILINK + 0 + + + + + $PROJ_DIR$\..\..\src\abort.c + + + $PROJ_DIR$\apdu.c + + + $PROJ_DIR$\av.c + + + $PROJ_DIR$\avr035.h + + + $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$\device.c + + + $PROJ_DIR$\dlmstp.c + + + $PROJ_DIR$\h_rp.c + + + $PROJ_DIR$\h_whois.c + + + $PROJ_DIR$\hardware.h + + + $PROJ_DIR$\..\..\src\iam.c + + + $PROJ_DIR$\iar2gcc.h + + + $PROJ_DIR$\main.c + + + $PROJ_DIR$\..\..\demo\handler\noserv.c + + + $PROJ_DIR$\..\..\src\npdu.c + + + $PROJ_DIR$\..\..\src\reject.c + + + $PROJ_DIR$\..\..\src\rp.c + + + $PROJ_DIR$\rs485.c + + + $PROJ_DIR$\rs485.h + + + $PROJ_DIR$\timer.c + + + $PROJ_DIR$\timer.h + + + $PROJ_DIR$\..\..\demo\handler\txbuf.c + + + $PROJ_DIR$\..\..\src\version.c + + + $PROJ_DIR$\..\..\src\whois.c + + + + diff --git a/bacnet-stack/ports/atmega168/bacnet.eww b/bacnet-stack/ports/atmega168/bacnet.eww new file mode 100644 index 00000000..7a4cd894 --- /dev/null +++ b/bacnet-stack/ports/atmega168/bacnet.eww @@ -0,0 +1,10 @@ + + + + + $WS_DIR$\bacnet.ewp + + + + + diff --git a/bacnet-stack/ports/atmega168/device.c b/bacnet-stack/ports/atmega168/device.c index 07d18d66..a112e5ba 100644 --- a/bacnet-stack/ports/atmega168/device.c +++ b/bacnet-stack/ports/atmega168/device.c @@ -270,7 +270,7 @@ int Device_Encode_Property_APDU( 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; diff --git a/bacnet-stack/ports/atmega168/hardware.h b/bacnet-stack/ports/atmega168/hardware.h index dbbef325..b5cfc2db 100644 --- a/bacnet-stack/ports/atmega168/hardware.h +++ b/bacnet-stack/ports/atmega168/hardware.h @@ -25,16 +25,19 @@ #ifndef HARDWARE_H #define HARDWARE_H -/* The processor clock frequency */ -#define F_CPU (7372800) +#if !defined(F_CPU) + /* The processor clock frequency */ + #define F_CPU (7372800) +#endif -#include -#include -#include +#if defined(__IAR_SYSTEMS_ICC__) || defined(__IAR_SYSTEMS_ASM__) + #include +#else + #if !defined(__AVR_ATmega168__) + #error Firmware is configured for ATmega168 only (-mmcu=atmega168) + #endif +#endif +#include "iar2gcc.h" #include "avr035.h" -#if !defined(__AVR_ATmega168__) -#error Firmware is configured for ATmega168 only. -#endif - #endif diff --git a/bacnet-stack/ports/atmega168/iar2gcc.h b/bacnet-stack/ports/atmega168/iar2gcc.h new file mode 100644 index 00000000..40521e42 --- /dev/null +++ b/bacnet-stack/ports/atmega168/iar2gcc.h @@ -0,0 +1,196 @@ +/*####COPYRIGHTBEGIN#### + ------------------------------------------- + Copyright (C) 2007 Steve Karg + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to: + The Free Software Foundation, Inc. + 59 Temple Place - Suite 330 + Boston, MA 02111-1307, USA. + + As a special exception, if other files instantiate templates or + use macros or inline functions from this file, or you compile + this file and link it with other works to produce a work based + on this file, this file does not by itself cause the resulting + work to be covered by the GNU General Public License. However + the source code for this file must still be made available in + accordance with section (3) of the GNU General Public License. + + This exception does not invalidate any other reasons why a work + based on this file might be covered by the GNU General Public + License. + ------------------------------------------- +####COPYRIGHTEND####*/ +#ifndef IAR2GCC_H +#define IAR2GCC_H + +#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(uint8_t microseconds) +{ + do { + __delay_cycles(F_CPU/1000000); + } while (microseconds--); +} + +#else + #if !defined(F_CPU) + #define F_CPU (7372800) + #endif + #include + #include + #include + + typedef struct + { + unsigned char bit0:1; + unsigned char bit1:1; + unsigned char bit2:1; + unsigned char bit3:1; + unsigned char bit4:1; + unsigned char bit5:1; + unsigned char bit6:1; + unsigned char bit7:1; + } BitRegisterType; + + #ifndef true + #define true 1 + #endif + + #ifndef false + #define false 0 + #endif + + #define GPIO_BITREG(port,bitnum) \ + ((volatile BitRegisterType*)_SFR_MEM_ADDR(port) \ + )->bit ## bitnum + + #define PINA_Bit0 GPIO_BITREG(PINA,0) + #define PINA_Bit1 GPIO_BITREG(PINA,1) + #define PINA_Bit2 GPIO_BITREG(PINA,2) + #define PINA_Bit3 GPIO_BITREG(PINA,3) + #define PINA_Bit4 GPIO_BITREG(PINA,4) + #define PINA_Bit5 GPIO_BITREG(PINA,5) + #define PINA_Bit6 GPIO_BITREG(PINA,6) + #define PINA_Bit7 GPIO_BITREG(PINA,7) + + #define PORTA_Bit0 GPIO_BITREG(PORTA,0) + #define PORTA_Bit1 GPIO_BITREG(PORTA,1) + #define PORTA_Bit2 GPIO_BITREG(PORTA,2) + #define PORTA_Bit3 GPIO_BITREG(PORTA,3) + #define PORTA_Bit4 GPIO_BITREG(PORTA,4) + #define PORTA_Bit5 GPIO_BITREG(PORTA,5) + #define PORTA_Bit6 GPIO_BITREG(PORTA,6) + #define PORTA_Bit7 GPIO_BITREG(PORTA,7) + + #define PINB_Bit0 GPIO_BITREG(PINB,0) + #define PINB_Bit1 GPIO_BITREG(PINB,1) + #define PINB_Bit2 GPIO_BITREG(PINB,2) + #define PINB_Bit3 GPIO_BITREG(PINB,3) + #define PINB_Bit4 GPIO_BITREG(PINB,4) + #define PINB_Bit5 GPIO_BITREG(PINB,5) + #define PINB_Bit6 GPIO_BITREG(PINB,6) + #define PINB_Bit7 GPIO_BITREG(PINB,7) + + #define PORTB_Bit0 GPIO_BITREG(PORTB,0) + #define PORTB_Bit1 GPIO_BITREG(PORTB,1) + #define PORTB_Bit2 GPIO_BITREG(PORTB,2) + #define PORTB_Bit3 GPIO_BITREG(PORTB,3) + #define PORTB_Bit4 GPIO_BITREG(PORTB,4) + #define PORTB_Bit5 GPIO_BITREG(PORTB,5) + #define PORTB_Bit6 GPIO_BITREG(PORTB,6) + #define PORTB_Bit7 GPIO_BITREG(PORTB,7) + + #define PINC_Bit0 GPIO_BITREG(PINC,0) + #define PINC_Bit1 GPIO_BITREG(PINC,1) + #define PINC_Bit2 GPIO_BITREG(PINC,2) + #define PINC_Bit3 GPIO_BITREG(PINC,3) + #define PINC_Bit4 GPIO_BITREG(PINC,4) + #define PINC_Bit5 GPIO_BITREG(PINC,5) + #define PINC_Bit6 GPIO_BITREG(PINC,6) + #define PINC_Bit7 GPIO_BITREG(PINC,7) + + #define PORTC_Bit0 GPIO_BITREG(PORTC,0) + #define PORTC_Bit1 GPIO_BITREG(PORTC,1) + #define PORTC_Bit2 GPIO_BITREG(PORTC,2) + #define PORTC_Bit3 GPIO_BITREG(PORTC,3) + #define PORTC_Bit4 GPIO_BITREG(PORTC,4) + #define PORTC_Bit5 GPIO_BITREG(PORTC,5) + #define PORTC_Bit6 GPIO_BITREG(PORTC,6) + #define PORTC_Bit7 GPIO_BITREG(PORTC,7) + + #define PIND_Bit0 GPIO_BITREG(PIND,0) + #define PIND_Bit1 GPIO_BITREG(PIND,1) + #define PIND_Bit2 GPIO_BITREG(PIND,2) + #define PIND_Bit3 GPIO_BITREG(PIND,3) + #define PIND_Bit4 GPIO_BITREG(PIND,4) + #define PIND_Bit5 GPIO_BITREG(PIND,5) + #define PIND_Bit6 GPIO_BITREG(PIND,6) + #define PIND_Bit7 GPIO_BITREG(PIND,7) + + #define PORTD_Bit0 GPIO_BITREG(PORTD,0) + #define PORTD_Bit1 GPIO_BITREG(PORTD,1) + #define PORTD_Bit2 GPIO_BITREG(PORTD,2) + #define PORTD_Bit3 GPIO_BITREG(PORTD,3) + #define PORTD_Bit4 GPIO_BITREG(PORTD,4) + #define PORTD_Bit5 GPIO_BITREG(PORTD,5) + #define PORTD_Bit6 GPIO_BITREG(PORTD,6) + #define PORTD_Bit7 GPIO_BITREG(PORTD,7) + + #define GPIOR0_Bit0 GPIO_BITREG(GPIOR0,0) + #define GPIOR0_Bit1 GPIO_BITREG(GPIOR0,1) + #define GPIOR0_Bit2 GPIO_BITREG(GPIOR0,2) + #define GPIOR0_Bit3 GPIO_BITREG(GPIOR0,3) + #define GPIOR0_Bit4 GPIO_BITREG(GPIOR0,4) + #define GPIOR0_Bit5 GPIO_BITREG(GPIOR0,5) + #define GPIOR0_Bit6 GPIO_BITREG(GPIOR0,6) + #define GPIOR0_Bit7 GPIO_BITREG(GPIOR0,7) + + #define GPIOR1_Bit0 GPIO_BITREG(GPIOR1,0) + #define GPIOR1_Bit1 GPIO_BITREG(GPIOR1,1) + #define GPIOR1_Bit2 GPIO_BITREG(GPIOR1,2) + #define GPIOR1_Bit3 GPIO_BITREG(GPIOR1,3) + #define GPIOR1_Bit4 GPIO_BITREG(GPIOR1,4) + #define GPIOR1_Bit5 GPIO_BITREG(GPIOR1,5) + #define GPIOR1_Bit6 GPIO_BITREG(GPIOR1,6) + #define GPIOR1_Bit7 GPIO_BITREG(GPIOR1,7) + + #define GPIOR2_Bit0 GPIO_BITREG(GPIOR2,0) + #define GPIOR2_Bit1 GPIO_BITREG(GPIOR2,1) + #define GPIOR2_Bit2 GPIO_BITREG(GPIOR2,2) + #define GPIOR2_Bit3 GPIO_BITREG(GPIOR2,3) + #define GPIOR2_Bit4 GPIO_BITREG(GPIOR2,4) + #define GPIOR2_Bit5 GPIO_BITREG(GPIOR2,5) + #define GPIOR2_Bit6 GPIO_BITREG(GPIOR2,6) + #define GPIOR2_Bit7 GPIO_BITREG(GPIOR2,7) + + /* FIXME: intrinsic routines: map to assembler for size/speed */ + #define __multiply_unsigned(x,y) ((x)*(y)) + + + /* memory location */ + #define __eeprom __attribute__((section (".eeprom"))) + #define __flash __attribute__((progmem)) + /* __root means to not optimize or strip */ + #define __root + #define __enable_interrupt() sei() + #define __disable_interrupt() cli() + +#endif + +#endif diff --git a/bacnet-stack/ports/atmega168/main.c b/bacnet-stack/ports/atmega168/main.c index 02dafdfe..e18a0522 100644 --- a/bacnet-stack/ports/atmega168/main.c +++ b/bacnet-stack/ports/atmega168/main.c @@ -95,7 +95,7 @@ static inline void init( BIT_SET(DDRD, DDD5); /* Enable global interrupts */ - sei(); + __enable_interrupt(); } static uint8_t NPDU_Timer; @@ -137,7 +137,8 @@ static inline void input_switch_read( uint8_t value; static uint8_t old_value = 0; - value = BITMASK_CHECK(PINC, 0x0F) | (BITMASK_CHECK(PINB, 0x07) << 4); + value = BITMASK_CHECK(PINC, 0x0F); + value |= (BITMASK_CHECK(PINB, 0x07) << 4); if (value != old_value) { old_value = value; } else { @@ -176,6 +177,4 @@ int main( NPDU_LED_On(); } } - - return 0; } diff --git a/bacnet-stack/ports/atmega168/readme.txt b/bacnet-stack/ports/atmega168/readme.txt index be55b569..3a51708b 100644 --- a/bacnet-stack/ports/atmega168/readme.txt +++ b/bacnet-stack/ports/atmega168/readme.txt @@ -30,12 +30,76 @@ C:\code\bacnet-stack\ports\atmega168> make clean all I also used the bacnet.aps project file in AVR Studio to make the project and simulate it. -Note that the bacnet stack is currently layed out as encapsulating -modules that include both client and server functionality for each service. -The nice thing about the all in one modules that it permits easy unit -testing. The bad thing is that it puts all the unused code into the build. -Therefore, until the code is split into separate modules, -the unused sections must be commented out (use #if 0, #endif). +Compiler settings for IAR Embedded Workbench (FIXME: makefile?): +General Options +--------------- +Target + Processor configuration: --cpu=m168. ATmega168 + Memory Model: Small + System configuration: Configure system using dialogs (not in .XCL file) +Output + Executable + Output Directories: Debug\Exe, Debug\Obj, Debug\List +Library Configuration + Library: CLIB +Library Options + Printf formatter: Small + Scanf formatter: Medium +Heap Configuration + CLIB heap size: 0x10 +System + CSTACK: 0x20 (0x60?) + RSTACK: 16 (32?) + Initialize unused interrupt vectors with RETI instructions (enabled) + Enable bit defnitions in I/O-Include files. (enabled) +MISRA C + not enabled + +C/C++ Compiler +-------------- +Language + Language: C + Require prototypes (not enabled) + Allow IAR extensions + Plain 'char' is Signed + Enable multibyte support (not enabled) +Code + Memory utilization: + Place aggregate initializers in flash memory (enabled) + Force generation of all global and static variables (not enabled) + Register utilization: + Number of registers to lock for global variables: 0 + Use ICCA90 1.x calling convention (not enabled) +Optimizations + Size: High (Maximum optimization) + Number of cross-call passes: Unlimited + Always do cross call optimization (not enabled) +Output + Module type: Override default (not enabled) + Object module name (not enabled) + Generate debug information (enabled) + No error messages in output files (not enabled) +List + Output list file (not enabled) + Output assembler file (enabled) +Preprocessor + Ignore standard include paths (not enabled) + Include paths: + $PROJ_DIR$ + $PROJ_DIR$\..\..\include + Preinclude file: (none) + Defined symbols: + BACDL_MSTP + MAX_APDU=128 + BIG_ENDIAN=0 + MAX_TSM_TRANSACTIONS=0 + BACAPP_REAL +Diagnostics + (not enabled) +MISRA C + (not enabled) +Extra Options + Use command line options (not enabled) Hopefully you find it useful! diff --git a/bacnet-stack/ports/atmega168/stdbool.h b/bacnet-stack/ports/atmega168/stdbool.h new file mode 100644 index 00000000..39c1c286 --- /dev/null +++ b/bacnet-stack/ports/atmega168/stdbool.h @@ -0,0 +1,28 @@ +#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 + +#ifndef FALSE +#define FALSE 0 +#endif + +#ifndef TRUE +#define TRUE 1 +#endif + +#endif diff --git a/bacnet-stack/ports/atmega168/stdint.h b/bacnet-stack/ports/atmega168/stdint.h new file mode 100644 index 00000000..874f309d --- /dev/null +++ b/bacnet-stack/ports/atmega168/stdint.h @@ -0,0 +1,15 @@ +/* Defines the standard integer types that are used in code */ + +#ifndef STDINT_H +#define STDINT_H 1 + +#include + +typedef unsigned char uint8_t; /* 1 byte 0 to 255 */ +typedef signed char int8_t; /* 1 byte -127 to 127 */ +typedef unsigned short uint16_t; /* 2 bytes 0 to 65535 */ +typedef signed short int16_t; /* 2 bytes -32767 to 32767 */ +typedef unsigned long uint32_t; /* 4 bytes 0 to 4294967295 */ +typedef signed long int32_t; /* 4 bytes -2147483647 to 2147483647 */ + +#endif /* STDINT_H */ diff --git a/bacnet-stack/ports/atmega168/timer.c b/bacnet-stack/ports/atmega168/timer.c index eec1b6be..3745a756 100644 --- a/bacnet-stack/ports/atmega168/timer.c +++ b/bacnet-stack/ports/atmega168/timer.c @@ -22,7 +22,7 @@ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * *********************************************************************/ - +#include #include "hardware.h" /* This module is a 1 millisecond timer */ @@ -46,7 +46,7 @@ void Timer_Initialize( { /* Normal Operation */ TCCR1A = 0; - /* CSn2 CSn1 CSn0 Description + /* CSn2 CSn1 CSn0 Description ---- ---- ---- ----------- 0 0 0 No Clock Source 0 0 1 No prescaling @@ -71,7 +71,12 @@ void Timer_Initialize( /* Timer interupt */ /* note: Global interupts must be enabled - sei() */ /* Timer Overflowed! Increment the time. */ +#if defined(__IAR_SYSTEMS_ICC__) || defined(__IAR_SYSTEMS_ASM__) +#pragma vector=TIMER0_OVF_vect +__interrupt void myTIMER0_OVF_vect() +#else ISR(TIMER0_OVF_vect) +#endif { /* Set the counter for the next interrupt */ TCNT0 = TIMER_COUNT; @@ -91,7 +96,7 @@ uint16_t Timer_Silence( uint8_t sreg; sreg = SREG; - cli(); + __disable_interrupt(); timer = SilenceTime; SREG = sreg; @@ -105,7 +110,7 @@ void Timer_Silence_Reset( uint8_t sreg; sreg = SREG; - cli(); + __disable_interrupt(); SilenceTime = 0; SREG = sreg; }