Skip to content
Merged
3 changes: 3 additions & 0 deletions samples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ TWISTER_RC=$?
# twister output directory cleanup files we do not archive
find "$OUTPUT_DIR" -name 'CMakeFiles' -exec rm -rf {} \; 2>/dev/null
find "$OUTPUT_DIR" -name 'modules' -exec rm -rf {} \; 2>/dev/null
find "$OUTPUT_DIR" -type f \( -name '*.bin' -o -name '*.hex' -o -name '*.elf' -o -name '*.map' \) -exec rm -f {} + 2>/dev/null
find "$OUTPUT_DIR" -type f -exec chmod u+rw,go+r {} + 2>/dev/null
find "$OUTPUT_DIR" -type d -exec chmod u+rwx,go+rx {} + 2>/dev/null
find "$OUTPUT_DIR" -name 'app' -exec rm -rf \
'{}/../zephyr/arch
{}/../zephyr/boards
Expand Down
3 changes: 3 additions & 0 deletions subsys.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ TWISTER_RC=$?
# twister output directory cleanup files we do not archive
find "$OUTPUT_DIR" -name 'CMakeFiles' -exec rm -rf {} \; 2>/dev/null
find "$OUTPUT_DIR" -name 'modules' -exec rm -rf {} \; 2>/dev/null
find "$OUTPUT_DIR" -type f \( -name '*.bin' -o -name '*.hex' -o -name '*.elf' -o -name '*.map' \) -exec rm -f {} + 2>/dev/null
find "$OUTPUT_DIR" -type f -exec chmod u+rw,go+r {} + 2>/dev/null
find "$OUTPUT_DIR" -type d -exec chmod u+rwx,go+rx {} + 2>/dev/null
find "$OUTPUT_DIR" -name 'app' -exec rm -rf \
'{}/../zephyr/arch
{}/../zephyr/boards
Expand Down
3 changes: 3 additions & 0 deletions unittest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ TWISTER_RC=$?
# twister output directory cleanup files we do not archive
find "$OUTPUT_DIR" -name 'CMakeFiles' -exec rm -rf {} \; 2>/dev/null
find "$OUTPUT_DIR" -name 'modules' -exec rm -rf {} \; 2>/dev/null
find "$OUTPUT_DIR" -type f \( -name '*.bin' -o -name '*.hex' -o -name '*.elf' -o -name '*.map' \) -exec rm -f {} + 2>/dev/null
find "$OUTPUT_DIR" -type f -exec chmod u+rw,go+r {} + 2>/dev/null
find "$OUTPUT_DIR" -type d -exec chmod u+rwx,go+rx {} + 2>/dev/null
find "$OUTPUT_DIR" -name 'app' -exec rm -rf \
'{}/../zephyr/arch
{}/../zephyr/boards
Expand Down
28 changes: 28 additions & 0 deletions zephyr/include/bacnet_osif/bacnet_reinit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* @file
* @brief BACnet OS interface for ReinitializeDevice reboot handling
* @author Steve Karg <skarg@users.sourceforge.net>
* @date August 2026
* @copyright SPDX-License-Identifier: Apache-2.0
*/
#ifndef BACNET_OSIF_BACNET_REINIT_H
#define BACNET_OSIF_BACNET_REINIT_H

#include <stdint.h>

typedef void (*bacnet_reinitialize_device_coldstart_callback)(void *context);

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

void bacnet_reinitialize_device_task(
bacnet_reinitialize_device_coldstart_callback coldstart_callback,
void *context);
void bacnet_reinitialize_device_init(uint32_t timeout_ms);

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* BACNET_OSIF_BACNET_REINIT_H */
1 change: 1 addition & 0 deletions zephyr/include/bacnet_settings/bacnet_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ bool bacnet_settings_string_set(
const char *value);

bool bacnet_settings_init(void);
int bacnet_settings_clear(void);

#ifdef __cplusplus
}
Expand Down
1 change: 1 addition & 0 deletions zephyr/include/bacnet_settings/bacnet_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ int bacnet_storage_set(
BACNET_STORAGE_KEY *key, const void *data, size_t data_size);
int bacnet_storage_get(BACNET_STORAGE_KEY *key, void *data, size_t data_size);
int bacnet_storage_delete(BACNET_STORAGE_KEY *key);
int bacnet_storage_clear(void);

#ifdef __cplusplus
}
Expand Down
1 change: 1 addition & 0 deletions zephyr/samples/profiles/b-asc/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ CONFIG_NVS=y
CONFIG_SETTINGS=y
CONFIG_SETTINGS_NVS=y
CONFIG_SETTINGS_RUNTIME=y
CONFIG_REBOOT=y
#CONFIG_SETTINGS_FILE=y
#CONFIG_SETTINGS_SHELL=y
# native_posix uses a simulated flash
Expand Down
19 changes: 18 additions & 1 deletion zephyr/samples/profiles/b-asc/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "bacnet/basic/server/bacnet_port.h"
/* BACnet Stack Zephyr services */
#include <bacnet_settings/bacnet_settings.h>
#include <bacnet_osif/bacnet_reinit.h>
/* Logging module registration is already done in ports/zephyr/main.c */
#include <bacnet_osif/bacnet_log.h>
LOG_MODULE_DECLARE(bacnet, CONFIG_BACNETSTACK_LOG_LEVEL);
Expand All @@ -38,6 +39,21 @@ static const uint32_t Device_Instance = 260127;
static const char *Device_Name =
"BACnet Application Specific Controller (B-ASC)";

/**
* @brief Clear any stored BACnet settings before a cold start reboot
* @param context [in] The context to pass to the callback function
*/
static void BACnet_Device_Coldstart_Callback(void *context)
{
int err;

(void)context;
err = bacnet_settings_clear();
if (err < 0) {
LOG_ERR("Failed to clear BACnet settings: %d", err);
}
}

/**
* @brief Callback data for WriteProperty restore iterator
* @param write_function The WriteProperty function to call
Expand Down Expand Up @@ -110,6 +126,7 @@ static void BACnet_Device_Init_Handler(void *context)
/* done */
LOG_INF("BACnet Device ID: %u", Device_Object_Instance_Number());
bacnet_basic_task_object_timer_set(1000UL);
bacnet_reinitialize_device_init(3000);
srand(sys_rand32_get());
}

Expand All @@ -120,7 +137,7 @@ static void BACnet_Device_Init_Handler(void *context)
*/
static void BACnet_Device_Task_Handler(void *context)
{
(void)context;
bacnet_reinitialize_device_task(BACnet_Device_Coldstart_Callback, context);
}

int main(void)
Expand Down
1 change: 1 addition & 0 deletions zephyr/samples/profiles/b-ld/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ CONFIG_NVS=y
CONFIG_SETTINGS=y
CONFIG_SETTINGS_NVS=y
CONFIG_SETTINGS_RUNTIME=y
CONFIG_REBOOT=y
#CONFIG_SETTINGS_FILE=y
#CONFIG_SETTINGS_SHELL=y

Expand Down
20 changes: 19 additions & 1 deletion zephyr/samples/profiles/b-ld/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

/* BACnet Stack Zephyr services */
#include <bacnet_settings/bacnet_settings.h>
#include <bacnet_osif/bacnet_reinit.h>
/* Logging module registration is already done in ports/zephyr/main.c */
#include <bacnet_osif/bacnet_log.h>
LOG_MODULE_DECLARE(bacnet, CONFIG_BACNETSTACK_LOG_LEVEL);
Expand Down Expand Up @@ -124,6 +125,21 @@ Settings_Restore_Callback(BACNET_WRITE_PROPERTY_DATA *wp_data, void *context)
return Device_Write_Property(wp_data);
}

/**
* @brief Clear any stored BACnet settings before a cold start reboot
* @param context [in] The context to pass to the callback function
*/
static void BACnet_Lighting_Device_Coldstart_Callback(void *context)
{
int err;

(void)context;
err = bacnet_settings_clear();
if (err < 0) {
LOG_ERR("Failed to clear BACnet settings: %d", err);
}
}

/**
* @brief BACnet Project Initialization Handler
* @param context [in] The context to pass to the callback function
Expand Down Expand Up @@ -152,6 +168,7 @@ static void BACnet_Lighting_Device_Init_Handler(void *context)
LOG_INF("BACnet Device ID: %u", Device_Object_Instance_Number());
/* set the BACnet Basic Task device object timer for lighting output use */
bacnet_basic_task_object_timer_set(10UL);
bacnet_reinitialize_device_init(3000);
srand(sys_rand32_get());
}

Expand All @@ -162,7 +179,8 @@ static void BACnet_Lighting_Device_Init_Handler(void *context)
*/
static void BACnet_Lighting_Device_Task_Handler(void *context)
{
(void)context;
bacnet_reinitialize_device_task(
BACnet_Lighting_Device_Coldstart_Callback, context);
}

int main(void)
Expand Down
1 change: 1 addition & 0 deletions zephyr/samples/profiles/b-ls/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ CONFIG_NVS=y
CONFIG_SETTINGS=y
CONFIG_SETTINGS_NVS=y
CONFIG_SETTINGS_RUNTIME=y
CONFIG_REBOOT=y
#CONFIG_SETTINGS_FILE=y
#CONFIG_SETTINGS_SHELL=y
# native_posix uses a simulated flash
Expand Down
20 changes: 19 additions & 1 deletion zephyr/samples/profiles/b-ls/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "bacnet/basic/server/bacnet_port.h"
/* BACnet Stack Zephyr services */
#include <bacnet_settings/bacnet_settings.h>
#include <bacnet_osif/bacnet_reinit.h>
/* Logging module registration is already done in ports/zephyr/main.c */
#include <bacnet_osif/bacnet_log.h>
LOG_MODULE_DECLARE(bacnet, CONFIG_BACNETSTACK_LOG_LEVEL);
Expand Down Expand Up @@ -108,6 +109,21 @@ void Binary_Lighting_Output_Blink_Warn_Handler(uint32_t object_instance)
(unsigned long)object_instance);
}

/**
* @brief Clear any stored BACnet settings before a cold start reboot
* @param context [in] The context to pass to the callback function
*/
static void BACnet_Lighting_Device_Coldstart_Callback(void *context)
{
int err;

(void)context;
err = bacnet_settings_clear();
if (err < 0) {
LOG_ERR("Failed to clear BACnet settings: %d", err);
}
}

/**
* @brief Callback data for WriteProperty restore iterator
* @param write_function The WriteProperty function to call
Expand Down Expand Up @@ -182,6 +198,7 @@ static void BACnet_Lighting_Device_Init_Handler(void *context)
LOG_INF("BACnet Device ID: %u", Device_Object_Instance_Number());
/* set the BACnet Basic Task device object timer for lighting output use */
bacnet_basic_task_object_timer_set(10UL);
bacnet_reinitialize_device_init(3000);
srand(sys_rand32_get());
}

Expand All @@ -192,7 +209,8 @@ static void BACnet_Lighting_Device_Init_Handler(void *context)
*/
static void BACnet_Lighting_Device_Task_Handler(void *context)
{
(void)context;
bacnet_reinitialize_device_task(
BACnet_Lighting_Device_Coldstart_Callback, context);
}

int main(void)
Expand Down
1 change: 1 addition & 0 deletions zephyr/samples/profiles/b-sa/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ CONFIG_NVS=y
CONFIG_SETTINGS=y
CONFIG_SETTINGS_NVS=y
CONFIG_SETTINGS_RUNTIME=y
CONFIG_REBOOT=y
#CONFIG_SETTINGS_FILE=y
#CONFIG_SETTINGS_SHELL=y
# native_posix uses a simulated flash
Expand Down
19 changes: 19 additions & 0 deletions zephyr/samples/profiles/b-sa/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "bacnet/basic/server/bacnet_port.h"
/* BACnet Stack Zephyr services */
#include <bacnet_settings/bacnet_settings.h>
#include <bacnet_osif/bacnet_reinit.h>
/* Logging module registration is already done in ports/zephyr/main.c */
#include <bacnet_osif/bacnet_log.h>
LOG_MODULE_DECLARE(bacnet, CONFIG_BACNETSTACK_LOG_LEVEL);
Expand All @@ -44,6 +45,21 @@ static void BACnet_Smart_Actuator_Datalink_Init(void)
/* nothing to do */
}

/**
* @brief Clear any stored BACnet settings before a cold start reboot
* @param context [in] The context to pass to the callback function
*/
static void BACnet_Smart_Actuator_Coldstart_Callback(void *context)
{
int err;

(void)context;
err = bacnet_settings_clear();
if (err < 0) {
LOG_ERR("Failed to clear BACnet settings: %d", err);
}
}

/**
* @brief Callback data for WriteProperty restore iterator
* @param write_function The WriteProperty function to call
Expand Down Expand Up @@ -85,6 +101,7 @@ static void BACnet_Smart_Actuator_Init_Handler(void *context)
LOG_INF("BACnet Device ID: %u", Device_Object_Instance_Number());
/* start the seconds cyclic timer */
mstimer_set(&Actuator_Update_Timer, 1000);
bacnet_reinitialize_device_init(3000);
srand(sys_rand32_get());
}

Expand All @@ -98,6 +115,8 @@ static void BACnet_Smart_Actuator_Task_Handler(void *context)
float percent = 0.0f, change = 0.0f;

(void)context;
bacnet_reinitialize_device_task(
BACnet_Smart_Actuator_Coldstart_Callback, context);
if (mstimer_expired(&Actuator_Update_Timer)) {
mstimer_reset(&Actuator_Update_Timer);
/* simulate an internal software program,
Expand Down
1 change: 1 addition & 0 deletions zephyr/samples/profiles/b-ss/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ CONFIG_NVS=y
CONFIG_SETTINGS=y
CONFIG_SETTINGS_NVS=y
CONFIG_SETTINGS_RUNTIME=y
CONFIG_REBOOT=y
# BACnet Library - options
CONFIG_BACNET_MAX_CHARACTER_STRING_BYTES=128
CONFIG_BACAPP_MINIMAL=y
Expand Down
20 changes: 19 additions & 1 deletion zephyr/samples/profiles/b-ss/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
/* BACnet Stack Zephyr services */
#include <bacnet_settings/bacnet_settings.h>
#include <bacnet_settings/bacnet_storage.h>
#include <bacnet_osif/bacnet_reinit.h>
/* Logging module registration is already done in ports/zephyr/main.c */
#include <bacnet_osif/bacnet_log.h>
LOG_MODULE_DECLARE(bacnet, CONFIG_BACNETSTACK_LOG_LEVEL);
Expand All @@ -39,6 +40,21 @@ static const uint32_t Sensor_Instance = 1;
/* timer for Sensor Update Interval */
static struct mstimer Sensor_Update_Timer;

/**
* @brief Clear any stored BACnet settings before a cold start reboot
* @param context [in] The context to pass to the callback function
*/
static void BACnet_Smart_Sensor_Coldstart_Callback(void *context)
{
int err;

(void)context;
err = bacnet_settings_clear();
if (err < 0) {
LOG_ERR("Failed to clear BACnet settings: %d", err);
}
}

/**
* @brief Callback data for WriteProperty restore iterator
* @param write_function The WriteProperty function to call
Expand Down Expand Up @@ -80,6 +96,7 @@ static void BACnet_Smart_Sensor_Init_Handler(void *context)
LOG_INF("BACnet Device ID: %u", Device_Object_Instance_Number());
/* start the seconds cyclic timer */
mstimer_set(&Sensor_Update_Timer, 1000);
bacnet_reinitialize_device_init(3000);
srand(sys_rand32_get());
}

Expand All @@ -92,7 +109,8 @@ static void BACnet_Smart_Sensor_Task_Handler(void *context)
{
float temperature = 0.0f, change = 0.0f;

(void)context;
bacnet_reinitialize_device_task(
BACnet_Smart_Sensor_Coldstart_Callback, context);
if (mstimer_expired(&Sensor_Update_Timer)) {
mstimer_reset(&Sensor_Update_Timer);
/* simulate a sensor reading, and update the BACnet object values */
Expand Down
1 change: 1 addition & 0 deletions zephyr/subsys/bacnet_osif/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
zephyr_sources(
bacnet_log.c
bacnet_mstimer.c
bacnet_reinit.c
)
Loading