name=K230 Arduino
version=0.0.1

tools.riscv-musl-gcc.path={runtime.tools.riscv-musl-gcc.path}
compiler.path={tools.riscv-musl-gcc.path}/bin/
compiler.prefix=riscv64-unknown-linux-musl-

compiler.exe.suffix=
compiler.exe.suffix.windows=.exe

compiler.c.cmd={compiler.prefix}gcc{compiler.exe.suffix}
compiler.cpp.cmd={compiler.prefix}g++{compiler.exe.suffix}
compiler.S.cmd={compiler.prefix}gcc{compiler.exe.suffix}
compiler.c.elf.cmd={compiler.prefix}g++{compiler.exe.suffix}
compiler.ar.cmd={compiler.prefix}ar{compiler.exe.suffix}
compiler.size.cmd={compiler.prefix}size{compiler.exe.suffix}
compiler.objcopy.cmd={compiler.prefix}objcopy{compiler.exe.suffix}
compiler.strip.cmd={compiler.prefix}strip{compiler.exe.suffix}

# Compile Flags
compiler.cores.path={runtime.platform.path}/cores/k230
compiler.sdk.path={compiler.cores.path}/sdk

compiler.includes.flags_0="-I{compiler.sdk.path}/include/" "-I{compiler.sdk.path}/include/mpp" "-I{compiler.sdk.path}/include/mpp/api/" "-I{compiler.sdk.path}/include/mpp/comm/" "-I{compiler.sdk.path}/include/mpp/ioctl/" "-I{compiler.sdk.path}/include/rtsmart_hal" -include "autoconf.h"
compiler.includes.flags_1="-I{compiler.sdk.path}/3rd_party/include/" "-I{compiler.sdk.path}/opencv/include/opencv4" "-I{compiler.sdk.path}/openblas/include/"
compiler.includes.flags_2="-I{compiler.sdk.path}/nncase/" "-I{compiler.sdk.path}/nncase/nncase/include/" "-I{compiler.sdk.path}/nncase/rvvlib/include/" "-I{compiler.sdk.path}/include/nn/" "-I{compiler.sdk.path}/include/ai_demo/"
compiler.includes.flags_3=-DARDUINO_ARCH_RISCV -DARDUINO={runtime.ide.version} -DARDUINO_ARCH_{build.arch} -DARDUINO_{build.board}  -DARDUINO_BOARD="{build.board}" -DARDUINO_VARIANT="{build.variant}" -DK230_DEBUG={build.cores_debug}

compiler.includes.flags={compiler.includes.flags_3} {compiler.includes.flags_0} {compiler.includes.flags_1} {compiler.includes.flags_2}

compiler.c_cpp.flags=-Os -fopenmp -march=rv64imafdcv -mabi=lp64d -mcmodel=medany

compiler.c.flags={compiler.includes.flags} {compiler.c_cpp.flags} -std=gnu99
compiler.cpp.flags={compiler.includes.flags} {compiler.c_cpp.flags} -std=gnu++17
compiler.S.flags={compiler.includes.flags} {compiler.c_cpp.flags} -x assembler-with-cpp
compiler.ar.flags=cr

compiler.c_cpp.elf.flags=-T {compiler.sdk.path}/link.lds --static -Wl,--gc-sections -Wl,--no-relax

compiler.c_cpp.elf.libs_0=-Wl,--start-group -lmpp -lrtsmart_hal -lfreetype -lrvv -lfunctional_k230 -lNncase.Runtime.Native -lnncase.rt_modules.k230 -lopenblas -Wl,--end-group "-L{compiler.sdk.path}/lib/" "-L{compiler.sdk.path}/3rd_party/lib/" "-L{compiler.sdk.path}/nncase/nncase/lib" "-L{compiler.sdk.path}/nncase/rvvlib" "-L{compiler.sdk.path}/openblas/lib"
# opencv
compiler.c_cpp.elf.libs_1=-Wl,--start-group -lstdc++ -lopencv_core -lopencv_imgcodecs -lopencv_imgproc -lopencv_highgui -lopencv_videoio -lopencv_calib3d -lopencv_features2d -lopencv_flann -lopencv_dnn -lopencv_ml -lopencv_objdetect -lopencv_gapi -lopencv_photo -lopencv_video -lopencv_stitching -lzlib -llibjpeg-turbo -llibopenjp2 -llibpng -llibtiff -llibwebp -lcsi_cv -latomic -Wl,--end-group "-L{compiler.sdk.path}/opencv/lib" "-L{compiler.sdk.path}/opencv/lib/3rdparty"

compiler.c_cpp.elf.libs={compiler.c_cpp.elf.libs_0} {compiler.c_cpp.elf.libs_1}

# Arduino Compile Warning Levels
compiler.warning_flags=-w
compiler.warning_flags.none=-w
compiler.warning_flags.default=
compiler.warning_flags.more=-Wall -Werror=all
compiler.warning_flags.all=-Wall -Werror=all -Wextra

# These can be overridden in platform.local.txt
compiler.c.extra_flags=
compiler.cpp.extra_flags=
compiler.S.extra_flags=
compiler.ar.extra_flags=

compiler.libraries.ldflags=
compiler.c_cpp.elf.extra_flags=

# This can be overriden in boards.txt

## Compile c files
recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {includes} {compiler.c.flags} {compiler.c.extra_flags} -c "{source_file}" -o "{object_file}"

## Compile c++ files
recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {includes} {compiler.cpp.flags} {compiler.cpp.extra_flags} -c "{source_file}" -o "{object_file}"

## Compile S files
recipe.S.o.pattern="{compiler.path}{compiler.c.cmd}" {includes} {compiler.S.flags} {compiler.S.extra_flags} -c "{source_file}" -o "{object_file}"

## Create archives
recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}"

## Combine gc-sections, archives, and objects
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" -o {build.path}/{build.project_name}.elf {object_files} {compiler.c_cpp.elf.flags} {compiler.c_cpp.elf.extra_flags} "{archive_file_path}" {compiler.c_cpp.elf.libs}

recipe.objcopy.bin.pattern="{compiler.path}{compiler.strip.cmd}" --strip-all "{build.path}/{build.project_name}.elf"

## Save bin
recipe.output.tmp_file={build.project_name}.elf
recipe.output.save_file={build.project_name}.{build.variant}.elf

## Compute size
recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -B "{build.path}/{build.project_name}.elf"
recipe.size.regex=\s*[0-9]+\s+[0-9]+\s+[0-9]+\s+([0-9]+).*
recipe.size.regex.data=\s*[0-9]+\s+[0-9]+\s+[0-9]+\s+([0-9]+).*

## ------------------
## Upload/Debug tools
## ------------------

## --------------
## K230_Flash_Cli
## --------------

tools.k230_flash.path={runtime.platform.path}/tools/k230_flash

## ------------------------------------------------------------------------------------
## `upload` a sketch to the target board (using a bootloader preinstalled on the board)
## ------------------------------------------------------------------------------------
tools.k230_flash.upload.protocol=kburn
tools.k230_flash.upload.params.verbose=
tools.k230_flash.upload.params.quiet=
tools.k230_flash.upload.pattern_args="{build.path}/{build.project_name}.elf" -p {runtime.platform.path} -v {build.variant} -m {build.medium}
tools.k230_flash.upload.pattern=python3 "{path}/k230_arduino_flash.py" {upload.pattern_args}
tools.k230_flash.upload.pattern.windows="{path}/windows/k230_arduino_flash.exe" {upload.pattern_args}

## -------------------------------------------------------------------
## `program` a sketch to the target board using an external programmer
## -------------------------------------------------------------------
tools.k230_flash.program.protocol=kburn
tools.k230_flash.program.params.verbose=
tools.k230_flash.program.params.quiet=
tools.k230_flash.program.pattern_args="{build.path}/{build.project_name}.elf" -p {runtime.platform.path} -v {build.variant} -m {build.medium}
tools.k230_flash.program.pattern=python "{path}/k230_arduino_flash.py" {program.pattern_args}
tools.k230_flash.program.pattern.windows="{path}/windows/k230_arduino_flash.exe" {program.pattern_args}

## --------------------------------------------------------------------
## `erase` the target board's flash memory using an external programmer
## --------------------------------------------------------------------
tools.k230_flash.erase.protocol=
tools.k230_flash.erase.params.verbose=
tools.k230_flash.erase.params.quiet=
tools.k230_flash.erase.pattern_args=
tools.k230_flash.erase.pattern=

## ----------------------------------------------------------------------
## burn a `bootloader` into the target board using an external programmer
## ----------------------------------------------------------------------
tools.k230_flash.bootloader.protocol=
tools.k230_flash.bootloader.params.verbose=
tools.k230_flash.bootloader.params.quiet=
tools.k230_flash.bootloader.pattern_args=
tools.k230_flash.bootloader.pattern=
