#
# Copyright (c) 2018 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

# ─── UART (Async, no console) ───────────────────────────────────────────────
CONFIG_SERIAL=y
CONFIG_UART_ASYNC_API=y
CONFIG_NRFX_UARTE0=y
CONFIG_CONSOLE=n
CONFIG_UART_CONSOLE=n


# ─── FOR UART STOP and RESTART AT RUNTIME WHEN UART RX ERROR EVT TRIGGERS ─────────────────────
CONFIG_PM_DEVICE=y
CONFIG_PM_DEVICE_RUNTIME=y


# ─── BLE Stack (Central / Scanner) ──────────────────────────────────────────
CONFIG_BT=y
CONFIG_BT_CENTRAL=y
CONFIG_BT_GATT_CLIENT=y
CONFIG_BT_SMP=y

# BLE NCS modules
CONFIG_BT_NUS_CLIENT=y
CONFIG_BT_SCAN=y
CONFIG_BT_SCAN_FILTER_ENABLE=y
CONFIG_BT_SCAN_UUID_CNT=1
CONFIG_BT_GATT_DM=y

# MTU / buffer sizing for 40-byte chunks
CONFIG_BT_L2CAP_TX_MTU=247
CONFIG_BT_BUF_ACL_TX_SIZE=251
CONFIG_BT_BUF_ACL_RX_SIZE=251
CONFIG_BT_CTLR_DATA_LENGTH_MAX=251

# BLE stack sizes
CONFIG_BT_RX_STACK_SIZE=4096

# Reduce BLE log noise — only errors
CONFIG_BT_LOG_LEVEL_ERR=y

# ─── Stack / Heap ────────────────────────────────────────────────────────────
CONFIG_MAIN_STACK_SIZE=4096
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096
CONFIG_HEAP_MEM_POOL_SIZE=4096

# ─── RTT Logging (no UART backend) ──────────────────────────────────────────
CONFIG_LOG=y
CONFIG_USE_SEGGER_RTT=y
CONFIG_LOG_BACKEND_RTT=y
CONFIG_LOG_BACKEND_UART=n
CONFIG_LOG_PRINTK=y
# 23rd March 2026, RTT BUFFER SIZE increased for crash log capture
CONFIG_SEGGER_RTT_BUFFER_SIZE_UP=4096
# ─── GPIO / SPI (needed for nRF21540 FEM) ───────────────────────────────────
CONFIG_GPIO=y
CONFIG_SPI=y

# ─── RTC Calendar ────────────────────────────────────────────────────────────
CONFIG_RTC=y
CONFIG_RTC_UPDATE=y

# ─── Watchdog ────────────────────────────────────────────────────────────────
CONFIG_WATCHDOG=y
CONFIG_REBOOT=y

# ─── Clock (RC low-frequency, 500 ppm) ───────────────────────────────────────
CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC=y
CONFIG_CLOCK_CONTROL_NRF_K32SRC_500PPM=y

# ─── Range Extender: nRF21540 FEM ────────────────────────────────────────────
CONFIG_MPSL=y
CONFIG_MPSL_FEM=y
CONFIG_MPSL_FEM_NRF21540_GPIO_SPI=y
CONFIG_MPSL_FEM_NRF21540_TX_GAIN_DB=20
CONFIG_MPSL_FEM_POWER_MODEL=y
CONFIG_MPSL_FEM_POWER_MODEL_NRF21540_USE_BUILTIN=y
CONFIG_BT_CTLR_TX_PWR_ANTENNA=20

# ─── Assert ──────────────────────────────────────────────────────────────────
CONFIG_ASSERT=y

# ─── Heap runtime stats (optional, useful for debugging) ─────────────────────
CONFIG_SYS_HEAP_RUNTIME_STATS=y

# ─────────── prj.conf ADDDED ON -> 9th MARCH for CRC CHECK ──────────────────────
CONFIG_CRC=y

# ─── Fatal Error Debugging 10th MARCH 2026, ───────────────────────────────────────────────────
CONFIG_RESET_ON_FATAL_ERROR=n       # Prevent immediate reboot so output is visible
CONFIG_THREAD_NAME=y                # Show thread name (e.g. "main") instead of "unknown"
CONFIG_ASSERT=y
CONFIG_ASSERT_VERBOSE=y
CONFIG_ASSERT_NO_COND_INFO=n
CONFIG_ASSERT_NO_MSG_INFO=n
# Stack overflow detection
CONFIG_HW_STACK_PROTECTION=y
CONFIG_INIT_STACKS=y
# Immediate logging ensures crash logs are flushed before halt
CONFIG_LOG_MODE_IMMEDIATE=y



#────────────────────────────  THREAD ANALYZER FOR STACK OVERFLOW DETECTION ──────────────────────
#CONFIG_THREAD_NAME=y

#CONFIG_THREAD_ANALYZER=y
#CONFIG_THREAD_ANALYZER_AUTO=y
#CONFIG_THREAD_ANALYZER_RUN_UNLOCKED=y
#CONFIG_THREAD_ANALYZER_USE_LOG=y
#CONFIG_THREAD_ANALYZER_AUTO_INTERVAL=30
#CONFIG_THREAD_ANALYZER_AUTO_STACK_SIZE=2048

#CONFIG_INIT_STACKS=y

