# Copyright (C) Frickly Systems GmbH
# Copyright (C) MBition GmbH
#
# SPDX-License-Identifier: Apache-2.0

menuconfig CAN_LOG
    bool "CAN Log Backend"
    depends on CAN
    depends on LOG
    # this currently only works with deferred or immediate log mode
    depends on LOG_MODE_DEFERRED || LOG_MODE_IMMEDIATE
    default n
    help
        Enable CAN logging backend. This backend sends log messages as raw CAN Frames on a specified CAN Identifier.
        It works best in Deferred mode with LOG_PROCESS_THREAD configuration enabled.


if CAN_LOG
    module = CAN_LOG
    module-str = CAN Logger
    source "subsys/logging/Kconfig.template.log_config"


    config CAN_LOG_ADDRESS_PROVIDER_EXTERNAL
        bool "External CAN Log ID Provider"
        default n
        help
          Use an external address provider to get the CAN ID for logging messages.
          This requires an external module that implements the address provider interface.

    if !CAN_LOG_ADDRESS_PROVIDER_EXTERNAL
        config CAN_LOG_ID
            hex
            prompt "CAN Log ID"
            default 0x100
            help
              CAN identifier used for logging messages.
    endif # CAN_LOG_ADDRESS_PROVIDER_EXTERNAL

    config CAN_LOG_SEND_TIMEOUT_MS
        int "CAN Log Send Timeout (ms)"
        default 10
        help
          Timeout in milliseconds for sending CAN log messages.
          Used as a timeout for waiting until a queue slot is free
          for sending and for waiting until the message is sent itself.

    config CAN_LOG_AUTOSTART_BUS
        bool "Auto-start CAN bus for logging"
        default n
        help
          If enabled, the CAN bus used for logging will be automatically
          started during CAN log backend initialization.

    if CAN_LOG_AUTOSTART_BUS
        config CAN_LOG_AUTOSTART_BUS_PRIORITY
            int
            prompt "CAN Log Auto-start Bus Priority"
            default CAN_INIT_PRIORITY
            help
              Priority used when starting the CAN bus for logging.
    endif # CAN_LOG_AUTOSTART_BUS
endif
