From 4b422d6c1c5efe090c1c768f11151b657ac07adc Mon Sep 17 00:00:00 2001 From: skarg Date: Thu, 20 Aug 2009 14:38:25 +0000 Subject: [PATCH] Changed modulo and division operations on 256 to bit shift using include/bytes.h macro to improve code size on architectures that don't do division natively. --- bacnet-stack/ports/at91sam7s/dlmstp.c | 5 +++-- bacnet-stack/ports/atmega168/dlmstp.c | 6 ++++-- bacnet-stack/ports/atmega8/dlmstp.c | 5 +++-- bacnet-stack/ports/bdk-atxx4-mstp/dlmstp.c | 5 +++-- bacnet-stack/ports/dos/dlmstp.c | 5 +++-- bacnet-stack/ports/pic18f6720/mstp.c | 4 ++-- bacnet-stack/ports/rtos32/mstp.c | 4 ++-- 7 files changed, 20 insertions(+), 14 deletions(-) diff --git a/bacnet-stack/ports/at91sam7s/dlmstp.c b/bacnet-stack/ports/at91sam7s/dlmstp.c index 19d6d67e..07cf54f8 100644 --- a/bacnet-stack/ports/at91sam7s/dlmstp.c +++ b/bacnet-stack/ports/at91sam7s/dlmstp.c @@ -42,6 +42,7 @@ #include "crc.h" #include "npdu.h" #include "bits.h" +#include "bytes.h" #include "bacaddr.h" /* This file has been customized for use with small microprocessors */ @@ -419,9 +420,9 @@ static void MSTP_Send_Frame( crc8 = CRC_Calc_Header(buffer[3], crc8); buffer[4] = source; crc8 = CRC_Calc_Header(buffer[4], crc8); - buffer[5] = data_len / 256; + buffer[5] = HI_BYTE(data_len); crc8 = CRC_Calc_Header(buffer[5], crc8); - buffer[6] = data_len % 256; + buffer[6] = LO_BYTE(data_len); crc8 = CRC_Calc_Header(buffer[6], crc8); buffer[7] = ~crc8; RS485_Turnaround_Delay(); diff --git a/bacnet-stack/ports/atmega168/dlmstp.c b/bacnet-stack/ports/atmega168/dlmstp.c index a2bd701c..597dc18a 100644 --- a/bacnet-stack/ports/atmega168/dlmstp.c +++ b/bacnet-stack/ports/atmega168/dlmstp.c @@ -42,6 +42,7 @@ #include "crc.h" #include "npdu.h" #include "bits.h" +#include "bytes.h" #include "bacaddr.h" /* special optimization - I-Am response in this module */ #include "client.h" @@ -331,9 +332,10 @@ static void MSTP_Send_Frame( crc8 = CRC_Calc_Header(buffer[3], crc8); buffer[4] = source; crc8 = CRC_Calc_Header(buffer[4], crc8); - buffer[5] = pdu_len / 256; + + buffer[5] = HI_BYTE(pdu_len); crc8 = CRC_Calc_Header(buffer[5], crc8); - buffer[6] = pdu_len % 256; + buffer[6] = LO_BYTE(pdu_len); crc8 = CRC_Calc_Header(buffer[6], crc8); buffer[7] = ~crc8; if (pdu_len) { diff --git a/bacnet-stack/ports/atmega8/dlmstp.c b/bacnet-stack/ports/atmega8/dlmstp.c index c2ed11b9..a9698b16 100644 --- a/bacnet-stack/ports/atmega8/dlmstp.c +++ b/bacnet-stack/ports/atmega8/dlmstp.c @@ -42,6 +42,7 @@ #include "crc.h" #include "npdu.h" #include "bits.h" +#include "bytes.h" #include "bacaddr.h" #include "txbuf.h" @@ -256,9 +257,9 @@ static void MSTP_Send_Frame( crc8 = CRC_Calc_Header(buffer[3], crc8); buffer[4] = source; crc8 = CRC_Calc_Header(buffer[4], crc8); - buffer[5] = pdu_len / 256; + buffer[5] = HI_BYTE(pdu_len); crc8 = CRC_Calc_Header(buffer[5], crc8); - buffer[6] = pdu_len % 256; + buffer[6] = LO_BYTE(pdu_len); crc8 = CRC_Calc_Header(buffer[6], crc8); buffer[7] = ~crc8; if (pdu_len) { diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/dlmstp.c b/bacnet-stack/ports/bdk-atxx4-mstp/dlmstp.c index 38d65d98..7608d94a 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/dlmstp.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/dlmstp.c @@ -42,6 +42,7 @@ #include "crc.h" #include "npdu.h" #include "bits.h" +#include "bytes.h" #include "bacaddr.h" #include "timer.h" @@ -416,9 +417,9 @@ static void MSTP_Send_Frame( crc8 = CRC_Calc_Header(buffer[3], crc8); buffer[4] = source; crc8 = CRC_Calc_Header(buffer[4], crc8); - buffer[5] = data_len / 256; + buffer[5] = HI_BYTE(data_len); crc8 = CRC_Calc_Header(buffer[5], crc8); - buffer[6] = data_len % 256; + buffer[6] = LO_BYTE(data_len); crc8 = CRC_Calc_Header(buffer[6], crc8); buffer[7] = ~crc8; rs485_turnaround_delay(); diff --git a/bacnet-stack/ports/dos/dlmstp.c b/bacnet-stack/ports/dos/dlmstp.c index 6ac18985..513a7e20 100644 --- a/bacnet-stack/ports/dos/dlmstp.c +++ b/bacnet-stack/ports/dos/dlmstp.c @@ -42,6 +42,7 @@ #include "crc.h" #include "npdu.h" #include "bits.h" +#include "bytes.h" #include "bacaddr.h" /* This file has been customized for use with small microprocessors */ @@ -418,9 +419,9 @@ static void MSTP_Send_Frame( crc8 = CRC_Calc_Header(buffer[3], crc8); buffer[4] = source; crc8 = CRC_Calc_Header(buffer[4], crc8); - buffer[5] = data_len / 256; + buffer[5] = HI_BYTE(data_len); crc8 = CRC_Calc_Header(buffer[5], crc8); - buffer[6] = data_len % 256; + buffer[6] = LO_BYTE(data_len); crc8 = CRC_Calc_Header(buffer[6], crc8); buffer[7] = ~crc8; RS485_Turnaround_Delay(); diff --git a/bacnet-stack/ports/pic18f6720/mstp.c b/bacnet-stack/ports/pic18f6720/mstp.c index 3d82acb1..e958a926 100644 --- a/bacnet-stack/ports/pic18f6720/mstp.c +++ b/bacnet-stack/ports/pic18f6720/mstp.c @@ -181,9 +181,9 @@ unsigned MSTP_Create_Frame( crc8 = CRC_Calc_Header(buffer[3], crc8); buffer[4] = source; crc8 = CRC_Calc_Header(buffer[4], crc8); - buffer[5] = data_len / 256; + buffer[5] = HI_BYTE(data_len); crc8 = CRC_Calc_Header(buffer[5], crc8); - buffer[6] = data_len % 256; + buffer[6] = LO_BYTE(data_len); crc8 = CRC_Calc_Header(buffer[6], crc8); buffer[7] = ~crc8; diff --git a/bacnet-stack/ports/rtos32/mstp.c b/bacnet-stack/ports/rtos32/mstp.c index 1a564e04..e70e3c47 100644 --- a/bacnet-stack/ports/rtos32/mstp.c +++ b/bacnet-stack/ports/rtos32/mstp.c @@ -178,9 +178,9 @@ unsigned MSTP_Create_Frame( crc8 = CRC_Calc_Header(buffer[3], crc8); buffer[4] = source; crc8 = CRC_Calc_Header(buffer[4], crc8); - buffer[5] = data_len / 256; + buffer[5] = HI_BYTE(data_len); crc8 = CRC_Calc_Header(buffer[5], crc8); - buffer[6] = data_len % 256; + buffer[6] = LO_BYTE(data_len); crc8 = CRC_Calc_Header(buffer[6], crc8); buffer[7] = ~crc8;