Refactor/ports xplained common dlmstp (#665)

* Refactored ports/xplained to use common DLMSTP module to enable extended frames

* Added floating point compares in cases where they don't exist in math library
This commit is contained in:
Steve Karg
2024-06-04 14:48:40 -05:00
committed by GitHub
parent 17c5e2e98d
commit 4576e41ec3
23 changed files with 247 additions and 1994 deletions
+6 -2
View File
@@ -45,7 +45,6 @@ CSRC = main.c \
bacnet.c \
bname.c \
device.c \
dlmstp.c \
led.c \
mstimer-init.c \
netport.c \
@@ -79,7 +78,6 @@ BASICSRC = $(BACNET_BASIC)/tsm/tsm.c \
# core BACnet stack files
CORESRC = \
$(BACNET_CORE)/datalink/crc.c \
$(BACNET_CORE)/abort.c \
$(BACNET_CORE)/bacaddr.c \
$(BACNET_CORE)/bacapp.c \
@@ -90,9 +88,15 @@ CORESRC = \
$(BACNET_CORE)/bacreal.c \
$(BACNET_CORE)/bacstr.c \
$(BACNET_CORE)/datetime.c \
$(BACNET_CORE)/datalink/cobs.c \
$(BACNET_CORE)/datalink/crc.c \
$(BACNET_CORE)/datalink/dlmstp.c \
$(BACNET_CORE)/datalink/mstp.c \
$(BACNET_CORE)/datalink/mstptext.c \
$(BACNET_CORE)/dcc.c \
$(BACNET_CORE)/iam.c \
$(BACNET_CORE)/ihave.c \
$(BACNET_CORE)/indtext.c \
$(BACNET_CORE)/memcopy.c \
$(BACNET_CORE)/hostnport.c \
$(BACNET_CORE)/npdu.c \
+7 -24
View File
@@ -1,27 +1,10 @@
/**************************************************************************
*
* Copyright (C) 2014 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.
*
*********************************************************************/
/**
* @file
* @brief ADC configuration
* @author Steve Karg <skarg@users.sourceforge.net>
* @date 2014
* @copyright SPDX-License-Identifier: MIT
*/
#include <stdint.h>
#include <stdbool.h>
#include <asf.h>
+7 -23
View File
@@ -1,26 +1,10 @@
/**************************************************************************
*
* Copyright (C) 2014 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.
*********************************************************************/
/**
* @file
* @brief ADC configuration
* @author Steve Karg <skarg@users.sourceforge.net>
* @date 2014
* @copyright SPDX-License-Identifier: MIT
*/
#ifndef ADC_HDW_H
#define ADC_HDW_H
+7 -27
View File
@@ -1,30 +1,10 @@
/**************************************************************************
*
* Copyright (C) 2005 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.
*
*********************************************************************/
/* Analog Input Objects customize for your use */
/**
* @file
* @brief Analog Input objects, customize for your use as required.
* @author Steve Karg <skarg@users.sourceforge.net>
* @date 2005
* @copyright SPDX-License-Identifier: MIT
*/
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
+7 -24
View File
@@ -1,27 +1,10 @@
/**************************************************************************
*
* Copyright (C) 2013 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.
*
*********************************************************************/
/**
* @file
* @brief BACnet task and initialization for the Xplained board
* @author Steve Karg <skarg@users.sourceforge.net>
* @date 2013
* @copyright SPDX-License-Identifier: MIT
*/
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
+20 -5
View File
@@ -707,11 +707,6 @@
<Compile Include="netport.c">
<SubType>compile</SubType>
</Compile>
<Compile Include="dlmstp.c">
<SubType>compile</SubType>
<CustomCompilationSetting Condition="'$(Configuration)' == 'Debug'">
</CustomCompilationSetting>
</Compile>
<Compile Include="..\..\src\bacnet\basic\service\h_dcc.c">
<SubType>compile</SubType>
<Link>bacnet-stack\h_dcc.c</Link>
@@ -800,10 +795,26 @@
<SubType>compile</SubType>
<Link>bacnet-stack\bacstr.c</Link>
</Compile>
<Compile Include="..\..\src\bacnet\datalink\cobs.c">
<SubType>compile</SubType>
<Link>bacnet-stack\cobs.c</Link>
</Compile>
<Compile Include="..\..\src\bacnet\datalink\crc.c">
<SubType>compile</SubType>
<Link>bacnet-stack\crc.c</Link>
</Compile>
<Compile Include="..\..\src\bacnet\datalink\dlmstp.c">
<SubType>compile</SubType>
<Link>bacnet-stack\dlmstp.c</Link>
</Compile>
<Compile Include="..\..\src\bacnet\datalink\mstptext.c">
<SubType>compile</SubType>
<Link>bacnet-stack\mstptext.c</Link>
</Compile>
<Compile Include="..\..\src\bacnet\datalink\mstp.c">
<SubType>compile</SubType>
<Link>bacnet-stack\mstp.c</Link>
</Compile>
<Compile Include="..\..\src\bacnet\dcc.c">
<SubType>compile</SubType>
<Link>bacnet-stack\dcc.c</Link>
@@ -820,6 +831,10 @@
<SubType>compile</SubType>
<Link>bacnet-stack\ihave.c</Link>
</Compile>
<Compile Include="..\..\src\bacnet\indtext.c">
<SubType>compile</SubType>
<Link>bacnet-stack\indtext.c</Link>
</Compile>
<Compile Include="..\..\src\bacnet\memcopy.c">
<SubType>compile</SubType>
<Link>bacnet-stack\memcopy.c</Link>
+7 -23
View File
@@ -1,26 +1,10 @@
/**************************************************************************
*
* Copyright (C) 2010 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.
*********************************************************************/
/**
* @file
* @brief API for BACnet task and initialization for the Xplained board
* @author Steve Karg <skarg@users.sourceforge.net>
* @date 2013
* @copyright SPDX-License-Identifier: MIT
*/
#ifndef BACNET_H
#define BACNET_H
+7 -24
View File
@@ -1,27 +1,10 @@
/**************************************************************************
*
* Copyright (C) 2011 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.
*
*********************************************************************/
/**
* @file
* @brief API for BACnet device name handling for the Xplained board
* @author Steve Karg <skarg@users.sourceforge.net>
* @date 2010
* @copyright SPDX-License-Identifier: MIT
*/
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
+7 -23
View File
@@ -1,26 +1,10 @@
/**************************************************************************
*
* Copyright (C) 2010 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.
*********************************************************************/
/**
* @file
* @brief API for BACnet device name handling for the Xplained board
* @author Steve Karg <skarg@users.sourceforge.net>
* @date 2010
* @copyright SPDX-License-Identifier: MIT
*/
#ifndef BACNET_NAME_H
#define BACNET_NAME_H
+7 -24
View File
@@ -1,27 +1,10 @@
/**************************************************************************
*
* Copyright (C) 2015 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.
*
*********************************************************************/
/**
* @file
* @brief BACnet device object handling for the Xplained board
* @author Steve Karg <skarg@users.sourceforge.net>
* @date 2015
* @copyright SPDX-License-Identifier: MIT
*/
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
File diff suppressed because it is too large Load Diff
+7 -23
View File
@@ -1,26 +1,10 @@
/**************************************************************************
*
* 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.
*********************************************************************/
/**
* @file
* @brief LED configuration and operation
* @author Steve Karg <skarg@users.sourceforge.net>
* @date 2014
* @copyright SPDX-License-Identifier: MIT
*/
#include <stdint.h>
#include "board.h"
#include "ioport.h"
+7 -23
View File
@@ -1,26 +1,10 @@
/**************************************************************************
*
* 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.
*********************************************************************/
/**
* @file
* @brief LED configuration and operation
* @author Steve Karg <skarg@users.sourceforge.net>
* @date 2014
* @copyright SPDX-License-Identifier: MIT
*/
#ifndef LED_H
#define LED_H
+53 -5
View File
@@ -1,19 +1,66 @@
/**
* \file
*
* \brief XMEGA-A3BU BACnet application
*
* @file
* @brief XMEGA-A3BU BACnet application
* @author Steve Karg <skarg@users.sourceforge.net>
* @date 2014
* @copyright SPDX-License-Identifier: MIT
*/
#include <asf.h>
#include "bacnet/basic/sys/mstimer.h"
#include "bacnet/datalink/datalink.h"
#include "bacnet/datalink/dlmstp.h"
#include "bacnet/datalink/mstp.h"
#include "rs485.h"
#include "led.h"
#include "adc-hdw.h"
#include "bacnet/datalink/dlmstp.h"
#include "bacnet.h"
static struct mstimer_callback_data_t BACnet_Callback;
/* MS/TP port */
static struct mstp_port_struct_t MSTP_Port;
static struct dlmstp_rs485_driver RS485_Driver = {
.init = rs485_init,
.send = rs485_bytes_send,
.read = rs485_byte_available,
.transmitting = rs485_rts_enabled,
.baud_rate = rs485_baud_rate,
.baud_rate_set = rs485_baud_rate_set,
.silence_milliseconds = rs485_silence_milliseconds,
.silence_reset = rs485_silence_reset
};
static struct dlmstp_user_data_t MSTP_User_Data;
static uint8_t Input_Buffer[DLMSTP_MPDU_MAX];
static uint8_t Output_Buffer[DLMSTP_MPDU_MAX];
/**
* @brief MS/TP configuraiton
*/
static void dlmstp_configure(void)
{
/* initialize MSTP datalink layer */
MSTP_Port.Nmax_info_frames = DLMSTP_MAX_INFO_FRAMES;
MSTP_Port.Nmax_master = DLMSTP_MAX_MASTER;
MSTP_Port.InputBuffer = Input_Buffer;
MSTP_Port.InputBufferSize = sizeof(Input_Buffer);
MSTP_Port.OutputBuffer = Output_Buffer;
MSTP_Port.OutputBufferSize = sizeof(Output_Buffer);
/* user data */
MSTP_Port.ZeroConfigEnabled = true;
MSTP_Port.SlaveNodeEnabled = false;
MSTP_User_Data.RS485_Driver = &RS485_Driver;
MSTP_Port.UserData = &MSTP_User_Data;
dlmstp_init((char *)&MSTP_Port);
if (MSTP_Port.ZeroConfigEnabled) {
dlmstp_set_mac_address(255);
} else {
/* FIXME: get the address from hardware DIP or from EEPROM */
dlmstp_set_mac_address(1);
}
/* FIXME: get the baud rate from hardware DIP or from EEPROM */
dlmstp_set_baud_rate(DLMSTP_BAUD_RATE_DEFAULT);
}
/**
* \brief Main function.
*
@@ -41,6 +88,7 @@ int main(void)
cpu_irq_enable();
/* application initialization */
rs485_baud_rate_set(38400);
dlmstp_configure();
bacnet_init();
/* run forever - timed tasks */
mstimer_callback(&BACnet_Callback, bacnet_task_timed, 5);
+4 -28
View File
@@ -1,33 +1,9 @@
/*
/**
* @file
*
* @brief 1ms timer configuration
*
* Copyright (C) 2009 Steve Karg <skarg@users.sourceforge.net>
*
* Created: 10/24/2013 8:58:56 PM
* Author: Steve
*
* @page License
*
* 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.
* @author Steve Karg <skarg@users.sourceforge.net>
* @date 2013
* @copyright SPDX-License-Identifier: MIT
*/
#include <stdint.h>
#include <stdbool.h>
+4 -27
View File
@@ -1,34 +1,11 @@
/**
* @file
* @author Steve Karg
* @date 2016
* @brief Network port objects, customize for your use
*
* @section DESCRIPTION
*
* The Network Port object provides access to the configuration
* @details The Network Port object provides access to the configuration
* and properties of network ports of a device.
*
* @section LICENSE
*
* 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.
* @author Steve Karg <skarg@users.sourceforge.net>
* @date 2014
* @copyright SPDX-License-Identifier: MIT
*/
#include <stdbool.h>
#include <stdint.h>
+2 -2
View File
@@ -1,9 +1,9 @@
/**
* @file
* @brief Store and retrieve non-volatile data
* @author Steve Karg <skarg@users.sourceforge.net>
* @date 2013
* @brief Store and retrieve non-volatile data
*
* @copyright SPDX-License-Identifier: MIT
*/
#include <stdint.h>
#include <stdbool.h>
+7 -24
View File
@@ -1,27 +1,10 @@
/************************************************************************
*
* Copyright (C) 2013 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.
*
*************************************************************************/
/**
* @file
* @brief Store and retrieve non-volatile data
* @author Steve Karg <skarg@users.sourceforge.net>
* @date 2013
* @copyright SPDX-License-Identifier: MIT
*/
#ifndef NVM_DATA_H
#define NVM_DATA_H
+37 -82
View File
@@ -1,30 +1,9 @@
/**
* @file
*
* @brief RS-485 Interface
*
* Copyright (C) 2013 Steve Karg <skarg@users.sourceforge.net>
*
* @page License
*
* 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.
* @author Steve Karg <skarg@users.sourceforge.net>
* @date 2013
* @copyright SPDX-License-Identifier: MIT
*/
#include <string.h>
#include <stdio.h>
@@ -71,11 +50,14 @@ static FIFO_BUFFER Transmit_Queue;
static uint32_t Baud_Rate;
/* timer for measuring line silence */
static struct mstimer Silence_Timer;
/* flag to track RTS status */
static volatile bool RTS_Status;
/* flag to track transmit status */
static volatile bool Transmitting;
/* statistics */
static volatile uint32_t RS485_Transmit_Bytes;
static volatile uint32_t RS485_Receive_Bytes;
/**
* Resets the silence timer
* @brief Reset the silence on the wire timer.
*/
void rs485_silence_reset(void)
{
@@ -83,15 +65,12 @@ void rs485_silence_reset(void)
}
/**
* Determine the amount of silence on the wire from the timer.
*
* @param interval - amount of time in milliseconds that line could be silent
*
* @return true if the line has been silent for the interval
* @brief Return the RS-485 silence time in milliseconds
* @return silence time in milliseconds
*/
bool rs485_silence_elapsed(uint32_t interval)
uint32_t rs485_silence_milliseconds(void)
{
return (mstimer_elapsed(&Silence_Timer) > interval);
return mstimer_elapsed(&Silence_Timer);
}
/**
@@ -106,13 +85,13 @@ void rs485_rts_enable(bool enable)
ioport_set_value(RS485_RE, 1);
ioport_set_value(RS485_DE, 1);
led_on(LED_RS485_TX);
RTS_Status = true;
Transmitting = true;
} else {
/* Turn Tx enable off */
ioport_set_value(RS485_RE, 0);
ioport_set_value(RS485_DE, 0);
led_off_delay(LED_RS485_TX, 10);
RTS_Status = false;
Transmitting = false;
}
}
@@ -123,39 +102,7 @@ void rs485_rts_enable(bool enable)
*/
bool rs485_rts_enabled(void)
{
return RTS_Status;
}
/**
* Baud rate determines turnaround time.
* The minimum time after the end of the stop bit of the final octet of a
* received frame before a node may enable its EIA-485 driver: 40 bit times.
* At 9600 baud, 40 bit times would be about 4.166 milliseconds
* At 19200 baud, 40 bit times would be about 2.083 milliseconds
* At 38400 baud, 40 bit times would be about 1.041 milliseconds
* At 57600 baud, 40 bit times would be about 0.694 milliseconds
* At 76800 baud, 40 bit times would be about 0.520 milliseconds
* At 115200 baud, 40 bit times would be about 0.347 milliseconds
* 40 bits is 4 octets including a start and stop bit with each octet
*
* @return: amount of milliseconds to wait
*/
static uint16_t rs485_turnaround_time(void)
{
/* delay after reception before transmitting - per MS/TP spec */
/* wait a minimum 40 bit times since reception */
/* at least 2 ms for errors: rounding, clock tick */
return (2 + ((Tturnaround * 1000) / Baud_Rate));
}
/**
* Use the silence timer to determine turnaround time.
*
* @return true if the line has been silent for the turnaround interval
*/
bool rs485_turnaround_elapsed(void)
{
return (mstimer_elapsed(&Silence_Timer) > rs485_turnaround_time());
return Transmitting;
}
/**
@@ -175,6 +122,7 @@ bool rs485_byte_available(uint8_t *data_register)
led_on(LED_RS485_RX);
if (data_register) {
*data_register = FIFO_Get(&Receive_Queue);
RS485_Receive_Bytes++;
}
data_available = true;
}
@@ -192,16 +140,6 @@ bool rs485_receive_error(void)
return false;
}
/**
* Determines if the entire frame is sent from USART FIFO
*
* @return true if the USART FIFO is empty
*/
bool rs485_frame_sent(void)
{
return usart_tx_is_complete(&RS485_USART);
}
/**
* Transmit one or more bytes on RS-485. Can be called while transmitting to
* add additional bytes to transmit queue.
@@ -209,7 +147,7 @@ bool rs485_frame_sent(void)
* @param buffer - array of one or more bytes to transmit
* @param nbytes - number of bytes to transmit
*/
bool rs485_bytes_send(uint8_t *buffer, uint16_t nbytes)
void rs485_bytes_send(uint8_t *buffer, uint16_t nbytes)
{
bool status = false;
bool start_required = false;
@@ -227,10 +165,9 @@ bool rs485_bytes_send(uint8_t *buffer, uint16_t nbytes)
usart_clear_tx_complete(&RS485_USART);
usart_set_tx_interrupt_level(&RS485_USART, USART_INT_LVL_LO);
usart_putchar(&RS485_USART, ch);
RS485_Transmit_Bytes++;
}
}
return status;
}
/**
@@ -306,6 +243,24 @@ bool rs485_baud_rate_set(uint32_t baud)
return valid;
}
/**
* @brief Return the RS-485 statistics for transmit bytes
* @return number of bytes transmitted
*/
uint32_t rs485_bytes_transmitted(void)
{
return RS485_Transmit_Bytes;
}
/**
* @brief Return the RS-485 statistics for receive bytes
* @return number of bytes received
*/
uint32_t rs485_bytes_received(void)
{
return RS485_Receive_Bytes;
}
/**
* Initialize the RS-485 UART interface, receive interrupts enabled
*/
+21 -45
View File
@@ -1,26 +1,10 @@
/**************************************************************************
*
* 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.
*********************************************************************/
/**
* @file
* @brief RS-485 Interface
* @author Steve Karg <skarg@users.sourceforge.net>
* @date 2013
* @copyright SPDX-License-Identifier: MIT
*/
#ifndef RS485_H
#define RS485_H
@@ -30,30 +14,22 @@
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
void rs485_rts_enable(
bool enable);
bool rs485_rts_enabled(
void);
bool rs485_byte_available(
uint8_t * data_register);
bool rs485_receive_error(
void);
bool rs485_bytes_send(
uint8_t * buffer, /* data to send */
uint16_t nbytes); /* number of bytes of data */
bool rs485_frame_sent(void);
bool rs485_turnaround_elapsed(
void);
uint32_t rs485_baud_rate(
void);
bool rs485_baud_rate_set(
uint32_t baud);
void rs485_rts_enable(bool enable);
bool rs485_rts_enabled(void);
bool rs485_byte_available(uint8_t *data_register);
bool rs485_receive_error(void);
void rs485_silence_reset(
void);
bool rs485_silence_elapsed(
uint32_t interval);
void rs485_bytes_send(uint8_t *buffer, uint16_t nbytes);
uint32_t rs485_baud_rate(void);
bool rs485_baud_rate_set(uint32_t baud);
uint32_t rs485_silence_milliseconds(void);
void rs485_silence_reset(void);
uint32_t rs485_bytes_transmitted(void);
uint32_t rs485_bytes_received(void);
void rs485_init(void);
+7 -24
View File
@@ -1,27 +1,10 @@
/**************************************************************************
*
* 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.
*
*********************************************************************/
/**
* @file
* @brief AVR C-Stack Tracking for stack overflow detection
* @author Steve Karg <skarg@users.sourceforge.net>
* @date 2013
* @copyright SPDX-License-Identifier: MIT
*/
#include "board.h"
/* me */
#include "stack.h"
+7 -24
View File
@@ -1,27 +1,10 @@
/**************************************************************************
*
* 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.
*
*********************************************************************/
/**
* @file
* @brief API for AVR C-Stack Tracking for stack overflow detection
* @author Steve Karg <skarg@users.sourceforge.net>
* @date 2013
* @copyright SPDX-License-Identifier: MIT
*/
#ifndef STACK_H
#define STACK_H
+8
View File
@@ -22,6 +22,14 @@
#define islessgreater(x, y) ((x) < (y) || (x) > (y))
#endif
#ifndef isgreaterequal
#define isgreaterequal(x, y) ((x) > (y) || !islessgreater((x),(y)))
#endif
#ifndef islessequal
#define islessequal(x, y) ((x) < (y) || !islessgreater((x),(y)))
#endif
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(array) ((size_t)(sizeof(array) / sizeof((array)[0])))
#endif