Bugfix/bacnet real endian simplify (#89)

* Remove dependence on endian define

* Make use of existing big_endian function if BACNET_BIG_ENDIAN is not defined

* Add efficient endian macro option if available

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
This commit is contained in:
Steve Karg
2020-05-24 09:36:21 -05:00
committed by GitHub
parent 764e0e8448
commit cbfa74e48d
25 changed files with 354 additions and 257 deletions
-2
View File
@@ -256,7 +256,6 @@
<name>CCDefines</name>
<state>BACDL_MSTP=1</state>
<state>MAX_APDU=50</state>
<state>BIG_ENDIAN=0</state>
<state>MAX_TSM_TRANSACTIONS=0</state>
<state>BACAPP_REAL</state>
<state>BACAPP_UNSIGNED</state>
@@ -1318,7 +1317,6 @@
<state>NDEBUG</state>
<state>BACDL_MSTP</state>
<state>MAX_APDU=50</state>
<state>BIG_ENDIAN=0</state>
<state>MAX_TSM_TRANSACTIONS=0</state>
<state>BACAPP_REAL</state>
<state>BACAPP_UNSIGNED</state>
+24 -25
View File
@@ -1,9 +1,9 @@
This port was done with the Atmel ATmega168 using two tools:
1. The WinAVR compiler avr-gcc (GCC) 4.1.2 (WinAVR 20070525)
and tools from <http://winavr.sourceforge.net/>, hints and
sample code from <http://www.avrfreaks.net/> and
and tools from <http://winavr.sourceforge.net/>, hints and
sample code from <http://www.avrfreaks.net/> and
<http://savannah.gnu.org/projects/avr-libc/>.
"avr-binutils, avr-gcc, and avr-libc form the heart of the
"avr-binutils, avr-gcc, and avr-libc form the heart of the
Free Software toolchain for the Atmel AVR microcontrollers."
2. AVR Studio from Atmel <http://atmel.com/>
@@ -29,16 +29,16 @@ server. dlmstp is the datalink layer for MS/TP over RS-485.
I used the makefile from the command line on Windows:
C:\code\bacnet-stack\ports\atmega168> make clean all
CStack check for GCC is included in the device object as property 512.
CStack check for GCC is included in the device object as property 512.
The compile shows 648 bytes of RAM used, and the ATmega168 has 1024 bytes
of RAM, leaving 376 for the CStack. Property 512 index 0 returns 376 from
a ReadProperty request. My understanding is that the remaining unallocated
RAM is used for the CStack. Keep this in mind when developing.
After some ReadProperty and WriteProperty requests, the CStack shows
159 CStack bytes free, meaning that 216 bytes of CStack are used.
Note that the value 0xC5 (197) was used to paint the CStack.
RAM is used for the CStack. Keep this in mind when developing.
After some ReadProperty and WriteProperty requests, the CStack shows
159 CStack bytes free, meaning that 216 bytes of CStack are used.
Note that the value 0xC5 (197) was used to paint the CStack.
I also used the bacnet.aps project file in AVR Studio to
I also used the bacnet.aps project file in AVR Studio to
make the project and simulate it, but have not kept it updated (FIXME).
Compiler settings for IAR Embedded Workbench (FIXME: makefile?):
@@ -95,14 +95,13 @@ List
Output assembler file (enabled)
Preprocessor
Ignore standard include paths (not enabled)
Include paths:
Include paths:
$PROJ_DIR$
$PROJ_DIR$\..\..\include
Preinclude file: (none)
Defined symbols:
Defined symbols:
BACDL_MSTP
MAX_APDU=50
BIG_ENDIAN=0
MAX_TSM_TRANSACTIONS=0
BACAPP_REAL
BACAPP_UNSIGNED
@@ -110,34 +109,34 @@ Preprocessor
BACAPP_CHARACTER_STRING
BACAPP_OBJECT_ID
WRITE_PROPERTY
Diagnostics
Diagnostics
(not enabled)
MISRA C
(not enabled)
Extra Options
Use command line options (not enabled)
Note: The BACnet Stack at Sourceforge source code has to be built
with lots of different compilers. The IAR compiler has particularly
strong (pedantic) source checking and generates several warnings when
compiling the source code. Unfortunately not all warnings can be
fixed by modifying the source code. Some warnings have therefore been
Note: The BACnet Stack at Sourceforge source code has to be built
with lots of different compilers. The IAR compiler has particularly
strong (pedantic) source checking and generates several warnings when
compiling the source code. Unfortunately not all warnings can be
fixed by modifying the source code. Some warnings have therefore been
disabled in the project file.
Compiler Diagnostics:
(Pe550) I initilize all local variables as a best practice.
Linker Diagnostics:
(w31) The supplied standard libraries expect char parameters to
be unsigned (in functions such as strncpy(), etc.). It may
(w31) The supplied standard libraries expect char parameters to
be unsigned (in functions such as strncpy(), etc.). It may
be possible to recompile the libraries with signed plain char's.
The BACnet Capabilities include WhoIs, I-Am, ReadProperty, and
The BACnet Capabilities include WhoIs, I-Am, ReadProperty, and
WriteProperty support. The BACnet objects include a Device object,
10 Binary Value objects, and 10 Analog Value objects. An LED is
10 Binary Value objects, and 10 Analog Value objects. An LED is
controlled by Binary Value object instance 0. All required object
properties can be retrieved using ReadProperty. The Present_Value
property of the Analog Value and Binary Value objects can be
written using WriteProperty. The Object_Identifier, Object_Name,
Max_Info_Frames, Max_Master, and baud rate (property 9600) of the
property of the Analog Value and Binary Value objects can be
written using WriteProperty. The Object_Identifier, Object_Name,
Max_Info_Frames, Max_Master, and baud rate (property 9600) of the
Device object can be written using WriteProperty.
With full optimization, the statistics on the demo are:
-2
View File
@@ -56,7 +56,6 @@
<ListValues>
<Value>BACDL_MSTP</Value>
<Value>MAX_APDU=128</Value>
<Value>BIG_ENDIAN=0</Value>
<Value>MAX_TSM_TRANSACTIONS=0</Value>
<Value>MSTP_PDU_PACKET_COUNT=2</Value>
<Value>MAX_CHARACTER_STRING_BYTES=64</Value>
@@ -108,7 +107,6 @@
<ListValues>
<Value>BACDL_MSTP</Value>
<Value>MAX_APDU=128</Value>
<Value>BIG_ENDIAN=0</Value>
<Value>MAX_TSM_TRANSACTIONS=0</Value>
<Value>MSTP_PDU_PACKET_COUNT=2</Value>
<Value>MAX_CHARACTER_STRING_BYTES=64</Value>
-2
View File
@@ -257,7 +257,6 @@
<state>BACDL_MSTP</state>
<state>MAX_ANALOG_INPUTS=100</state>
<state>MAX_APDU=50</state>
<state>BIG_ENDIAN=0</state>
<state>MAX_TSM_TRANSACTIONS=0</state>
<state>MSTP_PDU_PACKET_COUNT=2</state>
<state>MAX_CHARACTER_STRING_BYTES=64</state>
@@ -1323,7 +1322,6 @@
<state>NDEBUG</state>
<state>BACDL_MSTP</state>
<state>MAX_APDU=128</state>
<state>BIG_ENDIAN=0</state>
<state>MAX_TSM_TRANSACTIONS=0</state>
<state>MSTP_PDU_PACKET_COUNT=2</state>
<state>MAX_CHARACTER_STRING_BYTES=64</state>
+1 -1
View File
@@ -1,7 +1,7 @@
<!DOCTYPE CrossStudio_Project_File>
<solution Name="bacnet" version="2">
<project Name="bacnet">
<configuration Name="Common" Platform="AVR" Target="ATmega644P" avr_architecture="V2E" avr_debug_interface="JTAG" avr_flash_size="128K" build_use_hardware_multiplier="Yes" c_preprocessor_definitions="BACDL_MSTP;MAX_APDU=128;BIG_ENDIAN=0;MAX_TSM_TRANSACTIONS=0;MAX_CHARACTER_STRING_BYTES=64;MAX_OCTET_STRING_BYTES=64;BACAPP_BOOLEAN;BACAPP_REAL;BACAPP_OBJECT_ID;BACAPP_UNSIGNED;BACAPP_ENUMERATED;BACAPP_CHARACTER_STRING;WRITE_PROPERTY" c_user_include_directories="$(ProjectDir);$(ProjectDir)/crossworks;$(ProjectDir)/../../include;$(ProjectDir)/../../src" linker_call_stack_size="1024" linker_memory_map_file="$(PackagesDir)/targets/avr/ATmega644P.xml" project_directory="" project_type="Executable"/>
<configuration Name="Common" Platform="AVR" Target="ATmega644P" avr_architecture="V2E" avr_debug_interface="JTAG" avr_flash_size="128K" build_use_hardware_multiplier="Yes" c_preprocessor_definitions="BACDL_MSTP;MAX_APDU=128;MAX_TSM_TRANSACTIONS=0;MAX_CHARACTER_STRING_BYTES=64;MAX_OCTET_STRING_BYTES=64;BACAPP_BOOLEAN;BACAPP_REAL;BACAPP_OBJECT_ID;BACAPP_UNSIGNED;BACAPP_ENUMERATED;BACAPP_CHARACTER_STRING;WRITE_PROPERTY" c_user_include_directories="$(ProjectDir);$(ProjectDir)/crossworks;$(ProjectDir)/../../include;$(ProjectDir)/../../src" linker_call_stack_size="1024" linker_memory_map_file="$(PackagesDir)/targets/avr/ATmega644P.xml" project_directory="" project_type="Executable"/>
<folder Name="Source Files">
<configuration Name="Common" filter="c;h;s;asm;inc;s90"/>
<file file_name="adc.c">
+42
View File
@@ -0,0 +1,42 @@
<!DOCTYPE CrossStudio_Session_File>
<session>
<Bookmarks/>
<Breakpoints groups="Breakpoints" active_group="Breakpoints"/>
<ExecutionProfileWindow/>
<FrameBufferWindow>
<FrameBufferWindow bufferHeight="-1" addressSpace="" addressText="" bufferWidth="-1"/>
</FrameBufferWindow>
<Memory1/>
<Memory2/>
<Memory3/>
<Memory4/>
<Project>
<ProjectSessionItem path="bacnet"/>
<ProjectSessionItem path="bacnet;bacnet"/>
</Project>
<Register1/>
<Register2/>
<Register3/>
<Register4/>
<TargetWindow programLoadAddress="" programSize="" uploadStartAddress="" programMemoryInterface="" programFileName="" uploadMemoryInterface="" programFileType="" uploadFileName="" uploadFileType="" programAction="" uploadSize=""/>
<Threads>
<ThreadsWindow showLists=""/>
</Threads>
<TraceWindow>
<Trace enabled="Yes"/>
</TraceWindow>
<Watch1>
<Watches active="1" update="Never"/>
</Watch1>
<Watch2>
<Watches active="0" update="Never"/>
</Watch2>
<Watch3>
<Watches active="0" update="Never"/>
</Watch3>
<Watch4>
<Watches active="0" update="Never"/>
</Watch4>
<Files/>
<ARMCrossStudioWindow activeProject="bacnet" fileDialogDefaultFilter="*.c" autoConnectTarget="" buildConfiguration="Common" sessionSettings="" debugSearchFileMap="" fileDialogInitialDirectory="" debugSearchPath="" autoConnectCapabilities="0"/>
</session>
@@ -135,7 +135,7 @@
value="..\;..\..\..\include;..\..\..\demo\object"/>
<property key="optimization-master" value="Enable all"/>
<property key="preprocessor-macros"
value="PRINT_ENABLED=0;BACDL_MSTP=1;BIG_ENDIAN=0;MAX_APDU=50;MAX_TSM_TRANSACTIONS=0;BACAPP_MINIMAL"/>
value="PRINT_ENABLED=0;BACDL_MSTP=1;MAX_APDU=50;MAX_TSM_TRANSACTIONS=0;BACAPP_MINIMAL"/>
<property key="procedural-abstraction-passes" value="0"/>
<property key="storage-class" value="sca"/>
<property key="verbose" value="false"/>
+1 -1
View File
@@ -269,7 +269,7 @@ suite_state=
[TOOL_SETTINGS]
TS{DD2213A8-6310-47B1-8376-9430CDFC013F}=
TS{BFD27FBA-4A02-4C0E-A5E5-B812F3E7707C}=/m"$(BINDIR_)$(TARGETBASE).map" /o"$(TARGETBASE).cof"
TS{C2AF05E7-1416-4625-923D-E114DB6E2B96}=-DPRINT_ENABLED=0 -DBACDL_MSTP=1 -DBIG_ENDIAN=0 -DMAX_APDU=50 -DMAX_TSM_TRANSACTIONS=0 -mL -Ls -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-
TS{C2AF05E7-1416-4625-923D-E114DB6E2B96}=-DPRINT_ENABLED=0 -DBACDL_MSTP=1 -DMAX_APDU=50 -DMAX_TSM_TRANSACTIONS=0 -mL -Ls -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-
TS{ADE93A55-C7C7-4D4D-A4BA-59305F7D0391}=
[INSTRUMENTED_TRACE]
enable=0
+2 -3
View File
@@ -1,12 +1,12 @@
BACnet Stack - SourceForge.net
Build for MPLAB IDE
These are some settings that are important when building
These are some settings that are important when building
the BACnet Stack using MPLAB IDE and MCC18 Compiler,
1. Add the files to the project that you need:
abort.c, apdu.c, bacapp.c, bacdcode.c, bacerror.c,
bacstr.c, crc.c, datetime.c, dcc.c, iam.c,
bacstr.c, crc.c, datetime.c, dcc.c, iam.c,
npdu.c, rd.c, reject.c, rp.c, whois.c, wp.c
From ports/picxx: isr.c, main.c, rs485.c, mstp.c, dlmstp.c
@@ -31,7 +31,6 @@ MPLAB C18 Tab: General: Macro Definitions:
PRINT_ENABLED=0
BACDL_MSTP=1
TSM_ENABLED=0
BIG_ENDIAN=0
3. The linker script must reserve some extra stack space.
@@ -135,7 +135,7 @@
value="..\;..\..\..\include;..\..\..\demo\object"/>
<property key="optimization-master" value="Enable all"/>
<property key="preprocessor-macros"
value="PRINT_ENABLED=0;BACDL_MSTP=1;BIG_ENDIAN=0;MAX_APDU=50;MAX_TSM_TRANSACTIONS=0;BACAPP_MINIMAL"/>
value="PRINT_ENABLED=0;BACDL_MSTP=1;MAX_APDU=50;MAX_TSM_TRANSACTIONS=0;BACAPP_MINIMAL"/>
<property key="procedural-abstraction-passes" value="0"/>
<property key="storage-class" value="sca"/>
<property key="verbose" value="false"/>
+2 -3
View File
@@ -1,12 +1,12 @@
BACnet Stack - SourceForge.net
Build for MPLAB IDE
These are some settings that are important when building
These are some settings that are important when building
the BACnet Stack using MPLAB IDE and MCC18 Compiler,
1. Add the files to the project that you need:
abort.c, apdu.c, bacapp.c, bacdcode.c, bacerror.c,
bacstr.c, crc.c, datetime.c, dcc.c, iam.c,
bacstr.c, crc.c, datetime.c, dcc.c, iam.c,
npdu.c, rd.c, reject.c, rp.c, whois.c, wp.c
From ports/picxx: isr.c, main.c, rs485.c, mstp.c, dlmstp.c
@@ -31,7 +31,6 @@ MPLAB C18 Tab: General: Macro Definitions:
PRINT_ENABLED=0
BACDL_MSTP=1
TSM_ENABLED=0
BIG_ENDIAN=0
3. The linker script must reserve some extra stack space.
-1
View File
@@ -228,7 +228,6 @@
<state>USE_STDPERIPH_DRIVER</state>
<state>BACDL_MSTP</state>
<state>MAX_APDU=480</state>
<state>BIG_ENDIAN=0</state>
<state>MAX_TSM_TRANSACTIONS=0</state>
<state>BACAPP_BOOLEAN</state>
<state>BACAPP_REAL</state>