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

menuconfig UDS
    bool "UDS"
    select ISO14229
    imply REBOOT

if UDS 

    module = UDS
    module-str = UDS
    source "subsys/logging/Kconfig.template.log_config"

    config UDS_USE_DYNAMIC_REGISTRATION
        bool "Allow registering new event handlers at runtime"
        default n

    menuconfig UDS_UPLOAD_DOWNLOAD_MODULE
        bool "module to allow uploading and downloading of big chunks for data"
        select FLASH
        select FLASH_MAP
        default y

    if UDS_UPLOAD_DOWNLOAD_MODULE

        config UDS_FILE_TRANSFER
            bool "feature of upload download module that allows file transfer"
            depends on FILE_SYSTEM
            default y

        config UDS_UPLOAD_MAX_PAYLOAD_SIZE
            int "Maximum TransferData payload size for upload"
            default 128
            help
                Maximum size of each TransferData payload during upload.
                This value can also be limited by other factors, this is just a user-specified maximum

    endif # UDS_UPLOAD_DOWNLOAD_MODULE

    menuconfig UDS_USE_LINK_CONTROL
        bool "Enable LinkControl service (0x87)"
        default n
        help
          Enable support for the LinkControl service (0x87). This service allows
          switching the CAN bitrate at runtime.
          
    if UDS_USE_LINK_CONTROL

        config UDS_DEFAULT_CAN_BITRATE
            int "Default CAN bitrate"
            default 500000
            help
              Default CAN bitrate for UDS communication. When using the LinkControl
              function and the can interface gets reset to its default bitrate,
              this value is used.
    
    endif # UDS_USE_LINK_CONTROL

    menuconfig UDS_DEFAULT_INSTANCE
        bool "Enable default UDS instance"
        default y

    if UDS_DEFAULT_INSTANCE
        config UDS_DEFAULT_INSTANCE_AUTOSTART_PRIORITY
            int "Default UDS instance autostart priority"
            default APPLICATION_INIT_PRIORITY

        config UDS_DEFAULT_INSTANCE_DISABLE_SWITCH_TO_FIRMWARE_LOADER
            bool "Disable switch to firmware loader"
            default n
            help
                If enabled, switching to the firmware loader via Programming session is not enabled.
                Receivng a switch to programming session request is thus not handled.

        config UDS_DEFAULT_INSTANCE_EXTERNAL_ADDRESS_PROVIDER
            bool "Use external address provider for default UDS instance"
            default n
            help
                If enabled, a function is defined, but not implemented, which can be overwitten to provide
                custom CAN IDs for the default UDS instance.
                If disabled, default CAN IDs from the configuration are used.
        if !UDS_DEFAULT_INSTANCE_EXTERNAL_ADDRESS_PROVIDER
            config UDS_DEFAULT_INSTANCE_SOURCE_ADDRESS
                hex "Default UDS instance Source CAN ID"
                default 0x7E8
                help
                    CAN ID for receiving UDS requests.

            config UDS_DEFAULT_INSTANCE_TARGET_ADDRESS
                hex "Default UDS instance Target CAN ID"
                default 0x7E0
                help
                    CAN ID for sending UDS responses.

            config UDS_DEFAULT_INSTANCE_FUNCTIONAL_SOURCE_ADDRESS
                hex "Default UDS instance Functional Source CAN ID"
                default 0x7DF
                help
                    CAN ID for receiving functional UDS requests.
                    Can be set to 0xFFFFFFFF to disable functional addressing.

            config UDS_DEFAULT_INSTANCE_FUNCTIONAL_TARGET_ADDRESS
                hex "Default UDS instance Functional Target CAN ID"
                default 0xFFFFFFFF
                help
                    CAN ID for sending functional UDS responses.
                    Can be set to 0xFFFFFFFF to disable functional addressing.
        endif # !UDS_DEFAULT_INSTANCE_EXTERNAL_ADDRESS_PROVIDER

    endif # UDS_DEFAULT_INSTANCE
endif # UDS
