<!DOCTYPE module SYSTEM "module.dtd">

<module name="loggers">
  <doc>
    <description>
    Directly log values to memory for flash chips.
    </description>
    <configure name="DM_LOG_UART" value="UART1|UART2|UART3|UART4|UART5|UART6" description="Port to read back the memory"/>
    <configure name="DM_LOG_SPI_DEV" value="SPI1|SPI2|SPI3|SPI4|SPI5|SPI6" description="SPI bus which the memory is connected to"/>
    <configure name="DM_LOG_SPI_SLAVE" value="SPI_SLAVE1|SPI_SLAVE2|SPI_SLAVE3|SPI_SLAVE4|SPI_SLAVE5|SPI_SLAVE6" description="SPI slave which the memory is connected to"/>
  </doc>
  <settings>
    <dl_settings name="direct_memory_logger">
      <dl_settings name="direct_memory">
        <dl_setting module="loggers/direct_memory_logger" var="dml.status" shortname="Status" min="0" step="1" max="2" values="INIT|IDLE|ERASE|START|RUNNING|STOP|READ|READING" handler="set"/>
        <dl_setting module="loggers/direct_memory_logger" var="dml.sst.flash_addr" shortname="Flash ADDR" min="0" step="1" max="16777215"/>
        <dl_setting module="loggers/direct_memory_logger" var="dml.write_addr" shortname="Write ADDR" min="0" step="1" max="16777215"/>
      </dl_settings>
    </dl_settings>
  </settings>

  <header>
    <file name="direct_memory_logger.h"/>
  </header>

  <init fun="direct_memory_logger_init()"/>
  <periodic fun="direct_memory_logger_periodic()" autorun="TRUE"/>

  <makefile target="ap">
    <raw>
      DM_LOG_UART ?= uart1
      DM_LOG_UART_LOWER=$(shell echo $(DM_LOG_UART) | tr A-Z a-z)
      DM_LOG_UART_UPPER=$(shell echo $(DM_LOG_UART) | tr a-z A-Z)

      DM_LOG_SPI_DEV ?= spi2
      DM_LOG_SPI_DEV_LOWER=$(shell echo $(DM_LOG_SPI_DEV) | tr A-Z a-z)
      DM_LOG_SPI_DEV_UPPER=$(shell echo $(DM_LOG_SPI_DEV) | tr a-z A-Z)

      DM_LOG_SPI_SLAVE_IDX ?= spi_slave1
      DM_LOG_SPI_SLAVE_IDX_LOWER=$(shell echo $(DM_LOG_SPI_SLAVE_IDX) | tr A-Z a-z)
      DM_LOG_SPI_SLAVE_IDX_UPPER=$(shell echo $(DM_LOG_SPI_SLAVE_IDX) | tr a-z A-Z)

      include $(CFG_SHARED)/spi_master.makefile
    </raw>

    <define name="USE_$(DM_LOG_SPI_DEV_UPPER)" value="1" />
    <define name="USE_$(DM_LOG_SPI_SLAVE_IDX_UPPER)" value="1" />
    <define name="DM_LOG_SPI_DEV" value="$(DM_LOG_SPI_DEV_LOWER)" />
    <define name="DM_LOG_SPI_SLAVE_IDX" value="$(DM_LOG_SPI_SLAVE_IDX_UPPER)" />

    <define name="DM_LOG_UART" value="$(DM_LOG_UART_UPPER)"/>
    <define name="USE_$(DM_LOG_UART_UPPER)"/>
    <define name="$(DM_LOG_UART_UPPER)_BAUD" value="B230400"/>

    <file name="direct_memory_logger.c"/>
    <file name="sst25vfxxxx.c" dir="peripherals"/>
  </makefile>
</module>
