diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0d20b64 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.pyc diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..33f662e --- /dev/null +++ b/.travis.yml @@ -0,0 +1,25 @@ +language: python +python: + - "2.7" + - "3.6" + +env: + - PLATFORMIO_PROJECT_DIR=examples/shakti-sdk_gpio-keypad + - PLATFORMIO_PROJECT_DIR=examples/shakti-sdk_i2c-lm75 + - PLATFORMIO_PROJECT_DIR=examples/shakti-sdk_uart-hello + +install: + - pip install -U https://github.com/platformio/platformio/archive/develop.zip + - platformio platform install file://. + +script: + - platformio run -d $PLATFORMIO_PROJECT_DIR + +notifications: + email: false + + slack: + rooms: + secure: UgmaiBeFcBbN/gr5YI+ZKEd2s7hiudTa7EBTDtHx1nL8BcgJv32cUGbgXHJoCNILqBCkGhdm+KZLOgUHpEnqjfmmKHz28MUvghlBfVc4QiBdVChlKQa4CSfa2OgQrL5fO5X/ETGSmU+kvH7gPvvwdvK3cmI+KzZIoPCymWxPxdLjkQ29smJdGi7+PGL8z3ucsTmec2eTDLogymjQdWeqXgvqzV3mg9MmQ5KBGwEMTrArJl56kJnGON3SyhXdDOW52aicDX+79AwWtII87Jue17O3b80qNQeupvhsmqz1/rgME60UrpQslfrL/Zhq77s8WKj/5ticfTBWVBZmJoP3AGPQVFXiVAo8YD2A9/kHVyRVb2yCVVnouc08Cj8auZR8JMyJzD9B/CE27jLu5g4GdFtv0a3O7qLZ1sEzuTuWI1R0KdUt7ZtCM7B5i7+T2F36mdHattzSM4GrJfucltE63GkYyzyqsRV7fjiPyf4Vqv89PJGnu8kIAOH3HC0PXT722b3xR3qodnQaF1EAn2v4H4fWeNcpyXtgHI42HaFqfauMFc+JZRZ1PM8c/yFIbvJg3ndQcXCAzKRPFnQeHjjWjNYzHK/6CQes3ovQmgmdkbd4TnhJ5IvvG0tVAIcdeucp4RamOe0m8h8JDfBqoqykPrfiTGoedkTv6LULXwhRWHA= + on_failure: always + on_success: change diff --git a/README.md b/README.md new file mode 100644 index 0000000..89f026d --- /dev/null +++ b/README.md @@ -0,0 +1,35 @@ +# Shakti: development platform for [PlatformIO](http://platformio.org) +[![Build Status](https://travis-ci.org/platformio/platform-shakti.svg?branch=develop)](https://travis-ci.org/platformio/platform-shakti) +[![Build status](https://ci.appveyor.com/api/projects/status/pm59mq539ttp51hd/branch/develop?svg=true)](https://ci.appveyor.com/project/ivankravets/platform-shakti/branch/develop) + +Shakti is an open-source initiative by the RISE group at IIT-Madras, which is not only building open source, production grade processors, but also associated components like interconnect fabrics, verification tools, storage controllers, peripheral IPs and SOC tools. + +* [Home](http://platformio.org/platforms/shakti) (home page in PlatformIO Platform Registry) +* [Documentation](http://docs.platformio.org/page/platforms/shakti.html) (advanced usage, packages, boards, frameworks, etc.) + +# Usage + +1. [Install PlatformIO](http://platformio.org) +2. Create PlatformIO project and configure a platform option in [platformio.ini](http://docs.platformio.org/page/projectconf.html) file: + +## Stable version + +```ini +[env:stable] +platform = shakti +board = ... +... +``` + +## Development version + +```ini +[env:development] +platform = https://github.com/platformio/platform-shakti.git +board = ... +... +``` + +# Configuration + +Please navigate to [documentation](http://docs.platformio.org/page/platforms/shakti.html). diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..ad6b010 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,24 @@ +build: off +environment: + + matrix: + - PLATFORMIO_PROJECT_DIR: "examples/shakti-sdk_gpio-keypad" + - PLATFORMIO_PROJECT_DIR: "examples/shakti-sdk_i2c-lm75" + - PLATFORMIO_PROJECT_DIR: "examples/shakti-sdk_uart-hello" + +install: +- cmd: git submodule update --init --recursive +- cmd: SET PATH=%PATH%;C:\Python27\Scripts +- cmd: pip install -U https://github.com/platformio/platformio/archive/develop.zip +- cmd: platformio platform install file://. + +test_script: +- cmd: platformio run -d %PLATFORMIO_PROJECT_DIR% + +notifications: + - provider: Slack + incoming_webhook: + secure: E9H0SU0Ju7WLDvgxsV8cs3J62T3nTTX7QkEjsczN0Sto/c9hWkVfhc5gGWUkxhlD975cokHByKGJIdwYwCewqOI+7BrcT8U+nlga4Uau7J8= + on_build_success: false + on_build_failure: true + on_build_status_changed: true diff --git a/boards/artix7_100t.json b/boards/artix7_100t.json new file mode 100644 index 0000000..b132e9d --- /dev/null +++ b/boards/artix7_100t.json @@ -0,0 +1,47 @@ +{ + "build": { + "extra_flags": "-D ARTIX7_100T", + "f_cpu": "1500000000L", + "hwids": [ + [ + "0x0403", + "0x6010" + ] + ], + "ldscript": "link.ld", + "mabi": "lp64", + "march": "rv64imac", + "mcmodel": "medany", + "mcu": "e51" + }, + "debug": { + "init_cmds": [ + "define pio_reset_halt_target", + " monitor halt", + "end", + "define pio_reset_target", + " pio_reset_halt_target", + "end", + "target extended-remote $DEBUG_PORT", + "$INIT_BREAK", + "$LOAD_CMDS", + "monitor init", + "pio_reset_halt_target" + ] + }, + "frameworks": [ + "shakti-sdk" + ], + "name": "Arty A7-100: Artix-7 FPGA Development Board", + "upload": { + "maximum_ram_size": 268435456, + "maximum_size": 16777216, + "protocol": "jlink", + "protocols": [ + "ftdi", + "jlink" + ] + }, + "url": "https://www.xilinx.com/products/boards-and-kits/1-w51quh.html", + "vendor": "Xilinx" +} diff --git a/boards/artix7_35t.json b/boards/artix7_35t.json new file mode 100644 index 0000000..588dc5e --- /dev/null +++ b/boards/artix7_35t.json @@ -0,0 +1,52 @@ +{ + "build": { + "extra_flags": "-D ARTIX7_35T", + "f_cpu": "320000000L", + "hwids": [ + [ + "0x0403", + "0x6010" + ] + ], + "ldscript": "link.ld", + "mabi": "ilp32", + "march": "rv32imac", + "mcmodel": "medany", + "mcu": "e31" + }, + "debug": { + "jlink_device": "FE310", + "init_cmds": [ + "define pio_reset_halt_target", + " monitor halt", + "end", + "define pio_reset_target", + " pio_reset_halt_target", + "end", + "target extended-remote $DEBUG_PORT", + "$INIT_BREAK", + "$LOAD_CMDS", + "monitor init", + "pio_reset_halt_target" + ], + "svd_path": "FE310.svd", + "onboard_tools": [ + "ftdi" + ] + }, + "frameworks": [ + "shakti-sdk" + ], + "name": "Artix-7 35T Arty FPGA Evaluation Kit", + "upload": { + "maximum_ram_size": 268435456, + "maximum_size": 16777216, + "protocol": "ftdi", + "protocols": [ + "ftdi", + "jlink" + ] + }, + "url": "https://www.xilinx.com/products/boards-and-kits/arty.html", + "vendor": "Xilinx" +} diff --git a/builder/frameworks/_bare.py b/builder/frameworks/_bare.py new file mode 100644 index 0000000..9ff84c9 --- /dev/null +++ b/builder/frameworks/_bare.py @@ -0,0 +1,44 @@ +# Copyright 2014-present PlatformIO +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# +# Default flags for bare-metal programming (without any framework layers) +# + +from SCons.Script import Import + +Import("env") + +board_config = env.BoardConfig() + +env.Append( + CCFLAGS=[ + "-Wall", # show warnings + "-march=%s" % board_config.get("build.march"), + "-mabi=%s" % board_config.get("build.mabi"), + "-mcmodel=%s" % board_config.get("build.mcmodel") + ], + + LINKFLAGS=[ + "-nostartfiles", + "-march=%s" % board_config.get("build.march"), + "-mabi=%s" % board_config.get("build.mabi"), + "-mcmodel=%s" % board_config.get("build.mcmodel") + ], + + LIBS=["c", "m", "gcc"] +) + +# copy CCFLAGS to ASFLAGS (-x assembler-with-cpp mode) +env.Append(ASFLAGS=env.get("CCFLAGS", [])[:]) diff --git a/builder/frameworks/shakti-sdk.py b/builder/frameworks/shakti-sdk.py new file mode 100644 index 0000000..59a21e0 --- /dev/null +++ b/builder/frameworks/shakti-sdk.py @@ -0,0 +1,108 @@ +# Copyright 2019-present PlatformIO +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +Shakti SDK + +Open Source Software for Developing on the Shakti Platform + +https://gitlab.com/shaktiproject/software/shakti-sdk +""" + +from shutil import copyfile +from os import makedirs, listdir +from os.path import isdir, join + +from SCons.Script import DefaultEnvironment + +env = DefaultEnvironment() + +FRAMEWORK_DIR = env.PioPlatform().get_package_dir("framework-shakti-sdk") +assert FRAMEWORK_DIR and isdir(FRAMEWORK_DIR) + + +def is_valid_target(target): + target_dir = join(FRAMEWORK_DIR, "bsp", "third_party", target) + return isdir(target_dir) + + +env.SConscript("_bare.py", exports="env") + +target = env.subst("$BOARD") + +env.Append( + ASFLAGS=[ + ("-D__ASSEMBLY__=1") + ], + + CFLAGS=[ + "-std=gnu99" + ], + + CCFLAGS=[ + "-fno-common", + "-fno-builtin-printf" + ], + + CPPPATH=[ + join(FRAMEWORK_DIR, "bsp", "include"), + join(FRAMEWORK_DIR, "bsp", "third_party", target) + ], + + LIBPATH=[ + join(FRAMEWORK_DIR, "bsp", "third_party", target) + ] +) + +if not is_valid_target(target): + print ("Could not find BSP package for %s" % target) + env.Exit(1) + +# +# Target: Build core BSP libraries +# + +unsupported_drivers = ("plic", "timer") + +libs = [] + +for driver in listdir(join(FRAMEWORK_DIR, "bsp", "drivers")): + if driver in unsupported_drivers: + continue + + libs.append( + env.BuildLibrary( + join("$BUILD_DIR", "bsp", "drivers", driver), + join(FRAMEWORK_DIR, "bsp", "drivers", driver)) + ) + +libs.append( + env.BuildLibrary( + join("$BUILD_DIR", "bsp", "libwrap"), + join(FRAMEWORK_DIR, "bsp", "libwrap")) +) + +libs.append( + env.BuildLibrary( + join("$BUILD_DIR", "bsp", "include"), + join(FRAMEWORK_DIR, "bsp", "include")) +) + +libs.append( + env.BuildLibrary( + join("$BUILD_DIR", "bsp", "third_party", target), + join(FRAMEWORK_DIR, "bsp", "third_party", target)) +) + +env.Prepend(LIBS=libs) diff --git a/builder/main.py b/builder/main.py new file mode 100644 index 0000000..d3483d5 --- /dev/null +++ b/builder/main.py @@ -0,0 +1,173 @@ +# Copyright 2014-present PlatformIO +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +from platform import system +from os import makedirs +from os.path import isdir, join + +from SCons.Script import (ARGUMENTS, COMMAND_LINE_TARGETS, AlwaysBuild, + Builder, Default, DefaultEnvironment) + + +env = DefaultEnvironment() +platform = env.PioPlatform() +board_config = env.BoardConfig() + +env.Replace( + AR="riscv64-unknown-elf-gcc-ar", + AS="riscv64-unknown-elf-as", + CC="riscv64-unknown-elf-gcc", + GDB="riscv64-unknown-elf-gdb", + CXX="riscv64-unknown-elf-g++", + OBJCOPY="riscv64-unknown-elf-objcopy", + RANLIB="riscv64-unknown-elf-gcc-ranlib", + SIZETOOL="riscv64-unknown-elf-size", + + ARFLAGS=["rc"], + + SIZEPRINTCMD='$SIZETOOL -d $SOURCES', + + PROGSUFFIX=".elf" +) + +# Allow user to override via pre:script +if env.get("PROGNAME", "program") == "program": + env.Replace(PROGNAME="firmware") + +env.Append( + BUILDERS=dict( + ElfToHex=Builder( + action=env.VerboseAction(" ".join([ + "$OBJCOPY", + "-O", + "ihex", + "$SOURCES", + "$TARGET" + ]), "Building $TARGET"), + suffix=".hex" + ), + ElfToBin=Builder( + action=env.VerboseAction(" ".join([ + "$OBJCOPY", + "-O", + "binary", + "$SOURCES", + "$TARGET" + ]), "Building $TARGET"), + suffix=".bin" + ) + ) +) + +if not env.get("PIOFRAMEWORK"): + env.SConscript("frameworks/_bare.py", exports="env") + +# +# Target: Build executable and linkable firmware +# + +target_elf = None +if "nobuild" in COMMAND_LINE_TARGETS: + target_elf = join("$BUILD_DIR", "${PROGNAME}.elf") +else: + target_elf = env.BuildProgram() + target_hex = env.ElfToHex(join("$BUILD_DIR", "${PROGNAME}"), target_elf) + +AlwaysBuild(env.Alias("nobuild", target_elf)) +target_buildprog = env.Alias("buildprog", target_elf, target_elf) + +# +# Target: Print binary size +# + +target_size = env.Alias( + "size", target_elf, + env.VerboseAction("$SIZEPRINTCMD", "Calculating size $SOURCE")) +AlwaysBuild(target_size) + +# +# Target: Upload by default .bin file +# + +upload_protocol = env.subst("$UPLOAD_PROTOCOL") +debug_tools = board_config.get("debug.tools", {}) +upload_actions = [] +upload_target = target_elf + +if upload_protocol.startswith("jlink"): + + def _jlink_cmd_script(env, source): + build_dir = env.subst("$BUILD_DIR") + if not isdir(build_dir): + makedirs(build_dir) + script_path = join(build_dir, "upload.jlink") + commands = [ + "h", + "loadfile %s" % source, + "r", + "q" + ] + with open(script_path, "w") as fp: + fp.write("\n".join(commands)) + return script_path + + env.Replace( + __jlink_cmd_script=_jlink_cmd_script, + UPLOADER="JLink.exe" if system() == "Windows" else "JLinkExe", + UPLOADERFLAGS=[ + "-device", env.BoardConfig().get("debug", {}).get("jlink_device"), + "-speed", "1000", + "-if", "JTAG", + "-jtagconf", "-1,-1", + "-autoconnect", "1" + ], + UPLOADCMD='$UPLOADER $UPLOADERFLAGS -CommanderScript "${__jlink_cmd_script(__env__, SOURCE)}"' + ) + upload_target = target_hex + upload_actions = [env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE")] + +elif upload_protocol in debug_tools: + openocd_args = [ + "-c", + "debug_level %d" % (2 if int(ARGUMENTS.get("PIOVERBOSE", 0)) else 1), + "-s", platform.get_package_dir("tool-openocd-riscv") or "" + ] + openocd_args.extend( + debug_tools.get(upload_protocol).get("server").get("arguments", [])) + openocd_args.extend([ + "-c", "program {$SOURCE} %s verify; shutdown;" % + board_config.get("upload").get("flash_start", "") + ]) + env.Replace( + UPLOADER="openocd", + UPLOADERFLAGS=openocd_args, + UPLOADCMD="$UPLOADER $UPLOADERFLAGS") + upload_actions = [env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE")] + +# custom upload tool +elif upload_protocol == "custom": + upload_actions = [env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE")] + +else: + sys.stderr.write("Warning! Unknown upload protocol %s\n" % upload_protocol) + +AlwaysBuild(env.Alias("upload", upload_target, upload_actions)) + + +# +# Setup default targets +# + +Default([target_buildprog, target_size]) diff --git a/examples/shakti-sdk_gpio-keypad/.gitignore b/examples/shakti-sdk_gpio-keypad/.gitignore new file mode 100644 index 0000000..6c69f4c --- /dev/null +++ b/examples/shakti-sdk_gpio-keypad/.gitignore @@ -0,0 +1,2 @@ +.pioenvs +.piolibdeps diff --git a/examples/shakti-sdk_gpio-keypad/.pio/build/.sconsign.dblite b/examples/shakti-sdk_gpio-keypad/.pio/build/.sconsign.dblite new file mode 100644 index 0000000..e5778f1 Binary files /dev/null and b/examples/shakti-sdk_gpio-keypad/.pio/build/.sconsign.dblite differ diff --git a/examples/shakti-sdk_gpio-keypad/.pio/build/artix7_35t/bsp/include/crt.o b/examples/shakti-sdk_gpio-keypad/.pio/build/artix7_35t/bsp/include/crt.o new file mode 100644 index 0000000..4637e3b Binary files /dev/null and b/examples/shakti-sdk_gpio-keypad/.pio/build/artix7_35t/bsp/include/crt.o differ diff --git a/examples/shakti-sdk_gpio-keypad/.pio/build/artix7_35t/bsp/libinclude.a b/examples/shakti-sdk_gpio-keypad/.pio/build/artix7_35t/bsp/libinclude.a new file mode 100644 index 0000000..aa2b9e8 Binary files /dev/null and b/examples/shakti-sdk_gpio-keypad/.pio/build/artix7_35t/bsp/libinclude.a differ diff --git a/examples/shakti-sdk_gpio-keypad/.pio/build/artix7_35t/bsp/libwrap.a b/examples/shakti-sdk_gpio-keypad/.pio/build/artix7_35t/bsp/libwrap.a new file mode 100644 index 0000000..605a62f Binary files /dev/null and b/examples/shakti-sdk_gpio-keypad/.pio/build/artix7_35t/bsp/libwrap.a differ diff --git a/examples/shakti-sdk_gpio-keypad/.pio/build/artix7_35t/bsp/libwrap/syscalls.o b/examples/shakti-sdk_gpio-keypad/.pio/build/artix7_35t/bsp/libwrap/syscalls.o new file mode 100644 index 0000000..bd21bea Binary files /dev/null and b/examples/shakti-sdk_gpio-keypad/.pio/build/artix7_35t/bsp/libwrap/syscalls.o differ diff --git a/examples/shakti-sdk_gpio-keypad/.pio/build/artix7_35t/bsp/libwrap/util.o b/examples/shakti-sdk_gpio-keypad/.pio/build/artix7_35t/bsp/libwrap/util.o new file mode 100644 index 0000000..f3d0b3b Binary files /dev/null and b/examples/shakti-sdk_gpio-keypad/.pio/build/artix7_35t/bsp/libwrap/util.o differ diff --git a/examples/shakti-sdk_gpio-keypad/.pio/build/artix7_35t/bsp/third_party/artix7_35t/uart.o b/examples/shakti-sdk_gpio-keypad/.pio/build/artix7_35t/bsp/third_party/artix7_35t/uart.o new file mode 100644 index 0000000..4da5a5c Binary files /dev/null and b/examples/shakti-sdk_gpio-keypad/.pio/build/artix7_35t/bsp/third_party/artix7_35t/uart.o differ diff --git a/examples/shakti-sdk_gpio-keypad/.pio/build/artix7_35t/bsp/third_party/libartix7_35t.a b/examples/shakti-sdk_gpio-keypad/.pio/build/artix7_35t/bsp/third_party/libartix7_35t.a new file mode 100644 index 0000000..d90f3b3 Binary files /dev/null and b/examples/shakti-sdk_gpio-keypad/.pio/build/artix7_35t/bsp/third_party/libartix7_35t.a differ diff --git a/examples/shakti-sdk_gpio-keypad/.pio/build/artix7_35t/drivers/clic/clic_driver.o b/examples/shakti-sdk_gpio-keypad/.pio/build/artix7_35t/drivers/clic/clic_driver.o new file mode 100644 index 0000000..f427205 Binary files /dev/null and b/examples/shakti-sdk_gpio-keypad/.pio/build/artix7_35t/drivers/clic/clic_driver.o differ diff --git a/examples/shakti-sdk_gpio-keypad/.pio/build/artix7_35t/drivers/i2c/i2c_driver.o b/examples/shakti-sdk_gpio-keypad/.pio/build/artix7_35t/drivers/i2c/i2c_driver.o new file mode 100644 index 0000000..7e0c244 Binary files /dev/null and b/examples/shakti-sdk_gpio-keypad/.pio/build/artix7_35t/drivers/i2c/i2c_driver.o differ diff --git a/examples/shakti-sdk_gpio-keypad/.pio/build/artix7_35t/drivers/libclic.a b/examples/shakti-sdk_gpio-keypad/.pio/build/artix7_35t/drivers/libclic.a new file mode 100644 index 0000000..f3cfc0a Binary files /dev/null and b/examples/shakti-sdk_gpio-keypad/.pio/build/artix7_35t/drivers/libclic.a differ diff --git a/examples/shakti-sdk_gpio-keypad/.pio/build/artix7_35t/drivers/libi2c.a b/examples/shakti-sdk_gpio-keypad/.pio/build/artix7_35t/drivers/libi2c.a new file mode 100644 index 0000000..efaf386 Binary files /dev/null and b/examples/shakti-sdk_gpio-keypad/.pio/build/artix7_35t/drivers/libi2c.a differ diff --git a/examples/shakti-sdk_gpio-keypad/.pio/build/artix7_35t/drivers/libreadme.md b/examples/shakti-sdk_gpio-keypad/.pio/build/artix7_35t/drivers/libreadme.md new file mode 100644 index 0000000..8b277f0 --- /dev/null +++ b/examples/shakti-sdk_gpio-keypad/.pio/build/artix7_35t/drivers/libreadme.md @@ -0,0 +1 @@ +! diff --git a/examples/shakti-sdk_gpio-keypad/.pio/build/artix7_35t/firmware.elf b/examples/shakti-sdk_gpio-keypad/.pio/build/artix7_35t/firmware.elf new file mode 100644 index 0000000..cd265a2 Binary files /dev/null and b/examples/shakti-sdk_gpio-keypad/.pio/build/artix7_35t/firmware.elf differ diff --git a/examples/shakti-sdk_gpio-keypad/.pio/build/artix7_35t/src/keypad.o b/examples/shakti-sdk_gpio-keypad/.pio/build/artix7_35t/src/keypad.o new file mode 100644 index 0000000..fc41e6e Binary files /dev/null and b/examples/shakti-sdk_gpio-keypad/.pio/build/artix7_35t/src/keypad.o differ diff --git a/examples/shakti-sdk_gpio-keypad/.pio/build/structure.hash b/examples/shakti-sdk_gpio-keypad/.pio/build/structure.hash new file mode 100644 index 0000000..7ff6a50 --- /dev/null +++ b/examples/shakti-sdk_gpio-keypad/.pio/build/structure.hash @@ -0,0 +1 @@ +b00b31c89f669cfb29bc3c95427833f4612041a3 \ No newline at end of file diff --git a/examples/shakti-sdk_gpio-keypad/.travis.yml b/examples/shakti-sdk_gpio-keypad/.travis.yml new file mode 100644 index 0000000..7c486f1 --- /dev/null +++ b/examples/shakti-sdk_gpio-keypad/.travis.yml @@ -0,0 +1,67 @@ +# Continuous Integration (CI) is the practice, in software +# engineering, of merging all developer working copies with a shared mainline +# several times a day < https://docs.platformio.org/page/ci/index.html > +# +# Documentation: +# +# * Travis CI Embedded Builds with PlatformIO +# < https://docs.travis-ci.com/user/integration/platformio/ > +# +# * PlatformIO integration with Travis CI +# < https://docs.platformio.org/page/ci/travis.html > +# +# * User Guide for `platformio ci` command +# < https://docs.platformio.org/page/userguide/cmd_ci.html > +# +# +# Please choose one of the following templates (proposed below) and uncomment +# it (remove "# " before each line) or use own configuration according to the +# Travis CI documentation (see above). +# + + +# +# Template #1: General project. Test it using existing `platformio.ini`. +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# install: +# - pip install -U platformio +# - platformio update +# +# script: +# - platformio run + + +# +# Template #2: The project is intended to be used as a library with examples. +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# env: +# - PLATFORMIO_CI_SRC=path/to/test/file.c +# - PLATFORMIO_CI_SRC=examples/file.ino +# - PLATFORMIO_CI_SRC=path/to/test/directory +# +# install: +# - pip install -U platformio +# - platformio update +# +# script: +# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/examples/shakti-sdk_gpio-keypad/.vscode/.BROWSE.C_CPP.DB b/examples/shakti-sdk_gpio-keypad/.vscode/.BROWSE.C_CPP.DB new file mode 100644 index 0000000..e38bc92 Binary files /dev/null and b/examples/shakti-sdk_gpio-keypad/.vscode/.BROWSE.C_CPP.DB differ diff --git a/examples/shakti-sdk_gpio-keypad/.vscode/c_cpp_properties.json b/examples/shakti-sdk_gpio-keypad/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..74455fb --- /dev/null +++ b/examples/shakti-sdk_gpio-keypad/.vscode/c_cpp_properties.json @@ -0,0 +1,39 @@ +{ + "configurations": [ + { + "name": "!!! WARNING !!! AUTO-GENERATED FILE, PLEASE DO NOT MODIFY IT AND USE https://docs.platformio.org/page/projectconf/section_env_build.html#build-flags" + }, + { + "name": "Win32", + "includePath": [ + "c:/Users/ROOT/.platformio/platforms/shakti/examples/shakti-sdk_gpio-keypad/include", + "c:/Users/ROOT/.platformio/platforms/shakti/examples/shakti-sdk_gpio-keypad/src", + "C:/Users/ROOT/.platformio/packages/framework-shakti-sdk/bsp/include", + "C:/Users/ROOT/.platformio/packages/framework-shakti-sdk/bsp/third_party/artix7_35t", + "C:/Users/ROOT/.platformio/packages/tool-unity", + "" + ], + "browse": { + "limitSymbolsToIncludedHeaders": true, + "databaseFilename": "${workspaceRoot}/.vscode/.browse.c_cpp.db", + "path": [ + "c:/Users/ROOT/.platformio/platforms/shakti/examples/shakti-sdk_gpio-keypad/include", + "c:/Users/ROOT/.platformio/platforms/shakti/examples/shakti-sdk_gpio-keypad/src", + "C:/Users/ROOT/.platformio/packages/framework-shakti-sdk/bsp/include", + "C:/Users/ROOT/.platformio/packages/framework-shakti-sdk/bsp/third_party/artix7_35t", + "C:/Users/ROOT/.platformio/packages/tool-unity", + "" + ] + }, + "defines": [ + "PLATFORMIO=40000", + "ARTIX7_35T", + "" + ], + "intelliSenseMode": "clang-x64", + "cStandard": "c99", + "compilerPath": "\"C:/Users/ROOT/.platformio/packages/toolchain-riscv/bin/riscv64-unknown-elf-gcc.exe\" -march=rv32imac -mabi=ilp32 -mcmodel=medany" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/examples/shakti-sdk_gpio-keypad/.vscode/extensions.json b/examples/shakti-sdk_gpio-keypad/.vscode/extensions.json new file mode 100644 index 0000000..272828b --- /dev/null +++ b/examples/shakti-sdk_gpio-keypad/.vscode/extensions.json @@ -0,0 +1,7 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ] +} \ No newline at end of file diff --git a/examples/shakti-sdk_gpio-keypad/.vscode/launch.json b/examples/shakti-sdk_gpio-keypad/.vscode/launch.json new file mode 100644 index 0000000..0227a41 --- /dev/null +++ b/examples/shakti-sdk_gpio-keypad/.vscode/launch.json @@ -0,0 +1,34 @@ +// AUTOMATICALLY GENERATED FILE. PLEASE DO NOT MODIFY IT MANUALLY + +// PIO Unified Debugger +// +// Documentation: https://docs.platformio.org/page/plus/debugging.html +// Configuration: https://docs.platformio.org/page/projectconf/section_env_debug.html + +{ + "version": "0.2.0", + "configurations": [ + { + "type": "platformio-debug", + "request": "launch", + "name": "PIO Debug", + "executable": "c:/Users/ROOT/.platformio/platforms/shakti/examples/shakti-sdk_gpio-keypad/.pio/build/artix7_35t/firmware.elf", + "toolchainBinDir": "C:/Users/ROOT/.platformio/packages/toolchain-riscv/bin", + "svdPath": "C:/Users/ROOT/.platformio/platforms/shakti/misc/svd/FE310.svd", + "preLaunchTask": { + "type": "PlatformIO", + "task": "Pre-Debug" + }, + "internalConsoleOptions": "openOnSessionStart" + }, + { + "type": "platformio-debug", + "request": "launch", + "name": "PIO Debug (skip Pre-Debug)", + "executable": "c:/Users/ROOT/.platformio/platforms/shakti/examples/shakti-sdk_gpio-keypad/.pio/build/artix7_35t/firmware.elf", + "toolchainBinDir": "C:/Users/ROOT/.platformio/packages/toolchain-riscv/bin", + "svdPath": "C:/Users/ROOT/.platformio/platforms/shakti/misc/svd/FE310.svd", + "internalConsoleOptions": "openOnSessionStart" + } + ] +} \ No newline at end of file diff --git a/examples/shakti-sdk_gpio-keypad/.vscode/settings.json b/examples/shakti-sdk_gpio-keypad/.vscode/settings.json new file mode 100644 index 0000000..6bae624 --- /dev/null +++ b/examples/shakti-sdk_gpio-keypad/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "gpio.h": "c" + } +} \ No newline at end of file diff --git a/examples/shakti-sdk_gpio-keypad/README.rst b/examples/shakti-sdk_gpio-keypad/README.rst new file mode 100644 index 0000000..898d9e6 --- /dev/null +++ b/examples/shakti-sdk_gpio-keypad/README.rst @@ -0,0 +1,38 @@ +.. Copyright 2014-present PlatformIO + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +How to build PlatformIO based project +===================================== + +1. `Install PlatformIO Core `_ +2. Download `development platform with examples `_ +3. Extract ZIP archive +4. Run these commands: + +.. code-block:: bash + + # Change directory to example + > cd platform-shakti/examples/shakti-sdk_gpio-keypad + + # Build project + > platformio run + + # Upload firmware + > platformio run --target upload + + # Build specific environment + > platformio run -e artix7_35t + + # Upload firmware for the specific environment + > platformio run -e artix7_35t --target upload + + # Clean build files + > platformio run --target clean diff --git a/examples/shakti-sdk_gpio-keypad/include/README b/examples/shakti-sdk_gpio-keypad/include/README new file mode 100644 index 0000000..194dcd4 --- /dev/null +++ b/examples/shakti-sdk_gpio-keypad/include/README @@ -0,0 +1,39 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the usual convention is to give header files names that end with `.h'. +It is most portable to use only letters, digits, dashes, and underscores in +header file names, and at most one dot. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/examples/shakti-sdk_gpio-keypad/lib/README b/examples/shakti-sdk_gpio-keypad/lib/README new file mode 100644 index 0000000..6debab1 --- /dev/null +++ b/examples/shakti-sdk_gpio-keypad/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into executable file. + +The source code of each library should be placed in a an own separate directory +("lib/your_library_name/[here are source files]"). + +For example, see a structure of the following two libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +and a contents of `src/main.c`: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +PlatformIO Library Dependency Finder will find automatically dependent +libraries scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/examples/shakti-sdk_gpio-keypad/platformio.ini b/examples/shakti-sdk_gpio-keypad/platformio.ini new file mode 100644 index 0000000..a8f1086 --- /dev/null +++ b/examples/shakti-sdk_gpio-keypad/platformio.ini @@ -0,0 +1,26 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter, extra scripting +; Upload options: custom port, speed and extra flags +; Library options: dependencies, extra library storages +; +; Please visit documentation for the other options and examples +; http://docs.platformio.org/page/projectconf.html + +[platformio] +description = + A simple example with GPIO interaction + +[env:artix7_35t] +platform = shakti +framework = shakti-sdk +board = artix7_35t +monitor_speed = 115200 +debug_tool = qemu + +; [env:artix7_100t] +; platform = shakti +; framework = shakti-sdk +; board = artix7_100t +; monitor_speed = 115200 + diff --git a/examples/shakti-sdk_gpio-keypad/src/keypad.c b/examples/shakti-sdk_gpio-keypad/src/keypad.c new file mode 100644 index 0000000..5e21179 --- /dev/null +++ b/examples/shakti-sdk_gpio-keypad/src/keypad.c @@ -0,0 +1,199 @@ +/************************************************************************ + * Project : shakti devt board + * Name of the file : keypad.c + * Created date : 26.02.2019 + * Brief Description of file : This is an example on how to get the value of a key pressed on a Pmod keypad. + + Copyright (C) 2019 IIT Madras. All rights reserved. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + *****************************************************************************/ +/* + To Do: identify a key press to a letter. some more testing. +*/ + +/*********************************************************** +* Include File Definitions +************************************************************/ + +#include "gpio.h" +#include "platform.h" +#include "keypad.h"//Includes the definitions of keypad function// + +/* global variable definition*/ + +// initialize key and colrow to -1 indicate no key is pressed +int key = -1; +int colRow = -1; + +unsigned int rowPins[KYPD_ROWNUM]; +unsigned int colPins[KYPD_COLNUM]; +int keyMap[KYPD_COLNUM][KYPD_ROWNUM]; + +unsigned int col[4]={3, 2, 1, 0}; +unsigned int row[4]={7, 6, 5, 4}; + + +int keyTable[4][4]={{1, 4, 7, 15}, + {2, 5, 8, 0}, + {3, 6, 9, 14}, + {10, 11, 12, 13}}; + +/************************************************************ +* Description: +* This function sets the pins for the row and column +************************************************************/ +void setPins(unsigned int* row, unsigned int* col) +{ + for(int i = 0 ; i < KYPD_COLNUM ; i++) + { + colPins[i] = col[i];// set col + } + for(int j = 0 ; j < KYPD_ROWNUM ; j++) // set row + { + rowPins[j] = row[j]; + } +} + +/************************************************************ +* Description: +* This function maps table in to keymap +************************************************************/ + +void setKeyMap(int table[KYPD_COLNUM][KYPD_ROWNUM]) +{ + + for(int i = 0 ; i < KYPD_COLNUM ; i++) + { + for(int j = 0 ; j < KYPD_ROWNUM ; j++) + { + keyMap[i][j] = table[i][j]; + } + } +} + +/************************************************************ +* Description: +* This function returns the corresponding value in the keymap +************************************************************/ + +int getKey() +{ + + write_word(GPIO_DATA_REG, (0xF << OUTPINS_OFFSET) ); + + for(int i = 0 ; i < KYPD_COLNUM ; i++) + { + write_word(GPIO_DRV_CNTRL_REG2, ~(0x1 << (OUTPINS_OFFSET + i) ) ); + + for(int j = 0 ; j < KYPD_ROWNUM ; j++) + { + if( ( read_word(rowPins[j]) & (INPINS << INPINS_OFFSET ) ) == 0) + { + return keyMap[i][j]; + } + } + write_word(GPIO_DATA_REG, (0xF << OUTPINS_OFFSET) ); + } + + return 0; +} + +/************************************************************ + * Description: + * This function returns the column-row + ***********************************************************/ + +int getColRow(void) +{ + int colRow = 0; + unsigned long readValue = 0; + + write_word(GPIO_DATA_REG, (0xF << OUTPINS_OFFSET) ); + + + for(int i = 0 ; i < KYPD_COLNUM ; i++) + { + write_word(GPIO_DATA_REG, ~(0x1 << (OUTPINS_OFFSET + i) ) ); + + for(int j = 0 ; j < KYPD_ROWNUM ; j++) + { + readValue = read_word(GPIO_DATA_REG) ; + printf("\n The read value is %lx; rowPins: %d", (readValue & 0x0F0F0000), rowPins[j]); + + if( ( readValue & (1 << rowPins[j] ) == 0) ) + { + printf("\n The read value is %lx; rowPins: %d", readValue, rowPins[j]); + + return (i << 16 | j); + } + } + + write_word(GPIO_DATA_REG, (0xF << OUTPINS_OFFSET) ); + } + + return 0; +} + +/********************************************************************* +* Brief Description :This maps the keypad from pins. +* Parameters :rows,columns. +********************************************************************/ + +void gpio_init() +{ + setPins(row, col); + + setKeyMap(keyTable); + +#ifndef ARTIX7_35T + //Configure the GPIO pins + write_word(GPIO_DRV_CNTRL_REG0, OUTPINS); + write_word(GPIO_DRV_CNTRL_REG1, OUTPINS); + write_word(GPIO_DRV_CNTRL_REG2, 0x00); + + //Makes the output as pushpull (0 ---> open drain, 1 ---> pushpull) + write_word(GPIO_MODE_SEL_REG, OUTPINS); + + //Makes the slewrate as slow (0 ---> slow, 1 ---> fast) + write_word(GPIO_PROG_SLEW_CNTRL_REG, 0x00); +#endif + + //Configure direction of GPIO pins + write_word(GPIO_DIRECTION_CNTRL_REG, OUTPINS); +} + +int main() +{ + gpio_init(); //Intialization of gpio // + + printf("\nGPIO Init Done"); + + while(1) + { + colRow = getColRow(); + + if( colRow != -1 ) + { + key = getKey(); + printf("\ncol: %d; row: %d is value: %d", colRow>>16, (0xFFFF & colRow), key ); + } + + DelayLoop(100,100); + DelayLoop(5000, 5000); + } + + return 0; +} diff --git a/examples/shakti-sdk_gpio-keypad/src/keypad.h b/examples/shakti-sdk_gpio-keypad/src/keypad.h new file mode 100644 index 0000000..d34dc25 --- /dev/null +++ b/examples/shakti-sdk_gpio-keypad/src/keypad.h @@ -0,0 +1,61 @@ +/*************************************************************************** +* Project : shakti devt board +* Name of the file : keypad.h +* Created date : 26.02.2019 +* Brief Description of file : Declaration for keypad library. + + Copyright (C) 2019 IIT Madras. All rights reserved. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +***************************************************************************/ +/* ------------------------------------------------------------ */ +/* Include File Definitions */ +/* ------------------------------------------------------------ */ +#if !defined(KYPD_H) +#define KYPD_H + +#define KYPD_ROWNUM 4 +#define KYPD_COLNUM 4 + +#define GPIO_START 0X00011100 +#define GPIO_DIRECTION_CNTRL_REG (GPIO_START + 0X00) +#define GPIO_DATA_REG (GPIO_START + 0X04) +#define GPIO_DRV_CNTRL_REG0 (GPIO_START + 0X08) +#define GPIO_DRV_CNTRL_REG1 (GPIO_START + 0X0C) +#define GPIO_DRV_CNTRL_REG2 (GPIO_START + 0X10) +#define GPIO_PULL_DOWN_CNTRL_REG (GPIO_START + 0X14) +#define GPIO_MODE_SEL_REG (GPIO_START + 0X18) +#define GPIO_PROG_SLEW_CNTRL_REG (GPIO_START + 0X1C) +#define GPIO_PULL_UP_CNTRL_REG (GPIO_START + 0X20) +#define CORE_PWR_DOWN_STS_REG0 (GPIO_START + 0X24) +#define CORE_PWR_DOWN_STS_REG1 (GPIO_START + 0X28) +#define OUTPINS_OFFSET 24 +#define INPINS_OFFSET 16 +#define OUTPINS (0xF << OUTPINS_OFFSET) +#define INPINS (0xF << INPINS_OFFSET) +/* ------------------------------------------------------------ */ +/* Procedure Declarations */ +/* ------------------------------------------------------------ */ + + + + void setPins(unsigned int* row, unsigned int* col); + void setKeyMap(int table[KYPD_COLNUM][KYPD_ROWNUM]); + int getKey(); + int getColRow(void); + unsigned int rowPins[KYPD_ROWNUM]; + unsigned int colPins[KYPD_COLNUM]; + int keyMap[KYPD_COLNUM][KYPD_ROWNUM]; +#endif diff --git a/examples/shakti-sdk_gpio-keypad/test/README b/examples/shakti-sdk_gpio-keypad/test/README new file mode 100644 index 0000000..df5066e --- /dev/null +++ b/examples/shakti-sdk_gpio-keypad/test/README @@ -0,0 +1,11 @@ + +This directory is intended for PIO Unit Testing and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PIO Unit Testing: +- https://docs.platformio.org/page/plus/unit-testing.html diff --git a/examples/shakti-sdk_i2c-lm75/.gitignore b/examples/shakti-sdk_i2c-lm75/.gitignore new file mode 100644 index 0000000..6c69f4c --- /dev/null +++ b/examples/shakti-sdk_i2c-lm75/.gitignore @@ -0,0 +1,2 @@ +.pioenvs +.piolibdeps diff --git a/examples/shakti-sdk_i2c-lm75/.travis.yml b/examples/shakti-sdk_i2c-lm75/.travis.yml new file mode 100644 index 0000000..7c486f1 --- /dev/null +++ b/examples/shakti-sdk_i2c-lm75/.travis.yml @@ -0,0 +1,67 @@ +# Continuous Integration (CI) is the practice, in software +# engineering, of merging all developer working copies with a shared mainline +# several times a day < https://docs.platformio.org/page/ci/index.html > +# +# Documentation: +# +# * Travis CI Embedded Builds with PlatformIO +# < https://docs.travis-ci.com/user/integration/platformio/ > +# +# * PlatformIO integration with Travis CI +# < https://docs.platformio.org/page/ci/travis.html > +# +# * User Guide for `platformio ci` command +# < https://docs.platformio.org/page/userguide/cmd_ci.html > +# +# +# Please choose one of the following templates (proposed below) and uncomment +# it (remove "# " before each line) or use own configuration according to the +# Travis CI documentation (see above). +# + + +# +# Template #1: General project. Test it using existing `platformio.ini`. +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# install: +# - pip install -U platformio +# - platformio update +# +# script: +# - platformio run + + +# +# Template #2: The project is intended to be used as a library with examples. +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# env: +# - PLATFORMIO_CI_SRC=path/to/test/file.c +# - PLATFORMIO_CI_SRC=examples/file.ino +# - PLATFORMIO_CI_SRC=path/to/test/directory +# +# install: +# - pip install -U platformio +# - platformio update +# +# script: +# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/examples/shakti-sdk_i2c-lm75/README.rst b/examples/shakti-sdk_i2c-lm75/README.rst new file mode 100644 index 0000000..7dd0633 --- /dev/null +++ b/examples/shakti-sdk_i2c-lm75/README.rst @@ -0,0 +1,38 @@ +.. Copyright 2014-present PlatformIO + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +How to build PlatformIO based project +===================================== + +1. `Install PlatformIO Core `_ +2. Download `development platform with examples `_ +3. Extract ZIP archive +4. Run these commands: + +.. code-block:: bash + + # Change directory to example + > cd platform-shakti/examples/shakti-sdk_i2c-lm75 + + # Build project + > platformio run + + # Upload firmware + > platformio run --target upload + + # Build specific environment + > platformio run -e artix7_35t + + # Upload firmware for the specific environment + > platformio run -e artix7_35t --target upload + + # Clean build files + > platformio run --target clean diff --git a/examples/shakti-sdk_i2c-lm75/include/README b/examples/shakti-sdk_i2c-lm75/include/README new file mode 100644 index 0000000..194dcd4 --- /dev/null +++ b/examples/shakti-sdk_i2c-lm75/include/README @@ -0,0 +1,39 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the usual convention is to give header files names that end with `.h'. +It is most portable to use only letters, digits, dashes, and underscores in +header file names, and at most one dot. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/examples/shakti-sdk_i2c-lm75/lib/README b/examples/shakti-sdk_i2c-lm75/lib/README new file mode 100644 index 0000000..6debab1 --- /dev/null +++ b/examples/shakti-sdk_i2c-lm75/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into executable file. + +The source code of each library should be placed in a an own separate directory +("lib/your_library_name/[here are source files]"). + +For example, see a structure of the following two libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +and a contents of `src/main.c`: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +PlatformIO Library Dependency Finder will find automatically dependent +libraries scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/examples/shakti-sdk_i2c-lm75/platformio.ini b/examples/shakti-sdk_i2c-lm75/platformio.ini new file mode 100644 index 0000000..ee2ffcd --- /dev/null +++ b/examples/shakti-sdk_i2c-lm75/platformio.ini @@ -0,0 +1,25 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter, extra scripting +; Upload options: custom port, speed and extra flags +; Library options: dependencies, extra library storages +; +; Please visit documentation for the other options and examples +; http://docs.platformio.org/page/projectconf.html + +[platformio] +description = + A simple example with I2C bus and LM75 sensor + +[env:artix7_35t] +platform = shakti +framework = shakti-sdk +board = artix7_35t +monitor_speed = 115200 + +[env:artix7_100t] +platform = shakti +framework = shakti-sdk +board = artix7_100t +monitor_speed = 115200 + diff --git a/examples/shakti-sdk_i2c-lm75/src/i2c.h b/examples/shakti-sdk_i2c-lm75/src/i2c.h new file mode 100644 index 0000000..69e79a3 --- /dev/null +++ b/examples/shakti-sdk_i2c-lm75/src/i2c.h @@ -0,0 +1,345 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * + * Copyright (C) 1995-1997 Simon G. Vogl + * 1998-2000 Hans Berglund + * + * With some changes from Kyösti Mälkki and + * Frodo Looijaard , and also from Martin Bailey + * + * + * Partially rewriten by Oleg I. Vdovikin to handle multiple + * messages, proper stop/repstart signaling during receive, added detect code + * + * Partially rewritten by Vinod and Kotteeswaran for shakti i2c + * + * i2c-algo-pcf.c i2c driver algorithms for PCF8584 adapters was modified to this file. + */ + + + + +#ifndef I2C_H +#define I2C_H + +#define NEW_CCLASS + +#define ETIMEOUT -60 +#define DEF_TIMEOUT 60 +#define ETIMEDOUT -80 +#define ENXIO -82 +#define EREMOTEIO -81 + +#define I2C_SHAKTI_PIN 0x80 +#define I2C_SHAKTI_ESO 0x40 +#define I2C_SHAKTI_ES1 0x20 +#define I2C_SHAKTI_ES2 0x10 +#define I2C_SHAKTI_ENI 0x08 +#define I2C_SHAKTI_STA 0x04 +#define I2C_SHAKTI_STO 0x02 +#define I2C_SHAKTI_ACK 0x01 + +#define I2C_SHAKTI_INI 0x40 /* 1 if not initialized */ +#define I2C_SHAKTI_STS 0x20 +#define I2C_SHAKTI_BER 0x10 +#define I2C_SHAKTI_AD0 0x08 +#define I2C_SHAKTI_LRB 0x08 +#define I2C_SHAKTI_AAS 0x04 +#define I2C_SHAKTI_LAB 0x02 +#define I2C_SHAKTI_BB 0x01 + +#define I2C_SHAKTI_START (I2C_SHAKTI_PIN | I2C_SHAKTI_ESO | I2C_SHAKTI_STA | I2C_SHAKTI_ACK) +#define I2C_SHAKTI_START_ENI (I2C_SHAKTI_PIN | I2C_SHAKTI_ESO | I2C_SHAKTI_STA | I2C_SHAKTI_ACK | I2C_SHAKTI_START_ENI) +#define I2C_SHAKTI_STOP (I2C_SHAKTI_PIN | I2C_SHAKTI_ESO | I2C_SHAKTI_STO | I2C_SHAKTI_ACK) +#define I2C_SHAKTI_REPSTART ( I2C_SHAKTI_ESO | I2C_SHAKTI_STA | I2C_SHAKTI_ACK) +#define I2C_SHAKTI_REPSTART_ENI ( I2C_SHAKTI_ESO | I2C_SHAKTI_STA | I2C_SHAKTI_ACK | I2C_SHAKTI_REPSTART_ENI) +#define I2C_SHAKTI_IDLE (I2C_SHAKTI_PIN | I2C_SHAKTI_ESO | I2C_SHAKTI_ACK) +#define I2C_SHAKTI_NACK (I2C_SHAKTI_ESO ) + +#define I2C_READ 1 +#define I2C_WRITE 0 + + +#ifdef ECLASS +#define I2C0_BASE_ADDRESS 0x1001200 +#endif + +#ifdef NEW_CCLASS +#define I2C0_BASE_ADDRESS 0x020C0000 +#endif + + +//Following the memory map provided +#define I2C_PRESCALE (I2C0_BASE_ADDRESS + 0) +#define I2C_CONTROL (I2C0_BASE_ADDRESS + 8) +#define I2C_DATA (I2C0_BASE_ADDRESS + 0x10) +#define I2C_STATUS (I2C0_BASE_ADDRESS + 0x18) +#define I2C_SCL (I2C0_BASE_ADDRESS + 0x38) + + +#define I2C_TESTLED 0x11400 + +#if 1 +// Hardcoding the pointers with addresss -- let's see if this works +int* i2c_control = (const int *) I2C_CONTROL; +int* i2c_data = (const int *) I2C_DATA; +int* i2c_status = (const int *) I2C_STATUS; +int* i2c_prescale = (const int *) I2C_PRESCALE; +int* i2c_scl = (const int *) I2C_SCL; +int* i2c_led = (const int *) I2C_TESTLED; +#else + #define i2c_prescale 0x11400 + #define i2c_control 0x11408 + #define i2c_data 0x11410 + #define i2c_status 0x11418 + #define i2c_scl 0x11438 +#endif + + +//#undef ASM +//#define ASM + +char get_i2c_shakti(char *addr) +{ +#ifdef ASM + +char val; + + printf("\n The address is %p;", (char *) addr); + asm volatile("lb %0, 0(%1)" : "=r" (val) : "r" (*addr)); + return val; +#else + return *addr; +#endif +} + +void set_i2c_shakti(char *addr, char val) +{ +#ifdef ASM + printf("\n The address is %p; value: %x", (char *) addr, val); + asm volatile("sb %0, 0(%1)" : : "r" (val), "r" (*addr)); +#else + *addr = val; +#endif +} + +void waitfor(unsigned int secs) { + unsigned int time = 0; + while(time++ < secs); +} + +void i2c_start() +{ + set_i2c_shakti(i2c_control, I2C_SHAKTI_START); +} + +void i2c_start_eni() +{ + set_i2c_shakti(i2c_control, I2C_SHAKTI_START); +} + +void i2c_repstart() +{ + set_i2c_shakti(i2c_control, I2C_SHAKTI_REPSTART); +} + +void i2c_repstart_eni() +{ + set_i2c_shakti(i2c_control, I2C_SHAKTI_REPSTART); +} + +void i2c_stop() +{ + set_i2c_shakti(i2c_control, I2C_SHAKTI_STOP); +} + + +void i2c_nack() +{ + set_i2c_shakti(i2c_control, I2C_SHAKTI_NACK); +} + + +int shakti_init_i2c() +{ + unsigned char temp = 0; + printf("\tI2C: Initializing the Controller\n"); + + /* Doing an initialization sequence as how PCF8584 was supposed to be initialized */ + /* The Initialization Sequence is as follows */ + /* Reset Minimum 30 Clock Cycles -- Not necessary in our case */ + /* Load Byte 80H into Control */ + /* load Clock Register S2 */ /* We are doing the opposite -- Setting the clock and then the registers -- Doesn't really matter actually */ + /* Send C1H to S1 - Set I2C to Idle mode -- SDA and SCL should be high */ + +#if 1 + set_i2c_shakti(i2c_prescale,0x1F); //Setting the I2C clock value to be 1, which will set the clock for module and prescaler clock + temp = get_i2c_shakti(i2c_prescale); + set_i2c_shakti(i2c_scl,0x91); //Setting the I2C clock value to be 1, which will set the clock for module and prescaler clock + temp = get_i2c_shakti(i2c_scl); +/* Just reading the written value to see if all is well -- Compiler should not optimize this load!!! Compiler can just optimize the store to pointer address followed by load pointer to a register to just an immediate load to the register since clock register is not used anywhere -- but the purpose is lost. Don't give compiler optimizations */ + + if((temp | 0x00) != 0x91){ + printf("\tClock initialization failed Write Value: 0x91; read Value: %02x\n", temp); + return -ENXIO; + } + else{ + printf("\tClock successfully initalized\n"); + } +#endif + + + /* S1=0x80 S0 selected, serial interface off */ + printf("\tSetting Control Register with 0x80 \n"); + set_i2c_shakti(i2c_control, I2C_SHAKTI_PIN); + printf("\tControl Register Successfully set \n"); + + // Reading set control Register Value to ensure sanctity + printf("\tReading Control Register \n"); + temp = get_i2c_shakti(i2c_control); + printf("\tControl Register is Written with 0x%x \n", temp); + + if((temp & 0x7f) != 0){ + printf("\tDevice Not Recognized\n"); + return -ENXIO; + } + + printf("\tWaiting for a specified time\n "); + waitfor(900); //1 Second software wait -- Should be 900000 but setting to 900 now since simulation is already slow + printf("\tDone Waiting \n "); + + /* Enable Serial Interface */ + set_i2c_shakti(i2c_control, I2C_SHAKTI_IDLE); + waitfor(900); //1 Second software wait -- Should be 900000 but setting to 900 now since simulation is already slow + temp = get_i2c_shakti(i2c_status); + printf("\tStatus Reg value after sending I2C_SHAKTI_IDLE is : 0x%x \n",temp); + + /* Check to see if I2C is really in Idle and see if we can access the status register -- If not something wrong in initialization. This also verifies if Control is properly written since zero bit will be initialized to zero*/ + if(temp != (I2C_SHAKTI_PIN | I2C_SHAKTI_BB)){ + printf("\tInitialization failed\n"); + return -ENXIO; + } + else + printf("\tAll is well till here \n"); + + printf("\tI2C successfully initialized\n"); +} + +int wait_for_bb() +{ + + printf("\tIs bus busy?\n"); + int timeout = DEF_TIMEOUT; + int status; + + status = get_i2c_shakti(i2c_status); + + while (!(status & I2C_SHAKTI_BB) && --timeout) { + waitfor(20000); /* wait for 100 us */ + status = get_i2c_shakti(i2c_status); + } + + if (timeout == 0) { + printf("\t Bus busy wait - timed out. Resetting\n"); + return ETIMEDOUT; + } + + return 0; +} + +int wait_for_pin(int *status) +{ + + int timeout = DEF_TIMEOUT; + + *status = get_i2c_shakti(i2c_status); + + while ((*status & I2C_SHAKTI_PIN) && --timeout) { + waitfor(10000); /* wait for 100 us */ + *status = get_i2c_shakti(i2c_status); + } + + if (timeout == 0){ + printf("\tWait for pin timed out\n"); + return ETIMEDOUT; + } + + return 0; +} + +int shakti_sendbytes( const char *buf, int count, int last, int eni) +{ + int wrcount, status, timeout; + printf("\tStarting Write Transaction -- Did you create tri1 nets for SDA and SCL in verilog?\n"); + for (wrcount=0; wrcount and + * Frodo Looijaard , and also from Martin Bailey + * + * + * Partially rewriten by Oleg I. Vdovikin to handle multiple + * messages, proper stop/repstart signaling during receive, added detect code + * + * Partially rewritten by Vinod and Kotteeswaran for shakti i2c + * + * i2c-algo-pcf.c i2c driver algorithms for PCF8584 adapters was modified to this file. + */ + + + +#include "i2c.h"//Includes the definitions of i2c communication protocol// +#include //Includes the definitions of standard input/output functions// +#define LM75_SLAVE_ADDRESS 0x90//Defines the Starting address of slave// + + +/************************************************************************ +* Brief Description : Maintains the required delay to perform an operation. +* Parameters : Delay Required(Ms). +*************************************************************************/ + +void DelayLoop(unsigned long cntr1, unsigned long cntr2) +{ + unsigned long tmpCntr = cntr2; + while(cntr1--) + { + tmpCntr = cntr2; + while(tmpCntr--); + } +} +/************************************************************************ +* Brief Description : Performs the i2c protocol configuration. +* Parameters : prescalar clock,serial clock. +* Return : int. +*************************************************************************/ + +int i2c_configure(int psc, int sclkFrequency) +{ + unsigned char temp = 0; + + printf("\n\tI2C: Initializing the Controller"); + + set_i2c_shakti(i2c_prescale, psc); /* Setting Prescaler Clock */ + + //Setting the I2C clock value to be 1, which will set the clock for module and prescaler clock // + +#ifdef DEBUG /* Verify the above written psc value */ + + temp = get_i2c_shakti(i2c_prescale);//copies the prescalar clock value to the temp variable// + + if(temp != psc) + + { + printf("\n\t Error in setting prescaler clock; Wr. Value: 0x%02x; Read Value: 0x%02x", psc, temp); + } + + else + + { + printf("\n\t Prescaler value is written successfully\n"); + } + +#endif + set_i2c_shakti(i2c_scl, sclkFrequency);/* Set I2C Serial clock frequency */ + + +#ifdef DEBUG /* Verify the above written serial clock value */ + + temp = get_i2c_shakti(i2c_scl); +/* Just reading the written value to see if all is well -- Compiler should not optimize this load!!! Compiler can just optimize the store to pointer address followed by load pointer to a register to just an immediate load to the register since clock register is not used anywhere -- but the purpose is lost. Don't give compiler optimizations */ + + if(temp != sclkFrequency){/*if prescalar clock is not equal to serial clock*/ + + printf("\n\tClock initialization failed Write Value: 0x%02x; read Value: 0x%02x", sclkFrequency, temp); + return -ENXIO; + } + + else{ + printf("\tClock successfully initalized\n"); + } +#endif + +#ifdef DEBUG + + printf("\tSetting Control Register with 0x01 \n"); + + set_i2c_shakti(i2c_control, 0x01); // Reading set control Register Value to ensure sanctity// + + temp = get_i2c_shakti(i2c_control);//copies the i2c control variable to temp// + + printf("\tControl Register Read Value 0x%x \n", temp); + +#endif + + /* S1=0x80 S0 selected, serial interface off */ + printf("\tSetting Control Register with 0x80 \n"); + set_i2c_shakti(i2c_control, I2C_SHAKTI_PIN); + +#ifdef DEBUG + printf("\tControl Register Successfully set \n"); // Reading set control Register Value to ensure sanctity // + printf("\tReading Control Register \n"); + temp = get_i2c_shakti(i2c_control); + printf("\tControl Register is Written with 0x%x \n", temp); +#endif + + if((temp & 0x7f) != 0){ + printf("\tDevice Not Recognized\n"); + return -ENXIO; + } + + printf("\tWaiting for a specified time\n "); + waitfor(900); //1 Second software wait -- Should be 900000 but setting to 900 now since simulation is already slow + printf("\tDone Waiting \n "); + + i2c_stop(); + + /* Enable Serial Interface */ + printf("\n Making the I2C chip in idle State"); + set_i2c_shakti(i2c_control, I2C_SHAKTI_IDLE); + + printf("\n\tWaiting for a specified time After setting idle\n "); + waitfor(900); //1 Second software wait -- Should be 900000 but setting to 900 now since simulation is already slow + printf("\tDone Waiting \n "); + +#ifdef DEBUG + temp = get_i2c_shakti(i2c_status); + printf("\tStatus Reg value is : 0x%x \n",temp); + +#endif +/* Check to see if I2C is really in Idle and see if we can access the status register.This also verifies if Control is properly written since zero bit will be initialized to zero */ + + if(temp != (I2C_SHAKTI_PIN | I2C_SHAKTI_BB)){ + printf("\tInitialization failed\n"); + return -ENXIO; + } + + printf("\tI2C successfully initialized\n"); +} +/************************************************************************ +* Brief Description : Performs the intilization of i2c slave. +* Parameters : slave address. +* Return : int. +*************************************************************************/ + +int i2c_slave_init(unsigned char slaveAddress) +{ + int timeout; + unsigned char temp = 0; + int status = 0; + printf("\n\tSetting Slave Address : 0x%02x\n", slaveAddress);/* Writes the slave address to I2C controller */ + + set_i2c_shakti(i2c_data,slaveAddress); + printf("\tSlave Address set\n"); + + +#ifdef DEBUG + + temp = get_i2c_shakti(i2c_data); //Reads the slave address from I2C controller + printf("\tSet slave address read again, which is 0x%x\n",temp); + + if(slaveAddress != (int)temp) + printf("\tSlave address is not matching; Written Add. Value: 0x%02x; Read Add. Value: 0x%02x\n", slaveAddress, temp); +#endif + + i2c_start(); //Sending the slave address to the I2C slave + + + timeout = wait_for_pin(&status); + if (timeout) {//Asking the controller to send a start signal to initiate the transaction + printf("\tTimeout happened - Write did not go through the BFM -- Diagnose\n"); + i2c_stop(); //~ + return EREMOTEIO; + } + + if (status & I2C_SHAKTI_LRB) { + i2c_stop(); + printf("\tSome status check failing\n"); + } +} +/************************************************************************ +* Brief Description : It does the reading or writing from the address specified . +* Parameters : starting address. +* Return : int. +*************************************************************************/ + +int SendAddressToReadOrWrite(unsigned int startAddress) +{ + int timeout; + unsigned char temp = 0; + int status = 0; + +#ifdef _16Bit + set_i2c_shakti(i2c_data, (startAddress >> 8) & 0xFF); + timeout = wait_for_pin(&status); + if (timeout) { + printf("\tTimeout happened - Write did not go through the BFM -- Diagnose\n"); + i2c_stop(); //~ + return EREMOTEIO; + } + + if (status & I2C_SHAKTI_LRB) { // What error is this? + i2c_stop();//~ + printf("\tSome status check failing\n"); + return EREMOTEIO; + } +#endif + + set_i2c_shakti(i2c_data, (startAddress >> 0) & 0xFF); + timeout = wait_for_pin(&status); + if (timeout) { + printf("\tTimeout happened - Write did not go through the BFM -- Diagnose\n"); + i2c_stop(); //~ + return EREMOTEIO; + } + + if (status & I2C_SHAKTI_LRB) { // What error is this? + i2c_stop();//~ + printf("\tSome status check failing\n"); + } +} +/************************************************************************ +* Brief Description : It does the reading or writing from the address specified . +* Parameters : starting address. +* Return : int. +*************************************************************************/ +int i2c_rw_wait(int *status) +{ + int timeout = DEF_TIMEOUT; + + *status = get_i2c_shakti(i2c_status); + + while ((*status & I2C_SHAKTI_PIN) && --timeout) { + waitfor(10000); /* wait for 100 us */ + *status = get_i2c_shakti(i2c_status); + } + if (timeout == 0){ + printf("\tWait for pin timed out\n"); + return ETIMEDOUT; + } + + return 0; +} +/************************************************************************** +* Brief Description : This makes the read or write operation to wait until the count has been completed . +* Parameters : count value. +* Return : int. +*************************************************************************/ + +int i2c_datawrite( const char *buf, int count, int last, int eni) +{ + int wrcount, status, timeout; + int i = 0; + + printf("\tStarting Write Transaction -- Did you create tri1 nets for SDA and SCL in verilog?\n"); + + for (i = 0; i < count; ++i) + { + printf("\n\t Writing the value 0x%02x into EEPROM", buf[i]); + set_i2c_shakti(i2c_data, buf[i]); + if( ETIMEDOUT == i2c_rw_wait(&status)) + { + printf("\n I2C Write Timed out"); + i2c_stop(); //~ + return EREMOTEIO; + } + if (status & I2C_SHAKTI_LRB) + { + i2c_stop();//~ + printf("\tSome status check failing\n"); + return EREMOTEIO; + } + } + + if (last){ + printf("\n\tLast byte sent : Issue a stop\n"); + i2c_stop(); + } + else + { + printf("\n\tSending Rep Start and doing some other R/W transaction\n"); + if(!eni) + i2c_repstart(); + else + i2c_repstart_eni(); + } + + return i; +} +/************************************************************************ +* Brief Description : It does the data reading. +* Parameters : count value,ending address. +* Return : int. +*************************************************************************/ +int i2c_dataread(char *buf, int count, int last) +{ + int i, status; + int wfp; + int read_value = 0; + + /* increment number of bytes to read by one -- read dummy byte */ + for (i = -1; i < count; i++) + { + if( ETIMEDOUT == i2c_rw_wait(&status)) + { + printf("\n I2C Read Timed out"); + i2c_stop(); + return EREMOTEIO; + } + if (status & I2C_SHAKTI_LRB) + { + i2c_stop();//~ + printf("\tSome status check failing\n"); + return EREMOTEIO; + } + + + if (-1 != i)//Do Dummy Read initially// + { + buf[i] = get_i2c_shakti(i2c_data); + printf("\n\t Read Address Offset: %d; Value: %x", i, buf[i]); + } + else + { + printf("\n\t Dummy Read Value: 0x%02x", get_i2c_shakti(i2c_data) & 0xFF ); /* dummy read */ + } + + + if (i == count - 2)/*send NACK after the penultimate byte*/ + { + i2c_nack(); + waitfor(10000); + } + + if (i == count - 1) /*send STOP after the last byte*/ + { + waitfor(10000); + i2c_stop(); + } + } + printf("\n\t Read %d Bytes from EEPROM", i); + return i; //excluding the dummy read +} + +/************************************************************************ +* Brief Description : It does the Temperature sensing along with the configuration of i2c controller. +* Parameters : Addresses. +* Return : int. +*************************************************************************/ +int main() +{ + int timeout; + unsigned int tempReadValue = 0; + + printf("\tI2C: Starting Transaction\n"); + + + char writebuf1[2] = {0,0}; + char writebuf[18], writeData = 0x30; + writebuf[0] = 0; + writebuf[1] = 0; + + char readbuf[32]; + int i = 0, j = 0, k = 0, status=0; + int slaveaddr = 160; + unsigned char temp = 0; + + /*Configure the I2C controller*/ + + if( i2c_configure(0x0F, 0x51)) + { + printf("\tSomething Wrong In Initialization\n"); + return 0; + } + else + printf("\tIntilization Happened Fine\n"); + + + while(1) + { + printf("\n\r Reading the sensor again"); + + + /*Do a busy wait*/ + while(wait_for_bb()) + { + printf("\tError in Waiting for BB\n"); + return 0; + } + + + /*Write the slave address in Axi bus*/ + + i2c_slave_init(LM75_SLAVE_ADDRESS + 1); //for Read operation // + + /*Start reading from the slave device in the Axi bus*/ + + if(i2c_dataread( readbuf, 2, 1) != 2) + { + printf("\n\tSomething wrong in reading bytes\n -- Diagnose"); + return 0; + } + + + printf("\n\tReadValue: %x; %x", readbuf[0], readbuf[1]); + + tempReadValue = (readbuf[0] << 1) | (readbuf[1] >> 7); + + printf("\n\ttempReadValue = %x", tempReadValue); + printf("\n\t Temp. Value = %d", (tempReadValue / 2) ); + printf("\nCalling delay loop"); + DelayLoop(1000,1000); + printf("\nReturn from Delayloop"); + } + return 0; +} diff --git a/examples/shakti-sdk_i2c-lm75/test/README b/examples/shakti-sdk_i2c-lm75/test/README new file mode 100644 index 0000000..df5066e --- /dev/null +++ b/examples/shakti-sdk_i2c-lm75/test/README @@ -0,0 +1,11 @@ + +This directory is intended for PIO Unit Testing and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PIO Unit Testing: +- https://docs.platformio.org/page/plus/unit-testing.html diff --git a/examples/shakti-sdk_uart-hello/.gitignore b/examples/shakti-sdk_uart-hello/.gitignore new file mode 100644 index 0000000..6c69f4c --- /dev/null +++ b/examples/shakti-sdk_uart-hello/.gitignore @@ -0,0 +1,2 @@ +.pioenvs +.piolibdeps diff --git a/examples/shakti-sdk_uart-hello/.pio/build/.sconsign.dblite b/examples/shakti-sdk_uart-hello/.pio/build/.sconsign.dblite new file mode 100644 index 0000000..ad9fa49 Binary files /dev/null and b/examples/shakti-sdk_uart-hello/.pio/build/.sconsign.dblite differ diff --git a/examples/shakti-sdk_uart-hello/.pio/build/artix7_100t/bsp/include/crt.o b/examples/shakti-sdk_uart-hello/.pio/build/artix7_100t/bsp/include/crt.o new file mode 100644 index 0000000..aad14b8 Binary files /dev/null and b/examples/shakti-sdk_uart-hello/.pio/build/artix7_100t/bsp/include/crt.o differ diff --git a/examples/shakti-sdk_uart-hello/.pio/build/artix7_100t/bsp/libinclude.a b/examples/shakti-sdk_uart-hello/.pio/build/artix7_100t/bsp/libinclude.a new file mode 100644 index 0000000..c7d1d96 Binary files /dev/null and b/examples/shakti-sdk_uart-hello/.pio/build/artix7_100t/bsp/libinclude.a differ diff --git a/examples/shakti-sdk_uart-hello/.pio/build/artix7_100t/bsp/libwrap.a b/examples/shakti-sdk_uart-hello/.pio/build/artix7_100t/bsp/libwrap.a new file mode 100644 index 0000000..4966f6d Binary files /dev/null and b/examples/shakti-sdk_uart-hello/.pio/build/artix7_100t/bsp/libwrap.a differ diff --git a/examples/shakti-sdk_uart-hello/.pio/build/artix7_100t/bsp/libwrap/syscalls.o b/examples/shakti-sdk_uart-hello/.pio/build/artix7_100t/bsp/libwrap/syscalls.o new file mode 100644 index 0000000..2b7a8fa Binary files /dev/null and b/examples/shakti-sdk_uart-hello/.pio/build/artix7_100t/bsp/libwrap/syscalls.o differ diff --git a/examples/shakti-sdk_uart-hello/.pio/build/artix7_100t/bsp/libwrap/util.o b/examples/shakti-sdk_uart-hello/.pio/build/artix7_100t/bsp/libwrap/util.o new file mode 100644 index 0000000..22502f6 Binary files /dev/null and b/examples/shakti-sdk_uart-hello/.pio/build/artix7_100t/bsp/libwrap/util.o differ diff --git a/examples/shakti-sdk_uart-hello/.pio/build/artix7_100t/bsp/third_party/artix7_100t/uart.o b/examples/shakti-sdk_uart-hello/.pio/build/artix7_100t/bsp/third_party/artix7_100t/uart.o new file mode 100644 index 0000000..2ddbcca Binary files /dev/null and b/examples/shakti-sdk_uart-hello/.pio/build/artix7_100t/bsp/third_party/artix7_100t/uart.o differ diff --git a/examples/shakti-sdk_uart-hello/.pio/build/artix7_100t/bsp/third_party/libartix7_100t.a b/examples/shakti-sdk_uart-hello/.pio/build/artix7_100t/bsp/third_party/libartix7_100t.a new file mode 100644 index 0000000..cd602cd Binary files /dev/null and b/examples/shakti-sdk_uart-hello/.pio/build/artix7_100t/bsp/third_party/libartix7_100t.a differ diff --git a/examples/shakti-sdk_uart-hello/.pio/build/artix7_100t/drivers/clic/clic_driver.o b/examples/shakti-sdk_uart-hello/.pio/build/artix7_100t/drivers/clic/clic_driver.o new file mode 100644 index 0000000..df2c985 Binary files /dev/null and b/examples/shakti-sdk_uart-hello/.pio/build/artix7_100t/drivers/clic/clic_driver.o differ diff --git a/examples/shakti-sdk_uart-hello/.pio/build/artix7_100t/drivers/i2c/i2c_driver.o b/examples/shakti-sdk_uart-hello/.pio/build/artix7_100t/drivers/i2c/i2c_driver.o new file mode 100644 index 0000000..8e7f24a Binary files /dev/null and b/examples/shakti-sdk_uart-hello/.pio/build/artix7_100t/drivers/i2c/i2c_driver.o differ diff --git a/examples/shakti-sdk_uart-hello/.pio/build/artix7_100t/drivers/libclic.a b/examples/shakti-sdk_uart-hello/.pio/build/artix7_100t/drivers/libclic.a new file mode 100644 index 0000000..2158a2f Binary files /dev/null and b/examples/shakti-sdk_uart-hello/.pio/build/artix7_100t/drivers/libclic.a differ diff --git a/examples/shakti-sdk_uart-hello/.pio/build/artix7_100t/drivers/libi2c.a b/examples/shakti-sdk_uart-hello/.pio/build/artix7_100t/drivers/libi2c.a new file mode 100644 index 0000000..fd82d52 Binary files /dev/null and b/examples/shakti-sdk_uart-hello/.pio/build/artix7_100t/drivers/libi2c.a differ diff --git a/examples/shakti-sdk_uart-hello/.pio/build/artix7_100t/drivers/libreadme.md b/examples/shakti-sdk_uart-hello/.pio/build/artix7_100t/drivers/libreadme.md new file mode 100644 index 0000000..8b277f0 --- /dev/null +++ b/examples/shakti-sdk_uart-hello/.pio/build/artix7_100t/drivers/libreadme.md @@ -0,0 +1 @@ +! diff --git a/examples/shakti-sdk_uart-hello/.pio/build/artix7_100t/firmware.elf b/examples/shakti-sdk_uart-hello/.pio/build/artix7_100t/firmware.elf new file mode 100644 index 0000000..3da2ef6 Binary files /dev/null and b/examples/shakti-sdk_uart-hello/.pio/build/artix7_100t/firmware.elf differ diff --git a/examples/shakti-sdk_uart-hello/.pio/build/artix7_100t/src/hello.o b/examples/shakti-sdk_uart-hello/.pio/build/artix7_100t/src/hello.o new file mode 100644 index 0000000..c16e498 Binary files /dev/null and b/examples/shakti-sdk_uart-hello/.pio/build/artix7_100t/src/hello.o differ diff --git a/examples/shakti-sdk_uart-hello/.pio/build/artix7_35t/bsp/include/crt.o b/examples/shakti-sdk_uart-hello/.pio/build/artix7_35t/bsp/include/crt.o new file mode 100644 index 0000000..940aebd Binary files /dev/null and b/examples/shakti-sdk_uart-hello/.pio/build/artix7_35t/bsp/include/crt.o differ diff --git a/examples/shakti-sdk_uart-hello/.pio/build/artix7_35t/bsp/libinclude.a b/examples/shakti-sdk_uart-hello/.pio/build/artix7_35t/bsp/libinclude.a new file mode 100644 index 0000000..4133853 Binary files /dev/null and b/examples/shakti-sdk_uart-hello/.pio/build/artix7_35t/bsp/libinclude.a differ diff --git a/examples/shakti-sdk_uart-hello/.pio/build/artix7_35t/bsp/libwrap.a b/examples/shakti-sdk_uart-hello/.pio/build/artix7_35t/bsp/libwrap.a new file mode 100644 index 0000000..e819070 Binary files /dev/null and b/examples/shakti-sdk_uart-hello/.pio/build/artix7_35t/bsp/libwrap.a differ diff --git a/examples/shakti-sdk_uart-hello/.pio/build/artix7_35t/bsp/libwrap/syscalls.o b/examples/shakti-sdk_uart-hello/.pio/build/artix7_35t/bsp/libwrap/syscalls.o new file mode 100644 index 0000000..040d347 Binary files /dev/null and b/examples/shakti-sdk_uart-hello/.pio/build/artix7_35t/bsp/libwrap/syscalls.o differ diff --git a/examples/shakti-sdk_uart-hello/.pio/build/artix7_35t/bsp/libwrap/util.o b/examples/shakti-sdk_uart-hello/.pio/build/artix7_35t/bsp/libwrap/util.o new file mode 100644 index 0000000..5e933c9 Binary files /dev/null and b/examples/shakti-sdk_uart-hello/.pio/build/artix7_35t/bsp/libwrap/util.o differ diff --git a/examples/shakti-sdk_uart-hello/.pio/build/artix7_35t/bsp/third_party/artix7_35t/uart.o b/examples/shakti-sdk_uart-hello/.pio/build/artix7_35t/bsp/third_party/artix7_35t/uart.o new file mode 100644 index 0000000..c725948 Binary files /dev/null and b/examples/shakti-sdk_uart-hello/.pio/build/artix7_35t/bsp/third_party/artix7_35t/uart.o differ diff --git a/examples/shakti-sdk_uart-hello/.pio/build/artix7_35t/bsp/third_party/libartix7_35t.a b/examples/shakti-sdk_uart-hello/.pio/build/artix7_35t/bsp/third_party/libartix7_35t.a new file mode 100644 index 0000000..a8a9262 Binary files /dev/null and b/examples/shakti-sdk_uart-hello/.pio/build/artix7_35t/bsp/third_party/libartix7_35t.a differ diff --git a/examples/shakti-sdk_uart-hello/.pio/build/artix7_35t/drivers/clic/clic_driver.o b/examples/shakti-sdk_uart-hello/.pio/build/artix7_35t/drivers/clic/clic_driver.o new file mode 100644 index 0000000..61c9e2f Binary files /dev/null and b/examples/shakti-sdk_uart-hello/.pio/build/artix7_35t/drivers/clic/clic_driver.o differ diff --git a/examples/shakti-sdk_uart-hello/.pio/build/artix7_35t/drivers/i2c/i2c_driver.o b/examples/shakti-sdk_uart-hello/.pio/build/artix7_35t/drivers/i2c/i2c_driver.o new file mode 100644 index 0000000..b4d496c Binary files /dev/null and b/examples/shakti-sdk_uart-hello/.pio/build/artix7_35t/drivers/i2c/i2c_driver.o differ diff --git a/examples/shakti-sdk_uart-hello/.pio/build/artix7_35t/drivers/libclic.a b/examples/shakti-sdk_uart-hello/.pio/build/artix7_35t/drivers/libclic.a new file mode 100644 index 0000000..88e0cd3 Binary files /dev/null and b/examples/shakti-sdk_uart-hello/.pio/build/artix7_35t/drivers/libclic.a differ diff --git a/examples/shakti-sdk_uart-hello/.pio/build/artix7_35t/drivers/libi2c.a b/examples/shakti-sdk_uart-hello/.pio/build/artix7_35t/drivers/libi2c.a new file mode 100644 index 0000000..bee3a53 Binary files /dev/null and b/examples/shakti-sdk_uart-hello/.pio/build/artix7_35t/drivers/libi2c.a differ diff --git a/examples/shakti-sdk_uart-hello/.pio/build/artix7_35t/drivers/libreadme.md b/examples/shakti-sdk_uart-hello/.pio/build/artix7_35t/drivers/libreadme.md new file mode 100644 index 0000000..8b277f0 --- /dev/null +++ b/examples/shakti-sdk_uart-hello/.pio/build/artix7_35t/drivers/libreadme.md @@ -0,0 +1 @@ +! diff --git a/examples/shakti-sdk_uart-hello/.pio/build/artix7_35t/firmware.elf b/examples/shakti-sdk_uart-hello/.pio/build/artix7_35t/firmware.elf new file mode 100644 index 0000000..84d015d Binary files /dev/null and b/examples/shakti-sdk_uart-hello/.pio/build/artix7_35t/firmware.elf differ diff --git a/examples/shakti-sdk_uart-hello/.pio/build/artix7_35t/src/hello.o b/examples/shakti-sdk_uart-hello/.pio/build/artix7_35t/src/hello.o new file mode 100644 index 0000000..3e173a7 Binary files /dev/null and b/examples/shakti-sdk_uart-hello/.pio/build/artix7_35t/src/hello.o differ diff --git a/examples/shakti-sdk_uart-hello/.pio/build/structure.hash b/examples/shakti-sdk_uart-hello/.pio/build/structure.hash new file mode 100644 index 0000000..bf759b8 --- /dev/null +++ b/examples/shakti-sdk_uart-hello/.pio/build/structure.hash @@ -0,0 +1 @@ +7c92b1acb5ab12cfce810c6f1054fa00b4afe69b \ No newline at end of file diff --git a/examples/shakti-sdk_uart-hello/.travis.yml b/examples/shakti-sdk_uart-hello/.travis.yml new file mode 100644 index 0000000..7c486f1 --- /dev/null +++ b/examples/shakti-sdk_uart-hello/.travis.yml @@ -0,0 +1,67 @@ +# Continuous Integration (CI) is the practice, in software +# engineering, of merging all developer working copies with a shared mainline +# several times a day < https://docs.platformio.org/page/ci/index.html > +# +# Documentation: +# +# * Travis CI Embedded Builds with PlatformIO +# < https://docs.travis-ci.com/user/integration/platformio/ > +# +# * PlatformIO integration with Travis CI +# < https://docs.platformio.org/page/ci/travis.html > +# +# * User Guide for `platformio ci` command +# < https://docs.platformio.org/page/userguide/cmd_ci.html > +# +# +# Please choose one of the following templates (proposed below) and uncomment +# it (remove "# " before each line) or use own configuration according to the +# Travis CI documentation (see above). +# + + +# +# Template #1: General project. Test it using existing `platformio.ini`. +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# install: +# - pip install -U platformio +# - platformio update +# +# script: +# - platformio run + + +# +# Template #2: The project is intended to be used as a library with examples. +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# env: +# - PLATFORMIO_CI_SRC=path/to/test/file.c +# - PLATFORMIO_CI_SRC=examples/file.ino +# - PLATFORMIO_CI_SRC=path/to/test/directory +# +# install: +# - pip install -U platformio +# - platformio update +# +# script: +# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/examples/shakti-sdk_uart-hello/README.rst b/examples/shakti-sdk_uart-hello/README.rst new file mode 100644 index 0000000..7e22528 --- /dev/null +++ b/examples/shakti-sdk_uart-hello/README.rst @@ -0,0 +1,38 @@ +.. Copyright 2014-present PlatformIO + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +How to build PlatformIO based project +===================================== + +1. `Install PlatformIO Core `_ +2. Download `development platform with examples `_ +3. Extract ZIP archive +4. Run these commands: + +.. code-block:: bash + + # Change directory to example + > cd platform-shakti/examples/shakti-sdk_uart-hello + + # Build project + > platformio run + + # Upload firmware + > platformio run --target upload + + # Build specific environment + > platformio run -e artix7_35t + + # Upload firmware for the specific environment + > platformio run -e artix7_35t --target upload + + # Clean build files + > platformio run --target clean diff --git a/examples/shakti-sdk_uart-hello/include/README b/examples/shakti-sdk_uart-hello/include/README new file mode 100644 index 0000000..194dcd4 --- /dev/null +++ b/examples/shakti-sdk_uart-hello/include/README @@ -0,0 +1,39 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the usual convention is to give header files names that end with `.h'. +It is most portable to use only letters, digits, dashes, and underscores in +header file names, and at most one dot. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/examples/shakti-sdk_uart-hello/lib/README b/examples/shakti-sdk_uart-hello/lib/README new file mode 100644 index 0000000..6debab1 --- /dev/null +++ b/examples/shakti-sdk_uart-hello/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into executable file. + +The source code of each library should be placed in a an own separate directory +("lib/your_library_name/[here are source files]"). + +For example, see a structure of the following two libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +and a contents of `src/main.c`: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +PlatformIO Library Dependency Finder will find automatically dependent +libraries scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/examples/shakti-sdk_uart-hello/platformio.ini b/examples/shakti-sdk_uart-hello/platformio.ini new file mode 100644 index 0000000..a0e1110 --- /dev/null +++ b/examples/shakti-sdk_uart-hello/platformio.ini @@ -0,0 +1,25 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter, extra scripting +; Upload options: custom port, speed and extra flags +; Library options: dependencies, extra library storages +; +; Please visit documentation for the other options and examples +; http://docs.platformio.org/page/projectconf.html + +[platformio] +description = + A simple "Hello, World" example with UART peripheral + +[env:artix7_35t] +platform = shakti +framework = shakti-sdk +board = artix7_35t +monitor_speed = 115200 + +[env:artix7_100t] +platform = shakti +framework = shakti-sdk +board = artix7_100t +monitor_speed = 115200 + diff --git a/examples/shakti-sdk_uart-hello/src/hello.c b/examples/shakti-sdk_uart-hello/src/hello.c new file mode 100644 index 0000000..ce9990c --- /dev/null +++ b/examples/shakti-sdk_uart-hello/src/hello.c @@ -0,0 +1,33 @@ +/*************************************************************************** +* Project : shakti devt board +* Name of the file : hello.c +* Created date : 26.02.2019 +* Brief Description of file : Does the printing of hello with the help of uart communication protocol. +* Name of Author : Sathya Narayanan N +* Email ID : sathya281@gmail.com + + Copyright (C) 2019 IIT Madras. All rights reserved. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +***************************************************************************/ +#include "uart.h"//Includes the definitions of uart communication protocol// + + +void main() +{ + printf("Hello world !\n"); +} + + diff --git a/examples/shakti-sdk_uart-hello/test/README b/examples/shakti-sdk_uart-hello/test/README new file mode 100644 index 0000000..df5066e --- /dev/null +++ b/examples/shakti-sdk_uart-hello/test/README @@ -0,0 +1,11 @@ + +This directory is intended for PIO Unit Testing and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PIO Unit Testing: +- https://docs.platformio.org/page/plus/unit-testing.html diff --git a/misc/svd/FE310.svd b/misc/svd/FE310.svd new file mode 100644 index 0000000..04132d0 --- /dev/null +++ b/misc/svd/FE310.svd @@ -0,0 +1,1110 @@ + + + SiFive + SiFive + FE310 + Freedom Everywhere + + E31 CPU Coreplex, high-performance, 32-bit RV32IMAC core + + + 8 + 32 + 32 + 0x00000000 + 0xFFFFFFFF + + + E31 + little + + + + + + PLIC + Platform-Level Interrupt Controller. + 0x0C000000 + PLIC + 32 + read-write + + + 0 + 0x200008 + registers + + + + + + 52 + 4 + PRIORITY[%s] + PLIC Interrupt Priority Register. + 0x000000 + + PRIORITY02 + + + + + PENDING_1 + PLIC Interrupt Pending Register 1. + 0x001000 + + + + PENDING_2 + PLIC Interrupt Pending Register 2. + 0x001004 + + + + ENABLE_1 + PLIC Interrupt Enable Register 1. + 0x002000 + + + + ENABLE_2 + PLIC Interrupt Enable Register 2. + 0x002004 + + + + THRESHOLD + PLIC Interrupt Priority Threshold Register. + 0x200000 + + THRESHOLD02 + + + + + CLAIM + PLIC Claim/Complete Register. + 0x200004 + + + + + + + CLINT + Core Local Interruptor. + 0x02000000 + CLINT + 32 + read-write + + + 0 + 0x10000 + registers + + + + + + MSIP + Machine Software Interrupt Pending Register. + 0x0000 + + + + MTIMECMP_LO + Machine Timer Compare Register Low. + 0x4000 + + + + MTIMECMP_HI + Machine Timer Compare Register High. + 0x4004 + + + + MTIME_LO + Machine Timer Register Low. + 0xBFF8 + + + + MTIME_HI + Machine Timer Register High. + 0xBFFC + + + + + + + GPIO0 + General purpose input/output controller. + 0x10012000 + GPIO + 32 + read-write + + + 0 + 0x1000 + registers + + + GPIO_0_IRQ8 + GPIO_1_IRQ9 + GPIO_2_IRQ10 + GPIO_3_IRQ11 + GPIO_4_IRQ12 + GPIO_5_IRQ13 + GPIO_6_IRQ14 + GPIO_7_IRQ15 + GPIO_8_IRQ16 + GPIO_9_IRQ17 + GPIO_10_IRQ18 + GPIO_11_IRQ19 + GPIO_12_IRQ20 + GPIO_12_IRQ21 + GPIO_14_IRQ22 + GPIO_14_IRQ23 + GPIO_16_IRQ24 + GPIO_17_IRQ25 + GPIO_18_IRQ26 + GPIO_19_IRQ27 + GPIO_20_IRQ28 + GPIO_21_IRQ29 + GPIO_22_IRQ30 + GPIO_23_IRQ31 + GPIO_24_IRQ32 + GPIO_25_IRQ33 + GPIO_26_IRQ34 + GPIO_27_IRQ35 + GPIO_28_IRQ36 + GPIO_28_IRQ37 + GPIO_30_IRQ38 + GPIO_31_IRQ39 + + + + VALUE + Pin value. + 0x000 + + PIN000 + PIN111 + PIN222 + PIN333 + PIN444 + PIN555 + PIN666 + PIN777 + PIN888 + PIN999 + PIN101010 + PIN111111 + PIN121212 + PIN131313 + PIN141414 + PIN151515 + PIN161616 + PIN171717 + PIN181818 + PIN191919 + PIN202020 + PIN212121 + PIN222222 + PIN232323 + PIN242424 + PIN252525 + PIN262626 + PIN272727 + PIN282828 + PIN292929 + PIN303030 + PIN313131 + + + + INPUT_EN + Pin input enable. + 0x004 + + + OUTPUT_EN + Pin output enable. + 0x008 + + + PORT + Output port value. + 0x00C + + + PULLUP + Internal Pull-Up enable. + 0x010 + + + DRIVE + Drive Strength. + 0x014 + + + RISE_INT_EN + Rise interrupt enable. + 0x018 + + + RISE_INT_PEMD + Rise interrupt pending. + 0x01C + + + FALL_INT_EN + Fall interrupt enable. + 0x020 + + + FALL_INT_PEND + Fall interrupt pending. + 0x024 + + + HIGH_INT_EN + High interrupt enable. + 0x028 + + + HIGH_INT_PEND + High interrupt pending. + 0x02C + + + LOW_INT_EN + Low interrupt enable. + 0x030 + + + LOW_INT_PEND + Low interrupt pending. + 0x034 + + + IO_FUNC_EN + HW I/O function enable. + 0x038 + + + IO_FUNC_SEL + HW I/O function select. + 0x03C + + + OUT_XOR + Output XOR (invert). + 0x040 + + + + + + QSPI0 + Serial Peripheral Interface. + 0x10014000 + SPI + 32 + read-write + + + 0 + 0x1000 + registers + + + QSPI0_IRQ5 + + + + + SCKDIV + Serial Clock Divisor Register. + 0x000 + + SCALE011 + + + + + SCKMODE + Serial Clock Mode Register. + 0x004 + + + PHA00 + Serial Clock Phase + + CPHA + + 0 + + Data is sampled on the leading edge of SCK and shifted on the trailing edge of SCK. + + 0 + + + 1 + + Data is shifted on the leading edge of SCK and sampled on the trailing edge of SCK. + + 1 + + + + + POL11 + Serial Clock Polarity + + CPOL + + 0 + Inactive state of SCK is logical 0. + 0 + + + 1 + Inactive state of SCK is logical 1. + 1 + + + + + + + + CSID + Chip Select ID Register. + 0x010 + + + + CSDEF + Chip Select Default Register. + 0x014 + + + + CSMODE + Chip Select Mode Register. + 0x018 + + + MODE01 + + Chip_Select_Modes + + AUTO + Assert/de-assert CS at the beginning/end of each frame. + 0 + + + HOLD + Keep CS continuously asserted after the initial frame. + 2 + + + OFF + Disable hardware control of the CS pin. + 3 + + + + + + + + DELAY0 + Delay Control Register 0. + 0x028 + + CSSCK07 + SCKCS1623 + + + + + DELAY1 + Delay Control Register 1. + 0x02C + + INTERCS07 + INTERXFR1623 + + + + + FMT + Frame Format Register. + 0x040 + + + PROTO01 + + SPI_Protocol + + Single + Data Pins: DQ0 (MOSI), DQ1 (MISO). + 0 + + + Dual + Data Pins: DQ0, DQ1. + 1 + + + Quad + Data Pins: DQ0, DQ1, DQ2, DQ3. + 2 + + + + + ENDIAN22 + + SPI_Endianness + + MSB_First + Tansmit most-significant bit first. + 0 + + + LSB_First + Transmit least-significant bit first. + 1 + + + + + DIR33 + + SPI_IO_Direction + + RX + + For dual and quad protocols, the DQ pins are tri-stated. + For the single protocol, the DQ0 pin is driven with the transmit data as normal. + + 0 + + + TX + The receive FIFO is not populated. + 1 + + + + + LEN1619 + + + + + + TXDATA + Transmit Data Register. + 0x048 + + DATA07 + FULL3131 + + + + + RXDATA + Receive Data Register. + 0x04C + + DATA07 + EMPTY3131 + + + + + TXMARK + Transmit Watermark Register. + 0x050 + + TXMARK02 + + + + + RXMARK + Receive Watermark Register. + 0x054 + + RXMARK02 + + + + + IE + SPI Interrupt Enable Register. + 0x070 + + TXWM00 + RXWM11 + + + + + IP + SPI Interrupt Pending Register. + 0x074 + + TXWM00 + RXWM11 + + + + + FCTRL + SPI Flash Interface Control Register. + 0x060 + + ENABLE00 + + + + + FFMT + SPI Flash Instruction Format Register. + 0x064 + + CMD_EN00 + ADDR_LEN13 + PAD_CNT47 + CMD_PROTO89 + ADDR_PROTO1011 + DATA_PROTO1213 + CMD_CODE1623 + PAD_CODE2431 + + + + + + + + + QSPI1 + Serial Peripheral Interface. + 0x10024000 + SPI + QSPI1_IRQ6 + + + + QSPI2 + Serial Peripheral Interface. + 0x10034000 + SPI + QSPI2_IRQ7 + + + + UART0 + Universal Asynchronous Receiver/Transmitter. + 0x10013000 + UART + 32 + read-write + + + 0 + 0x1000 + registers + + + UART0_IRQ3 + + + + TXDATA + Transmit Data Register. + 0x000 + + DATA07 + FULL3131 + + + + RXDATA + Receive Data Register. + 0x004 + + DATA07 + EMPTY3131 + + + + TXCTRL + Transmit Control Register. + 0x008 + + ENABLE00 + NSTOP11 + TXCNT1618 + + + + RXCTRL + Receive Control Register. + 0x00C + + ENABLE00 + RXCNT1618 + + + + IP + Interrupt Pending Register. + 0x0010 + + TXWM00 + RXWM11 + + + + IE + Interrupt Enable Register. + 0x0014 + + + DIV + Baud Rate Divisor Register (BAUD = Fin / (DIV + 1)). + + 0x0018 + + DIV015 + + + + + + UART1 + Universal Asynchronous Receiver/Transmitter. + 0x10023000 + UART + UART1_IRQ4 + + + + PWM0 + Pulse-Width Modulation. + 0x10015000 + PWM + 32 + read-write + + + 0 + 0x1000 + registers + + + PWMO_CMP0_IRQ40 + PWMO_CMP1_IRQ41 + PWMO_CMP2_IRQ42 + PWMO_CMP3_IRQ43 + + + + CONFIG + PWM Configuration Register. + 0x000 + + SCALE03 + STICKY88 + ZEROCMP99 + DEGLITCH1010 + ENALWAYS1212 + ENONESHOT1313 + + CMP_CENTER01616 + CMP_CENTER11717 + CMP_CENTER21818 + CMP_CENTER31919 + + CMP_GANG02424 + CMP_GANG12525 + CMP_GANG22626 + CMP_GANG32727 + + CMP_IP02828 + CMP_IP12929 + CMP_IP23030 + CMP_IP33131 + + + + + COUNT + PWM Count Register. + 0x008 + + CNT030 + + + + + SCALE_COUNT + PWM Scaled Counter Register. + 0x010 + + CNT015 + + + + + COMPARE0 + PWM Compare Register. + 0x020 + + COMPARE015 + + + + COMPARE1 + 0x024 + + + COMPARE2 + 0x028 + + + COMPARE3 + 0x02C + + + + + + PWM1 + 0x10025000 + PWM + PWM1_CMP0_IRQ44 + PWM1_CMP1_IRQ45 + PWM1_CMP2_IRQ46 + PWM1_CMP3_IRQ47 + + + PWM2 + 0x10035000 + PWM + PWM2_CMP0_IRQ48 + PWM2_CMP1_IRQ49 + PWM2_CMP2_IRQ50 + PWM2_CMP3_IRQ51 + + + + WDT + Watchdog Timer. + 0x10000000 + WDT + 32 + read-write + + + 0 + 0x40 + registers + + + Watchdog_IRQ1 + + + + + COUNT + Watchdog Count Register. + 0x08 + + CNT030 + + + + + CONFIG + Watchdog Configuration Register. + 0x00 + + SCALE03 + RSTEN88 + ZEROCMP99 + ENALWAYS1212 + ENCOREAWAKE1313 + CMP_IP2828 + + + + + SCALE_COUNT + Watchdog Scaled Counter Register. + 0x10 + + CNT015 + + + + + COMPARE + Watchdog Compare Register. + 0x20 + + CMP015 + + + + + KEY + Watchdog Key Register. + 0x1C + + + + FEED + Watchdog Feed Address. + 0x18 + + + + + + + RTC + Real-Time Clock. + 0x10000040 + RTC + 32 + read-write + + + 0 + 0x30 + registers + + + RTC_IRQ2 + + + + + HI + RTC Count Register High. + 0x0C + + CNT015 + + + + + LO + RTC Count Register Low. + 0x08 + + + + CONFIG + RTC Configuration Register. + 0x00 + + SCALE03 + ENALWAYS1212 + CMP_IP2828 + + + + + SCALE_COUNT + RTC Scaled Counter Register. + 0x10 + + + + COMPARE + RTC Compare Register. + 0x20 + + + + + + + AON + AON Clock Configuration. + 0x10000070 + AON + 32 + read-write + + + 0 + 0x10 + registers + + + + + + LFROSCCFG + LF Ring Oscillator Configuration Register. + 0x0 + + DIV05 + TRIM1620 + ENABLE3030 + READY3131 + + + + + + + + BACKUP + Backup Registers. + 0x10000080 + BACKUP + 32 + read-write + + + 0 + 0x80 + registers + + + + + + 32 + 4 + Backup[%s] + 0x00 + + + + + + + PMU + Power Management Unit. + 0x10000100 + PMU + 32 + read-write + + + 0 + 0x50 + registers + + + + + + 8 + 4 + WAKEUPI[%s] + Wakeup program instructions. + 0x00 + + DELAY03 + PMU_OUT_044 + PMU_OUT_155 + CORERST77 + HFCLKRST88 + + + + + SLEEPI[%s] + Sleep program instructions. + 0x20 + + + + IE + PMU interrupt enables. + 0x40 + + RTC11 + DWAKEUP22 + + + + + CAUSE + PMU wakeup cause. + 0x44 + + + WAKEUP_CAUSE01 + + Wakeup_Cause_Values + + Reset + Reset. + 0 + + + RTC + RTC Wakeup. + 1 + + + DWakeup + Digital input wakeup. + 2 + + + + + RESET_CAUSE89 + + Reset_Cause_Values + + External + External reset. + 1 + + + Watchdog + Watchdog timer reset. + 2 + + + + + + + + SLEEP + Initiate sleep sequence. + 0x48 + + + + KEY + PMU key register. + 0x4C + + + + + + + diff --git a/platform.json b/platform.json new file mode 100644 index 0000000..5682059 --- /dev/null +++ b/platform.json @@ -0,0 +1,51 @@ +{ + "name": "shakti", + "title": "Shakti", + "description": "Shakti is an open-source initiative by the RISE group at IIT-Madras, which is not only building open source, production grade processors, but also associated components like interconnect fabrics, verification tools, storage controllers, peripheral IPs and SOC tools.", + "url": "https://shakti.org.in/", + "homepage": "http://platformio.org/platforms/shakti", + "license": "Apache-2.0", + "engines": { + "platformio": "<5" + }, + "repository": { + "type": "git", + "url": "https://github.com/platformio/platform-shakti.git" + }, + "version": "0.0.0", + "packageRepositories": [ + "https://dl.bintray.com/platformio/dl-packages/manifest.json", + "http://dl.platformio.org/packages/manifest.json" + ], + "frameworks": { + "shakti-sdk": { + "package": "framework-shakti-sdk", + "script": "builder/frameworks/shakti-sdk.py" + } + }, + "packages": { + "toolchain-riscv": { + "type": "toolchain", + "version": "~1.80200.0" + }, + "framework-shakti-sdk": { + "type": "framework", + "version": "~0.0.190709" + }, + "tool-openocd-riscv": { + "optional": true, + "type": "uploader", + "version": "~2.1000.0" + }, + "tool-jlink": { + "type": "uploader", + "optional": true, + "version": "^1.63208.0" + }, + "tool-qemu-riscv": { + "type": "debugger", + "optional": true, + "version": "~1.30100.0" + } + } +} diff --git a/platform.py b/platform.py new file mode 100644 index 0000000..9374690 --- /dev/null +++ b/platform.py @@ -0,0 +1,103 @@ +# Copyright 2014-present PlatformIO +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from os.path import join +from platform import system + +from platformio.managers.platform import PlatformBase + + +class ShaktiPlatform(PlatformBase): + + def get_boards(self, id_=None): + result = PlatformBase.get_boards(self, id_) + if not result: + return result + if id_: + return self._add_default_debug_tools(result) + else: + for key, value in result.items(): + result[key] = self._add_default_debug_tools(result[key]) + return result + + def _add_default_debug_tools(self, board): + debug = board.manifest.get("debug", {}) + upload_protocols = board.manifest.get("upload", {}).get( + "protocols", []) + if "tools" not in debug: + debug['tools'] = {} + + tools = ("ftdi", "jlink", "qemu") + for link in tools: + if link not in upload_protocols or link in debug['tools']: + continue + if link == "jlink": + assert debug.get("jlink_device"), ( + "Missed J-Link Device ID for %s" % board.id) + debug['tools'][link] = { + "server": { + "package": "tool-jlink", + "arguments": [ + "-singlerun", + "-if", "JTAG", + "-select", "USB", + "-speed", "1000", + "-jtagconf", "-1,-1", + "-device", debug.get("jlink_device"), + "-port", "2331" + ], + "executable": ("JLinkGDBServerCL.exe" + if system() == "Windows" else + "JLinkGDBServer") + }, + "onboard": link in debug.get("onboard_tools", []) + } + + elif link == "qemu": + machine64bit = "64" in board.get("build.mabi") + debug['tools'][link] = { + "server": { + "package": "tool-qemu-riscv", + "arguments": [ + "-nographic", + "-machine", "sifive_%s" % ( + "u" if machine64bit else "e"), + "-d", "unimp,guest_errors", + "-gdb", "tcp::1234", + "-S" + ], + "executable": "bin/qemu-system-riscv%s" % ( + "64" if machine64bit else "32") + }, + "onboard": True + } + else: + server_args = [ + "-s", "$PACKAGE_DIR/share/openocd/scripts", + "-f", join( + self.get_package_dir("framework-shakti-sdk"), + "bsp", "third_party", board.id, "spike.cfg") + ] + debug['tools'][link] = { + "server": { + "package": "tool-openocd-riscv", + "executable": "bin/openocd", + "arguments": server_args + }, + "onboard": link in debug.get("onboard_tools", []), + "init_cmds": debug.get("init_cmds", None) + } + + board.manifest['debug'] = debug + return board