├── .gitignore ├── .gitmodules ├── README.asciidoc ├── build ├── 99-grisp.rules ├── build-bsp.sh ├── build-libbsd.sh ├── build-libgrisp.sh ├── build-libinih.sh ├── build-openocd.sh ├── build-toolchain.sh ├── build.sh ├── configuration.sh ├── create-package.sh ├── debug-load-flash.sh ├── debug-reset.sh ├── debug-set-gpnvm.sh ├── debug-start-gdb.sh ├── debug-start-openocd.sh ├── setup_manual_build_env.sh └── src │ ├── bsp.mk │ ├── libbsd.ini │ ├── openocd-0.10.0.tar.bz2 │ ├── openocd-grisp.cfg │ ├── start.gdb │ └── waf-2.0.2 ├── grisp-bootloader ├── Makefile ├── binaries │ └── bootloader.exe ├── init.c ├── linkcmds.bootloader └── slim-down.h ├── grisp-fatbench ├── Makefile ├── fatbench-libbsd-4b1426368b973f008cae17e51d7562f2fe102a5b.txt ├── fatbench-libbsd-ef5d536f840e01cb7a9edfd9f72dd0f058fb62aa.txt ├── fatbench.c ├── fatbench.h └── init.c ├── grisp-rtems-hw-test ├── Makefile ├── init.c └── sd-card-content │ ├── grisp.ini │ └── rtems-hw-test.bin ├── grisp-sd-sample ├── Makefile ├── init.c └── wpa_supplicant.conf.example ├── grisp-simple-sample ├── Makefile ├── init.c └── sample-binaries │ ├── grisp.ini │ └── simple-sample.bin └── libinih └── Makefile /.gitignore: -------------------------------------------------------------------------------- 1 | build/*.log 2 | b-* 3 | rtems-install 4 | *.tar.gz 5 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "rtems"] 2 | path = rtems 3 | url = https://github.com/grisp/rtems 4 | branch = 5 5 | [submodule "rtems-libbsd"] 6 | path = rtems-libbsd 7 | url = https://github.com/grisp/rtems-libbsd 8 | branch = 5-freebsd-12 9 | [submodule "rtems-source-builder"] 10 | path = rtems-source-builder 11 | url = git://git.rtems.org/rtems-source-builder.git 12 | branch = 5 13 | [submodule "libinih/inih"] 14 | path = libinih/inih 15 | url = https://github.com/grisp/inih 16 | branch = master 17 | [submodule "libgrisp"] 18 | path = libgrisp 19 | url = https://github.com/grisp/libgrisp 20 | branch = master 21 | -------------------------------------------------------------------------------- /README.asciidoc: -------------------------------------------------------------------------------- 1 | GRISP 2 | ===== 3 | 4 | :toc: 5 | == Prerequisites 6 | 7 | - the +xz+ decompression tool needs to be installed 8 | - the +zlib+ development files are necessary 9 | - +bison+, +flex+ and +texinfo+ 10 | - to check for some of RTEMS source builders prerequisites 11 | 12 | git submodule init 13 | git submodule update rtems-source-builder 14 | cd rtems-source-builder 15 | ./source-builder/sb-check 16 | 17 | == Quick Start Guide 18 | 19 | You can build the whole toolchain by running +./build/build.sh+. See 20 | <> for more details. 21 | 22 | To build the simple RTEMS sample application, go to +grisp-simple-sample+ and 23 | call +make+. 24 | 25 | If you want to use OpenOCD, you have to make sure that you have read and write 26 | access to the USB device. On a Linux system using udev, you can copy the 27 | udev-rule from build/99-grisp.rule to /etc/udev/rules.d/ for that. The rule also 28 | provides a fixed name for the serial console (/dev/ttyGRiSP). 29 | 30 | == Directory Structure 31 | 32 | The following directory structure is used in this project: 33 | 34 | - build: scripts for building the tool chain and libraries 35 | - grisp-XYZ: applications 36 | - libXYZ: non-RTEMS libraries 37 | - rtems-XYZ: software and libraries related to RTEMS 38 | - README.asciidoc: this document 39 | 40 | == Building 41 | 42 | The complete toolchain is built by running +./build/build.sh+. This will do the 43 | following: 44 | 45 | - check out the necessary git submodules 46 | - bootstrap RTEMS 47 | - build and install the toolchain 48 | - build and install the RTEMS BSP 49 | - build and install necessary libs 50 | 51 | All installations are made inside the +rtems-install+ subdirectory in the base 52 | directory of the repository. To change the install location edit the +PREFIX+ in 53 | +build/configuration.sh+. 54 | 55 | == git Repository Structure 56 | 57 | The +grisp-software+ project pulls in a number of git submodules (like RTEMS). 58 | Most of these submodules have been forked with no or only minimal changes. The 59 | branches in the submodules follow the following guidelines: 60 | 61 | - +master+ tracks the upstream development of the project. 62 | - If patches are necessary, they will be added on branches and the commits on 63 | the branch are referenced in +grisp-software+. 64 | 65 | Here is an example for how a git tree of a submodule could look like: 66 | 67 | ---- 68 | o---o---o---B'--o---o---o---o---o---o master (clone of upstream/master) 69 | \ \ 70 | \ A'--C' grisp-20171110-xyz 71 | \ 72 | A---B---C grisp-20171020-xyz 73 | ---- 74 | 75 | In that example +grisp-20171020-xyz+ is a version of the software with some 76 | adaptions for GRiSP. If for example a (maybe slightly modified) version of the 77 | patch +B+ has been accepted in the upstream repository and GRiSP now wants to 78 | update to a newer version of the master, +B+ is no longer necessary. Therefore 79 | the new +grisp-20171110-xyx+ no longer contains +B+ but (adapted) versions of 80 | +A+ and +C+ are still necessary. 81 | 82 | The old +grisp-20171020-xyz+ is still be kept so that a old version of the 83 | +grisp-software+ repository can still access the commits. 84 | 85 | That structure makes it relatively easy to see the exact differences to the 86 | upstream version and which patches might should be integrated into it in the 87 | future. The disadvantage is that it will leave quite a number of old branches 88 | that are still necessary so that older +grisp-software+ revisions can reference 89 | them. 90 | 91 | === Re-Building only target specific RTEMS libs 92 | 93 | Since building the toolchain takes a lot of time and since the toolchain 94 | changes less often than the rest of the system you can also just rebuild 95 | RTEMS and its libs. 96 | 97 | To do that delete the 98 | `rtems-install/rtems-4.12/arm-rtems4.12/atsamv` directory and then do a 99 | 100 | ./build/build.sh --no-toolchain --no-bootstrap 101 | 102 | === Updating the submodules from github 103 | 104 | When you want to rebuild with some new version from the Git repos you need to make 105 | sure that you update the sumodules: 106 | 107 | git pull 108 | git submodule update 109 | 110 | === Cleaning 111 | 112 | Normally, running `./build/build.sh` (or any other of the individual build 113 | scripts in the `./build` folder) should rebuild without the need for cleaning. 114 | 115 | However, if you want a clean start you can delete the `rtems-install` folder 116 | which will delete all created binaries, libraries and header files. 117 | 118 | To make a complete reset of the whole repository, use the following commands: 119 | 120 | [source,shell] 121 | ---- 122 | git co . # Reverts all uncommited changes 123 | git clean -dxn # gives a preview, what unversioned files would be deleted 124 | git clean -dxf # deletes everything that is not under version control 125 | ---- 126 | 127 | == Boot Loader 128 | 129 | The boot loader will try to initialize and mount the SD card. In case this is 130 | successful it tries to read the +grisp.ini+ configuration file from the SD root 131 | directory. 132 | 133 | Sample grisp.ini (showing the default values): 134 | [source,ini] 135 | ---- 136 | [boot] 137 | timeout_in_seconds = 3 138 | image_path = /media/mmcsd-0-0/grisp.bin 139 | ---- 140 | 141 | All values are optional and in case something is missing default values will be 142 | used (presented in the listing above). Once the timeout expired without user 143 | input the automatic application load sequence starts. 144 | 145 | === Updating the Boot Loader 146 | 147 | For updating the bootloader build OpenOCD by running `./build/build-openocd.sh`. 148 | You can then update the boot loader with the following call: 149 | 150 | ---- 151 | ./build/debug-load-flash.sh grisp-bootloader/binaries/bootloader.exe 152 | ---- 153 | 154 | The process will need quite some time (about 30 seconds for loading and about a 155 | minute for verify). 156 | 157 | If OpenOCD is failing due to libusb related issues, you might need to make 158 | adjustments specific to your operating system. Please see the libusb FAQ: 159 | https://github.com/libusb/libusb/wiki/FAQ 160 | 161 | == Debugging 162 | 163 | It is possible to debug an application using the on-board FTDI to SWD adapter. 164 | First build and install OpenOCD by running `./build/build-openocd.sh`. 165 | 166 | Place a SD with some sample application into the target. This takes care that 167 | the bootloader starts an application. The debug scripts will wait for this and 168 | then overwrite the application that is booted by the bootloader with the one 169 | that should be debugged. 170 | 171 | After that you should start openocd on one console using 172 | `./build/debug-start-openocd.sh`. This starts an GDB-Server. Do not terminate 173 | the process. You can then start a gdb that connects to the server using 174 | `./build/debug-start-gdb.sh path/to/app.exe`. The script adds a `reset` command 175 | to the normal gdb that restarts the target and reloads the application. Note 176 | that for bigger applications, that might need quite some time. 177 | 178 | == WiFi 179 | 180 | By default, the wpa_supplicant.conf from the root of the SD card will be used. 181 | For a default WPA2 encrypted network, the file should look like follows: 182 | 183 | ---- 184 | network={ 185 | ssid="mynetwork" 186 | key_mgmt=WPA-PSK 187 | psk="secret" 188 | } 189 | ---- 190 | -------------------------------------------------------------------------------- /build/99-grisp.rules: -------------------------------------------------------------------------------- 1 | # create symlink for serial port 2 | ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6010", ATTRS{product}=="Grisp", ENV{ID_USB_INTERFACE_NUM}=="01", SUBSYSTEM=="tty", SYMLINK+="ttyGRiSP" 3 | 4 | # allow access for everyone (necessary to use openocd) 5 | ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6010", ATTRS{product}=="Grisp", MODE="666" 6 | -------------------------------------------------------------------------------- /build/build-bsp.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env sh 2 | 3 | # be more verbose 4 | set -x 5 | # exit on wrong command and undefined variables 6 | set -e -u 7 | 8 | # find out own directory 9 | SCRIPTPATH=$(readlink -- "$0" || echo "$0") 10 | SCRIPTDIR=$(CDPATH= cd -- "$(dirname -- "$SCRIPTPATH")" && pwd) 11 | PROJECTDIR="${SCRIPTDIR}/../" 12 | 13 | # Configuration 14 | . "${SCRIPTDIR}/configuration.sh" 15 | BUILD_DIR="${PROJECTDIR}/build/b-$BSP_NAME" 16 | export PATH="${PREFIX}/bin:${PATH}" 17 | 18 | # Evaluate options 19 | make_targets="all" 20 | for i in "$@" ; do 21 | case "$i" in 22 | clean) 23 | rm -rf "$BUILD_DIR" 24 | ;; 25 | install) 26 | make_targets="all install" 27 | ;; 28 | *) 29 | echo "Unexpected option: '$i'" 30 | exit 1 31 | ;; 32 | esac 33 | done 34 | 35 | # Create build directory 36 | mkdir -p "${BUILD_DIR}" 37 | cd "${BUILD_DIR}" 38 | 39 | # Configure 40 | "${RTEMS_SOURCE_DIR}/configure" \ 41 | "--target=${TARGET}" \ 42 | "--prefix=${PREFIX}" \ 43 | "--enable-rtemsbsp=${BSP_NAME}" \ 44 | "--enable-maintainer-mode" \ 45 | ${BSP_CONFIG_OPT} 46 | 47 | # Make 48 | make ${make_targets} 49 | 50 | # Generate .mk file 51 | mkdir -p "${PREFIX}/make/custom/" 52 | cat "${PROJECTDIR}/build/src/bsp.mk" | \ 53 | sed -e "s/##RTEMS_API##/$RTEMS_VERSION/g" \ 54 | -e "s/##RTEMS_BSP##/$BSP_NAME/g" \ 55 | -e "s/##RTEMS_CPU##/$RTEMS_CPU/g" \ 56 | > "${PREFIX}/make/custom/${BSP_NAME}.mk" 57 | -------------------------------------------------------------------------------- /build/build-libbsd.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env sh 2 | 3 | # be more verbose 4 | set -x 5 | # exit on wrong command and undefined variables 6 | set -e -u 7 | 8 | # find out own directory 9 | SCRIPTPATH=$(readlink -- "$0" || echo "$0") 10 | SCRIPTDIR=$(CDPATH= cd -- "$(dirname -- "$SCRIPTPATH")" && pwd) 11 | PROJECTDIR="${SCRIPTDIR}/../" 12 | 13 | # Configuration 14 | . "${SCRIPTDIR}/configuration.sh" 15 | export PATH="${PREFIX}/bin:${PATH}" 16 | 17 | cd "${LIBBSD_SOURCE_DIR}" 18 | 19 | if [ "$BSP_NAME" = "atsamv" ] 20 | then 21 | # ugly workaround to build the tests with external RAM 22 | if [ ! -e "${PREFIX}/${TARGET}/${BSP_NAME}/lib/linkcmds.org" ] 23 | then 24 | mv "${PREFIX}/${TARGET}/${BSP_NAME}/lib/linkcmds" \ 25 | "${PREFIX}/${TARGET}/${BSP_NAME}/lib/linkcmds.org" 26 | fi 27 | cp "${PREFIX}/${TARGET}/${BSP_NAME}/lib/linkcmds.sdram" \ 28 | "${PREFIX}/${TARGET}/${BSP_NAME}/lib/linkcmds" 29 | fi 30 | 31 | # Evaluate options 32 | DO_CLEAN=0 33 | DO_INSTALL=0 34 | for i in "$@" ; do 35 | case "$i" in 36 | clean) 37 | DO_CLEAN=1 38 | ;; 39 | install) 40 | DO_INSTALL=1 41 | ;; 42 | *) 43 | echo "Unexpected option: '$i'" 44 | exit 1 45 | ;; 46 | esac 47 | done 48 | 49 | # Build and install libbsd 50 | if [ $DO_CLEAN -ne 0 ] 51 | then 52 | if [ -e build ] 53 | then 54 | rm -rf build 55 | fi 56 | fi 57 | 58 | waf configure \ 59 | --prefix="${PREFIX}" \ 60 | --rtems-bsps="${RTEMS_CPU}/${BSP_NAME}" \ 61 | --buildset="${PROJECTDIR}/build/src/libbsd.ini" 62 | waf 63 | 64 | if [ $DO_INSTALL -ne 0 ] 65 | then 66 | waf install 67 | fi 68 | 69 | if [ "$BSP_NAME" = "atsamv" ] 70 | then 71 | # part 2 of ugly workaround to build the tests with external RAM 72 | mv "${PREFIX}/${TARGET}/${BSP_NAME}/lib/linkcmds.org" \ 73 | "${PREFIX}/${TARGET}/${BSP_NAME}/lib/linkcmds" 74 | fi 75 | -------------------------------------------------------------------------------- /build/build-libgrisp.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env sh 2 | 3 | # be more verbose 4 | set -x 5 | # exit on wrong command and undefined variables 6 | set -e -u 7 | 8 | # find out own directory 9 | SCRIPTPATH=$(readlink -- "$0" || echo "$0") 10 | SCRIPTDIR=$(CDPATH= cd -- "$(dirname -- "$SCRIPTPATH")" && pwd) 11 | PROJECTDIR="${SCRIPTDIR}/../" 12 | 13 | # Configuration 14 | . "${SCRIPTDIR}/configuration.sh" 15 | export PATH="${PREFIX}/bin:${PATH}" 16 | 17 | cd "${LIBGRISP_SOURCE_DIR}" 18 | make clean install 19 | -------------------------------------------------------------------------------- /build/build-libinih.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env sh 2 | 3 | # be more verbose 4 | set -x 5 | # exit on wrong command and undefined variables 6 | set -e -u 7 | 8 | # find out own directory 9 | SCRIPTPATH=$(readlink -- "$0" || echo "$0") 10 | SCRIPTDIR=$(CDPATH= cd -- "$(dirname -- "$SCRIPTPATH")" && pwd) 11 | PROJECTDIR="${SCRIPTDIR}/../" 12 | 13 | # Configuration 14 | . "${SCRIPTDIR}/configuration.sh" 15 | export PATH="${PREFIX}/bin:${PATH}" 16 | 17 | cd "${LIBINIH_SOURCE_DIR}" 18 | make clean install 19 | -------------------------------------------------------------------------------- /build/build-openocd.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env sh 2 | 3 | # be more verbose 4 | set -x 5 | # exit on wrong command and undefined variables 6 | set -e -u 7 | 8 | # find out own directory 9 | SCRIPTPATH=$(readlink -- "$0" || echo "$0") 10 | SCRIPTDIR=$(CDPATH= cd -- "$(dirname -- "$SCRIPTPATH")" && pwd) 11 | PROJECTDIR="${SCRIPTDIR}/../" 12 | 13 | # configuration 14 | . "${SCRIPTDIR}/configuration.sh" 15 | 16 | # Build openocd 17 | cd ${SCRIPTDIR} 18 | rm -rf ./b-openocd 19 | mkdir -p b-openocd 20 | cd ${SCRIPTDIR}/b-openocd 21 | tar -xaf ${SCRIPTDIR}/src/openocd-0.10.0.tar.bz2 22 | cd "openocd-0.10.0" 23 | # Disable most options. It will only increase the build time and the binary. 24 | ./configure --prefix="${PREFIX}" \ 25 | --enable-ftdi \ 26 | --disable-stlink \ 27 | --disable-ti-icdi \ 28 | --disable-ulink \ 29 | --disable-usb-blaster-2 \ 30 | --disable-vsllink \ 31 | --disable-osbdm \ 32 | --disable-opendous \ 33 | --disable-aice \ 34 | --disable-usbprog \ 35 | --disable-rlink \ 36 | --disable-armjtagew \ 37 | --disable-cmsis-dap \ 38 | --disable-usb-blaster \ 39 | --disable-presto \ 40 | --disable-openjtag \ 41 | --disable-jlink \ 42 | --disable-parport \ 43 | --disable-parport-ppdev \ 44 | --disable-parport-giveio \ 45 | --disable-jtag_vpi \ 46 | --disable-amtjtagaccel \ 47 | --disable-zy1000-master \ 48 | --disable-zy1000 \ 49 | --disable-ioutil \ 50 | --disable-ep93xx \ 51 | --disable-at91rm9200 \ 52 | --disable-bcm2835gpio \ 53 | --disable-gw16012 \ 54 | --disable-oocd_trace \ 55 | --disable-buspirate \ 56 | --disable-sysfsgpio \ 57 | --disable-minidriver-dummy \ 58 | --disable-remote-bitbang \ 59 | --disable-werror 60 | 61 | make -j `nproc` install 62 | -------------------------------------------------------------------------------- /build/build-toolchain.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env sh 2 | 3 | # be more verbose 4 | set -x 5 | # exit on wrong command and undefined variables 6 | set -e -u 7 | 8 | # find out own directory 9 | SCRIPTPATH=$(readlink -- "$0" || echo "$0") 10 | SCRIPTDIR=$(CDPATH= cd -- "$(dirname -- "$SCRIPTPATH")" && pwd) 11 | PROJECTDIR="${SCRIPTDIR}/../" 12 | 13 | # configuration 14 | . "${SCRIPTDIR}/configuration.sh" 15 | LOGDIR="${PROJECTDIR}/build/" 16 | NOW="$(date +%Y%m%d_%H%M%S)" 17 | export PATH="${PREFIX}/bin:${PATH}" 18 | 19 | # Build tools using source builder 20 | cd "${PROJECTDIR}/rtems-source-builder" 21 | ./source-builder/sb-check 22 | if [ $? -ne 0 ] 23 | then 24 | echo "ERROR: Please check your build environment." 25 | exit 1 26 | fi 27 | 28 | cd "${PROJECTDIR}/rtems-source-builder/rtems" 29 | ../source-builder/sb-set-builder \ 30 | --log="${LOGDIR}/rsb-${RTEMS_CPU}-${NOW}.log" \ 31 | --prefix="${PREFIX}" \ 32 | --no-clean \ 33 | --without-rtems \ 34 | "${RTEMS_VERSION}/rtems-${RTEMS_CPU}" 35 | 36 | # install waf 37 | mkdir -p "${PREFIX}/bin/" 38 | cp "${PROJECTDIR}/build/src/waf-2.0.2" "${PREFIX}/bin/waf" 39 | chmod 755 "${PREFIX}/bin/waf" 40 | -------------------------------------------------------------------------------- /build/build.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env sh 2 | 3 | # be more verbose 4 | set -x 5 | # exit on wrong command and undefined variables 6 | set -e -u 7 | 8 | # find out own directory 9 | SCRIPTPATH=$(readlink -- "$0" || echo "$0") 10 | SCRIPTDIR=$(CDPATH= cd -- "$(dirname -- "$SCRIPTPATH")" && pwd) 11 | PROJECTDIR="${SCRIPTDIR}/../" 12 | 13 | . "${SCRIPTDIR}/configuration.sh" 14 | BUILD_DIR="${PROJECTDIR}/build/b-$BSP_NAME" 15 | export PATH="${PREFIX}/bin:${PATH}" 16 | 17 | # Evaluate options 18 | DO_SUBMODULES=1 19 | DO_TOOLCHAIN=1 20 | DO_BOOTSTRAP=1 21 | for i in "$@" ; do 22 | case "$i" in 23 | --no-submodules) 24 | DO_SUBMODULES=0 25 | ;; 26 | --no-toolchain) 27 | DO_TOOLCHAIN=0 28 | ;; 29 | --no-bootstrap) 30 | DO_BOOTSTRAP=0 31 | ;; 32 | *) 33 | echo "Unexpected option: '$i'" 34 | exit 1 35 | ;; 36 | esac 37 | done 38 | 39 | if [ ${DO_SUBMODULES} -ne 0 ] 40 | then 41 | # init git submodules 42 | cd "${PROJECTDIR}" 43 | git submodule init 44 | git submodule update 45 | cd "${LIBBSD_SOURCE_DIR}" 46 | git submodule init 47 | git submodule update rtems_waf 48 | fi 49 | 50 | # build parts 51 | cd "${PROJECTDIR}" 52 | if [ ${DO_TOOLCHAIN} -ne 0 ] 53 | then 54 | "${SCRIPTDIR}/build-toolchain.sh" 55 | fi 56 | if [ ${DO_BOOTSTRAP} -ne 0 ] 57 | then 58 | cd "${RTEMS_SOURCE_DIR}" 59 | ./bootstrap 60 | fi 61 | cd "${PROJECTDIR}" 62 | "${SCRIPTDIR}/build-bsp.sh" clean install 63 | "${SCRIPTDIR}/build-libbsd.sh" clean install 64 | "${SCRIPTDIR}/build-libinih.sh" 65 | "${SCRIPTDIR}/build-libgrisp.sh" 66 | 67 | echo "${TOOLCHAIN_REVISION}" > "${PREFIX}/GRISP_TOOLCHAIN_REVISION" 68 | echo "#define GRISP_TOOLCHAIN_REVISION \"${TOOLCHAIN_REVISION}\"" > \ 69 | "${PREFIX}/${TARGET}/${BSP_NAME}/lib/include/grisp/grisp-buildinfo.h" 70 | echo "-define(GRISP_TOOLCHAIN_REVISION, \"${TOOLCHAIN_REVISION}\")." > \ 71 | "${PREFIX}/grisp_buildinfo.hrl" 72 | 73 | cd "${PROJECTDIR}/grisp-bootloader" && make clean all 74 | cd "${PROJECTDIR}/grisp-fatbench" && make clean all 75 | cd "${PROJECTDIR}/grisp-rtems-hw-test" && make clean all 76 | cd "${PROJECTDIR}/grisp-sd-sample" && make clean all 77 | cd "${PROJECTDIR}/grisp-simple-sample" && make clean all 78 | -------------------------------------------------------------------------------- /build/configuration.sh: -------------------------------------------------------------------------------- 1 | # This script is expected to be sourced. It expects the following variables to 2 | # be already set: 3 | # $PROJECTDIR -- set to the base dir of the project 4 | 5 | BSP_NAME="atsamv" 6 | RTEMS_CPU="arm" 7 | RTEMS_VERSION="5" 8 | TARGET="${RTEMS_CPU}-rtems${RTEMS_VERSION}" 9 | PREFIX="${PROJECTDIR}/rtems-install/rtems/${RTEMS_VERSION}/" 10 | TOOLCHAIN_REVISION="$(git rev-parse HEAD)" 11 | 12 | RTEMS_SOURCE_DIR="${PROJECTDIR}/rtems" 13 | LIBBSD_SOURCE_DIR="${PROJECTDIR}/rtems-libbsd" 14 | LIBINIH_SOURCE_DIR="${PROJECTDIR}/libinih" 15 | LIBGRISP_SOURCE_DIR="${PROJECTDIR}/libgrisp" 16 | 17 | BSP_CONFIG_OPT=" 18 | --disable-tests 19 | --disable-networking 20 | --enable-chip=same70q21 21 | --enable-sdram=is42s16320f-7bl 22 | ATSAM_CONSOLE_DEVICE_TYPE=1 23 | ATSAM_CONSOLE_DEVICE_INDEX=2 24 | ATSAM_MEMORY_QSPIFLASH_SIZE=0x0 25 | ATSAM_MEMORY_NOCACHE_SIZE=0x8000 26 | " 27 | -------------------------------------------------------------------------------- /build/create-package.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # Exit on errors 4 | set -e -u 5 | 6 | SCRIPTDIR="$( cd "$(dirname "$0")" ; pwd -P )" 7 | PROJECTDIR="${SCRIPTDIR}/../" 8 | source "${SCRIPTDIR}/configuration.sh" 9 | 10 | PLATFORM=$(uname) 11 | 12 | case "$PLATFORM" in 13 | Darwin) 14 | full=$(defaults read loginwindow SystemVersionStampAsString) 15 | VERSION=$(echo "${full}" | sed -E 's:([0-9]*.[0-9]*).*:\1:') 16 | ;; 17 | *) 18 | VERSION=unknown 19 | ;; 20 | esac 21 | 22 | PACKAGE_OS="${PLATFORM}-${VERSION}" 23 | PACKAGE_ID="${TARGET}_${PACKAGE_OS}_${TOOLCHAIN_REVISION}" 24 | 25 | PACKAGE_NAME="grisp_toolchain_${PACKAGE_ID}.tar.gz" 26 | 27 | tar -czf "${PACKAGE_NAME}" -C "${PREFIX}" . 28 | -------------------------------------------------------------------------------- /build/debug-load-flash.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # be more verbose 4 | set -x 5 | # exit on wrong command and undefined variables 6 | set -e -u 7 | 8 | # find out own directory 9 | SCRIPTPATH=$(readlink -- "$0" || echo "$0") 10 | SCRIPTDIR=$(CDPATH= cd -- "$(dirname -- "$SCRIPTPATH")" && pwd) 11 | PROJECTDIR="${SCRIPTDIR}/../" 12 | 13 | ELFFILE=$1 14 | 15 | ${SCRIPTDIR}/debug-start-openocd.sh \ 16 | -c "reset" -c "halt" -c "program \"${ELFFILE}\"" \ 17 | -c "reset" -c "halt" -c "verify_image_checksum \"${ELFFILE}\"" \ 18 | -c "reset" -c "exit" 19 | -------------------------------------------------------------------------------- /build/debug-reset.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # be more verbose 4 | set -x 5 | # exit on wrong command and undefined variables 6 | set -e -u 7 | 8 | # find out own directory 9 | SCRIPTPATH=$(readlink -- "$0" || echo "$0") 10 | SCRIPTDIR=$(CDPATH= cd -- "$(dirname -- "$SCRIPTPATH")" && pwd) 11 | PROJECTDIR="${SCRIPTDIR}/../" 12 | 13 | ${SCRIPTDIR}/debug-start-openocd.sh \ 14 | -c "reset" -c "exit" 15 | -------------------------------------------------------------------------------- /build/debug-set-gpnvm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # be more verbose 4 | set -x 5 | # exit on wrong command and undefined variables 6 | set -e -u 7 | 8 | # find out own directory 9 | SCRIPTPATH=$(readlink -- "$0" || echo "$0") 10 | SCRIPTDIR=$(CDPATH= cd -- "$(dirname -- "$SCRIPTPATH")" && pwd) 11 | PROJECTDIR="${SCRIPTDIR}/../" 12 | 13 | ${SCRIPTDIR}/debug-start-openocd.sh \ 14 | -c "reset" -c "halt" -c "mww 0x400e0c04 0x5a00010b"\ 15 | -c "reset" -c "exit" 16 | -------------------------------------------------------------------------------- /build/debug-start-gdb.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # be more verbose 4 | set -x 5 | # exit on wrong command and undefined variables 6 | set -e -u 7 | 8 | # find out own directory 9 | SCRIPTPATH=$(readlink -- "$0" || echo "$0") 10 | SCRIPTDIR=$(CDPATH= cd -- "$(dirname -- "$SCRIPTPATH")" && pwd) 11 | PROJECTDIR="${SCRIPTDIR}/../" 12 | 13 | # Configuration 14 | . "${SCRIPTDIR}/configuration.sh" 15 | BUILD_DIR="${PROJECTDIR}/build/b-$BSP_NAME" 16 | export PATH="${PREFIX}/bin:${PATH}" 17 | 18 | arm-rtems5-gdb -x ${SCRIPTDIR}/src/start.gdb "$@" 19 | -------------------------------------------------------------------------------- /build/debug-start-openocd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # be more verbose 4 | set -x 5 | # exit on wrong command and undefined variables 6 | set -e -u 7 | 8 | # find out own directory 9 | SCRIPTPATH=$(readlink -- "$0" || echo "$0") 10 | SCRIPTDIR=$(CDPATH= cd -- "$(dirname -- "$SCRIPTPATH")" && pwd) 11 | PROJECTDIR="${SCRIPTDIR}/../" 12 | 13 | # Configuration 14 | . "${SCRIPTDIR}/configuration.sh" 15 | BUILD_DIR="${PROJECTDIR}/build/b-$BSP_NAME" 16 | export PATH="${PREFIX}/bin:${PATH}" 17 | 18 | openocd -s "${TARGET}/share/openocd/scripts/" \ 19 | -f "${SCRIPTDIR}/src/openocd-grisp.cfg" \ 20 | -c "init" \ 21 | -c "reset halt" \ 22 | "$@" 23 | -------------------------------------------------------------------------------- /build/setup_manual_build_env.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env sh 2 | 3 | # **************************************** 4 | # NORMALLY YOU SHOULD NOT NEED THIS SCRIPT 5 | # **************************************** 6 | 7 | # This script set's up an environment that can be used for building RTEMS for 8 | # GRiSP manually. This is only necessary for RTEMS system development. You 9 | # should never need it to build an application. 10 | 11 | # be more verbose 12 | set -x 13 | # exit on wrong command and undefined variables 14 | set -e -u 15 | 16 | # find out own directory 17 | SCRIPTPATH=$(readlink -- "$0" || echo "$0") 18 | SCRIPTDIR=$(CDPATH= cd -- "$(dirname -- "$SCRIPTPATH")" && pwd) 19 | PROJECTDIR="${SCRIPTDIR}/../" 20 | 21 | # Configuration 22 | . "${SCRIPTDIR}/configuration.sh" 23 | ADDPATH=`readlink -f "${PREFIX}/bin"` 24 | export PATH="${ADDPATH}:${PATH}" 25 | 26 | export PREPROMPT="%B(GRISP-RTEMS)%b " 27 | 28 | ${SHELL} 29 | -------------------------------------------------------------------------------- /build/src/bsp.mk: -------------------------------------------------------------------------------- 1 | RTEMS_API = ##RTEMS_API## 2 | RTEMS_BSP = ##RTEMS_BSP## 3 | RTEMS_CPU = ##RTEMS_CPU## 4 | 5 | RTEMS_SHARE = $(RTEMS_ROOT)/share/rtems$(RTEMS_API) 6 | PROJECT_ROOT = $(RTEMS_ROOT)/$(RTEMS_CPU)-rtems$(RTEMS_API)/$(RTEMS_BSP) 7 | PROJECT_INCLUDE = $(PROJECT_ROOT)/lib/include 8 | PROJECT_LIB = $(PROJECT_ROOT)/lib 9 | BUILDDIR = b-$(RTEMS_BSP) 10 | 11 | prefix = $(RTEMS_ROOT) 12 | exec_prefix = $(RTEMS_ROOT)/$(RTEMS_CPU)-rtems$(RTEMS_API) 13 | 14 | include $(RTEMS_ROOT)/make/custom/$(RTEMS_BSP).cfg 15 | 16 | DEPFLAGS = -MT $@ -MD -MP -MF $(basename $@).d 17 | SYSFLAGS = -B $(PROJECT_LIB) -specs bsp_specs -qrtems 18 | WARNFLAGS = -Wall -Wextra -Wconversion -Wformat-security -Wformat=2 -Wshadow -Wcast-qual -Wcast-align -Wredundant-decls 19 | CWARNFLAGS = $(WARNFLAGS) -Wstrict-prototypes -Wbad-function-cast 20 | OPTFLAGS = $(CFLAGS_OPTIMIZE_V) 21 | 22 | CFLAGS = $(DEPFLAGS) $(SYSFLAGS) $(CWARNFLAGS) $(CPU_CFLAGS) $(OPTFLAGS) 23 | CXXFLAGS = $(DEPFLAGS) $(SYSFLAGS) $(WARNFLAGS) $(CPU_CFLAGS) $(OPTFLAGS) 24 | LINKFLAGS = $(SYSFLAGS) $(CPU_CFLAGS) $(LDFLAGS) $(OPTFLAGS) 25 | ASFLAGS = $(CPU_CFLAGS) 26 | 27 | CCLINK = $(CC) $(LINKFLAGS) -Wl,-Map,$(basename $@).map 28 | CXXLINK = $(CXX) $(LINKFLAGS) -Wl,-Map,$(basename $@).map 29 | 30 | $(BUILDDIR)/%.o: %.c 31 | $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@ 32 | 33 | $(BUILDDIR)/%.o: %.S 34 | $(CC) $(CPPFLAGS) -DASM $(CFLAGS) -c $< -o $@ 35 | 36 | $(BUILDDIR)/%.o: %.cc 37 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@ 38 | 39 | $(BUILDDIR)/%.o: %.cpp 40 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@ 41 | 42 | $(BUILDDIR)/%.o: %.s 43 | $(AS) $(ASFLAGS) $< -o $@ 44 | 45 | AR = $(RTEMS_CPU)-rtems$(RTEMS_API)-ar 46 | AS = $(RTEMS_CPU)-rtems$(RTEMS_API)-as 47 | CC = $(RTEMS_CPU)-rtems$(RTEMS_API)-gcc --pipe 48 | CXX = $(RTEMS_CPU)-rtems$(RTEMS_API)-g++ 49 | LD = $(RTEMS_CPU)-rtems$(RTEMS_API)-ld 50 | NM = $(RTEMS_CPU)-rtems$(RTEMS_API)-nm 51 | OBJCOPY = $(RTEMS_CPU)-rtems$(RTEMS_API)-objcopy 52 | RANLIB = $(RTEMS_CPU)-rtems$(RTEMS_API)-ranlib 53 | SIZE = $(RTEMS_CPU)-rtems$(RTEMS_API)-size 54 | STRIP = $(RTEMS_CPU)-rtems$(RTEMS_API)-strip 55 | export AR 56 | export AS 57 | export CC 58 | export CXX 59 | export LD 60 | export NM 61 | export OBJCOPY 62 | export RANLIB 63 | export SIZE 64 | export STRIP 65 | 66 | export PATH := $(RTEMS_ROOT)/bin:$(PATH) 67 | -------------------------------------------------------------------------------- /build/src/libbsd.ini: -------------------------------------------------------------------------------- 1 | [general] 2 | name = grisp2 3 | extends = default.ini 4 | 5 | [modules] 6 | dev_usb_wlan = on 7 | dev_wlan_rtwn = on 8 | net80211 = on 9 | user_space_wlanstats = on 10 | usr_sbin_wpa_supplicant = on 11 | -------------------------------------------------------------------------------- /build/src/openocd-0.10.0.tar.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grisp/grisp-software/f2324212d9ad9e28574fa2211045fab96fb30dc6/build/src/openocd-0.10.0.tar.bz2 -------------------------------------------------------------------------------- /build/src/openocd-grisp.cfg: -------------------------------------------------------------------------------- 1 | # 2 | # Grisp 3 | # http://www.GRiSP.org 4 | # 5 | 6 | # debug adapter 7 | interface ftdi 8 | ftdi_device_desc "Grisp" 9 | ftdi_vid_pid 0x0403 0x6010 10 | transport select swd 11 | ftdi_channel 0 12 | ftdi_layout_init 0x0018 0x001b 13 | ftdi_layout_signal nSRST -data 0x0010 -oe 0x0010 14 | ftdi_layout_signal SWD_EN -data 0 15 | 16 | # select chip 17 | set CHIPNAME atsame70q21 18 | source [find target/atsamv.cfg] 19 | reset_config srst_only 20 | adapter_khz 6000 21 | 22 | echo "basic initialization done" 23 | 24 | proc reset_and_run_bootloader {args} { 25 | echo "Reset, run bootloader and stop system" 26 | reset halt 27 | 28 | # wait till the bootloader has written the second word of the app 29 | wp 0x70000148 2 w 30 | resume 31 | wait_halt 5000 32 | rwp 0x70000148 33 | 34 | # and then break on first one 35 | bp 0x70000144 2 36 | resume 37 | wait_halt 5000 38 | rbp 0x70000144 39 | 40 | halt 41 | mww 0xE000ED14 0x00040200 42 | } 43 | -------------------------------------------------------------------------------- /build/src/start.gdb: -------------------------------------------------------------------------------- 1 | # reload the binary 2 | def reset 3 | print "Resetting target" 4 | monitor reset_and_run_bootloader 5 | load 6 | end 7 | 8 | # enable history 9 | set history filename ~/.gdb_history 10 | set history save 11 | 12 | # some behavioural settings 13 | set print pretty on 14 | set pagination off 15 | set confirm off 16 | 17 | # connect 18 | target extended-remote localhost:3333 19 | monitor gdb_breakpoint_override hard 20 | 21 | # load application for the first time 22 | reset 23 | -------------------------------------------------------------------------------- /build/src/waf-2.0.2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grisp/grisp-software/f2324212d9ad9e28574fa2211045fab96fb30dc6/build/src/waf-2.0.2 -------------------------------------------------------------------------------- /grisp-bootloader/Makefile: -------------------------------------------------------------------------------- 1 | RTEMS_ROOT ?= $(PWD)/../rtems-install/rtems/5 2 | RTEMS_BSP ?= atsamv 3 | 4 | include $(RTEMS_ROOT)/make/custom/$(RTEMS_BSP).mk 5 | 6 | GRISP_BL_VERSION := $(shell git describe --abbrev=4 --dirty --always --tags) 7 | GRISP_BL_BUILD_DATE := $(shell LC_LOCALE=en_US date -u) 8 | CFLAGS += -O2 9 | CFLAGS += -DGRISP_BL_VERSION="\"$(GRISP_BL_VERSION)\"" 10 | CFLAGS += -DGRISP_BL_BUILD_DATE="\"$(GRISP_BL_BUILD_DATE)\"" 11 | LDFLAGS += -qnolinkcmds -T linkcmds.bootloader 12 | #LDFLAGS += -qnolinkcmds -T linkcmds.sdram 13 | 14 | APP = $(BUILDDIR)/bootloader 15 | APP_PIECES = $(wildcard *.c) 16 | APP_OBJS = $(APP_PIECES:%.c=$(BUILDDIR)/%.o) 17 | APP_DEPS = $(APP_PIECES:%.c=$(BUILDDIR)/%.d) 18 | 19 | all: $(BUILDDIR) $(APP).exe 20 | 21 | $(BUILDDIR): 22 | mkdir $(BUILDDIR) 23 | 24 | $(APP).exe: $(APP_OBJS) 25 | $(CCLINK) $^ -lgrisp -linih -lbsd -lm -o $@ 26 | 27 | clean: 28 | rm -rf $(BUILDDIR) 29 | 30 | -include $(APP_DEPS) 31 | -------------------------------------------------------------------------------- /grisp-bootloader/binaries/bootloader.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grisp/grisp-software/f2324212d9ad9e28574fa2211045fab96fb30dc6/grisp-bootloader/binaries/bootloader.exe -------------------------------------------------------------------------------- /grisp-bootloader/init.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 embedded brains GmbH. All rights reserved. 3 | * 4 | * embedded brains GmbH 5 | * Dornierstr. 4 6 | * 82178 Puchheim 7 | * Germany 8 | * 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | */ 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | 49 | #include 50 | 51 | #include 52 | #include 53 | #include 54 | 55 | #include 56 | 57 | #define STACK_SIZE_INIT_TASK (64 * 1024) 58 | #define STACK_SIZE_SHELL (64 * 1024) 59 | 60 | #define PRIO_SHELL 10 61 | 62 | /* NOTE: With the default linker commands, only the internal SRAM is used. So it 63 | * is save to overwrite the external one. */ 64 | #define RESET_VECTOR_OFFSET 0x00000004 65 | #define RESET_VECTOR_SIZE 4 66 | static char *app_begin = atsam_memory_sdram_begin; 67 | /* Bootloader occupies the SDRAM from (start + 50M) to the end */ 68 | /* FIXME: Get from linker */ 69 | static char *app_end = atsam_memory_sdram_end - (14*1024*1024); 70 | 71 | const Pin atsam_pin_config[] = {GRISP_PIN_CONFIG}; 72 | const size_t atsam_pin_config_count = PIO_LISTSIZE(atsam_pin_config); 73 | const uint32_t atsam_matrix_ccfg_sysio = GRISP_MATRIX_CCFG_SYSIO; 74 | 75 | static const char ini_file[] = "/media/mmcsd-0-0/grisp.ini"; 76 | static int timeout_in_seconds = 3; 77 | static char image_path[PATH_MAX + 1] = "/media/mmcsd-0-0/grisp.bin"; 78 | 79 | static rtems_id led_timer_id = RTEMS_INVALID_ID; 80 | 81 | #include "slim-down.h" 82 | 83 | static int 84 | ini_value_copy(void *dst, size_t dst_size, const char *value) 85 | { 86 | int ok = 1; 87 | size_t value_size = strlen(value) + 1; 88 | 89 | if (value_size <= dst_size) { 90 | memcpy(dst, value, value_size); 91 | } else { 92 | ok = 0; 93 | } 94 | 95 | return ok; 96 | } 97 | 98 | static int 99 | ini_file_handler(void *arg, const char *section, const char *name, 100 | const char *value) 101 | { 102 | int ok = 0; 103 | 104 | (void)arg; 105 | 106 | if (strcmp(section, "boot") == 0) { 107 | if (strcmp(name, "image_path") == 0) { 108 | ok = ini_value_copy(&image_path[0], sizeof(image_path), 109 | value); 110 | } 111 | if (strcmp(name, "timeout_in_seconds") == 0) { 112 | rtems_status_code sc = rtems_string_to_int(value, 113 | &timeout_in_seconds, NULL, 10); 114 | ok = sc == RTEMS_SUCCESSFUL; 115 | } 116 | } else { 117 | /* All other sections are not relevant */ 118 | ok = 1; 119 | } 120 | 121 | if (!ok) { 122 | printf("boot: error in configuration file: section \"%s\", name \"%s\", value \"%s\"\n", 123 | section, name, value); 124 | ok = 1; 125 | } 126 | 127 | return ok; 128 | } 129 | 130 | static void 131 | led_timer(rtems_id timer, void *arg) 132 | { 133 | rtems_status_code sc; 134 | static bool is_on = false; 135 | bool ok = (bool)arg; 136 | bool r = false; 137 | bool g = false; 138 | bool b = false; 139 | 140 | sc = rtems_timer_reset(timer); 141 | assert(sc == RTEMS_SUCCESSFUL); 142 | 143 | if (!is_on) { 144 | if (ok) { 145 | b = true; 146 | } else { 147 | r = true; 148 | } 149 | } 150 | 151 | is_on = !is_on; 152 | 153 | grisp_led_set1(r, g, b); 154 | } 155 | 156 | static void 157 | init_led_early(void) 158 | { 159 | grisp_led_set1(false, true, true); 160 | grisp_led_set2(false, false, false); 161 | } 162 | 163 | static void 164 | init_led_timer(void) 165 | { 166 | rtems_status_code sc; 167 | 168 | sc = rtems_timer_create(rtems_build_name('L', 'E', 'D', ' '), 169 | &led_timer_id); 170 | assert(sc == RTEMS_SUCCESSFUL); 171 | 172 | sc = rtems_timer_server_fire_after( 173 | led_timer_id, 174 | rtems_clock_get_ticks_per_second() / 2, 175 | led_timer, 176 | (void*)true 177 | ); 178 | assert(sc == RTEMS_SUCCESSFUL); 179 | } 180 | 181 | static void 182 | led_not_ok(void) 183 | { 184 | rtems_status_code sc; 185 | 186 | sc = rtems_timer_cancel(led_timer_id); 187 | assert(sc == RTEMS_SUCCESSFUL); 188 | 189 | grisp_led_set1(true, false, false); 190 | 191 | sc = rtems_timer_server_fire_after( 192 | led_timer_id, 193 | rtems_clock_get_ticks_per_second() / 4, 194 | led_timer, 195 | (void*)false 196 | ); 197 | assert(sc == RTEMS_SUCCESSFUL); 198 | } 199 | 200 | static void 201 | print_status(bool ok) 202 | { 203 | if (ok) { 204 | printf("done\n"); 205 | } else { 206 | printf("failed\n"); 207 | } 208 | } 209 | 210 | static void _ARMV7M_Systick_cleanup(void) 211 | { 212 | volatile ARMV7M_Systick *systick = _ARMV7M_Systick; 213 | systick->csr = 0; 214 | } 215 | 216 | static void 217 | jump_to_app(void *start) 218 | { 219 | rtems_interrupt_level level; 220 | 221 | rtems_interrupt_disable(level); 222 | (void)level; 223 | rtems_cache_disable_instruction(); 224 | rtems_cache_disable_data(); 225 | rtems_cache_invalidate_entire_instruction(); 226 | rtems_cache_invalidate_entire_data(); 227 | _ARMV7M_Systick_cleanup(); 228 | 229 | void(*foo)(void) = (void(*)(void))(start); 230 | foo(); 231 | } 232 | 233 | static void 234 | start_app_from_ram(void) 235 | { 236 | uint32_t *reset_vector; 237 | void *app_start; 238 | 239 | reset_vector = (void *)(app_begin + RESET_VECTOR_OFFSET); 240 | app_start = (void *)(*reset_vector); 241 | jump_to_app(app_start); 242 | } 243 | 244 | static void 245 | load_via_file(const char *file) 246 | { 247 | int fd; 248 | bool ok; 249 | ssize_t in; 250 | int rv; 251 | size_t max_app_size = (size_t) (app_end - app_begin); 252 | 253 | printf("boot: open file \"%s\"... ", file); 254 | fd = open(file, O_RDONLY); 255 | ok = (fd >= 0); 256 | print_status(ok); 257 | if (ok) { 258 | printf("boot: read file \"%s\"... ", file); 259 | in = read(fd, app_begin, max_app_size); 260 | printf("received %zi bytes\n", in); 261 | 262 | rv = close(fd); 263 | assert(rv == 0); 264 | 265 | if (in > RESET_VECTOR_OFFSET + RESET_VECTOR_SIZE) { 266 | rtems_status_code sc = rtems_timer_cancel(led_timer_id); 267 | assert(sc == RTEMS_SUCCESSFUL); 268 | 269 | grisp_led_set1(false, true, false); 270 | /* Enough time to print all messages. */ 271 | rtems_task_wake_after(RTEMS_MILLISECONDS_TO_TICKS(100)); 272 | 273 | start_app_from_ram(); 274 | 275 | /* Should never reach this */ 276 | grisp_led_set1(true, false, false); 277 | } 278 | } 279 | } 280 | 281 | static void 282 | evaluate_ini_file(const char *filename) 283 | { 284 | ini_parse(filename, ini_file_handler, NULL); 285 | } 286 | 287 | static void print_message(int fd, int seconds_remaining, void *arg) 288 | { 289 | (void) fd; 290 | (void) seconds_remaining; 291 | (void) arg; 292 | 293 | printf("boot: press key to enter service mode\n"); 294 | } 295 | 296 | static bool 297 | wait_for_user_input(void) 298 | { 299 | bool service_mode_requested; 300 | int fd; 301 | 302 | fd = open(CONSOLE_DEVICE_NAME, O_RDWR); 303 | assert(fd >= 0); 304 | 305 | rtems_status_code sc = rtems_shell_wait_for_input( 306 | fd, timeout_in_seconds, print_message, NULL); 307 | service_mode_requested = (sc == RTEMS_SUCCESSFUL); 308 | 309 | return service_mode_requested; 310 | } 311 | 312 | static void 313 | start_shell(void) 314 | { 315 | rtems_status_code sc = rtems_shell_init( 316 | "SHLL", 317 | STACK_SIZE_SHELL, 318 | PRIO_SHELL, 319 | CONSOLE_DEVICE_NAME, 320 | false, 321 | true, 322 | NULL 323 | ); 324 | assert(sc == RTEMS_SUCCESSFUL); 325 | } 326 | 327 | static void 328 | service_mode(void) 329 | { 330 | start_shell(); 331 | } 332 | 333 | static int 334 | command_boot(int argc, char *argv[]) 335 | { 336 | if (argc != 2) { 337 | printf("Need exactly one file to boot as argument.\n"); 338 | } else { 339 | load_via_file(argv[1]); 340 | } 341 | 342 | return 0; 343 | } 344 | 345 | rtems_shell_cmd_t grisp_shell_BOOT_Command = { 346 | "boot", /* name */ 347 | "boot # boot from the given file", /* usage */ 348 | "grisp", /* topic */ 349 | command_boot, /* command */ 350 | NULL, /* alias */ 351 | NULL, /* next */ 352 | 0, 0, 0 353 | }; 354 | 355 | static void 356 | Init(rtems_task_argument arg) 357 | { 358 | bool service_mode_requested; 359 | rtems_status_code sc; 360 | 361 | (void)arg; 362 | 363 | init_led_early(); 364 | puts("\n----------------"); 365 | puts("GRISP bootloader"); 366 | puts("----------------"); 367 | printf("Version: %s (Build %s)\n", GRISP_BL_VERSION, GRISP_BL_BUILD_DATE); 368 | grisp_init_sd_card(); 369 | grisp_init_lower_self_prio(); 370 | grisp_init_libbsd(); 371 | init_led_timer(); 372 | 373 | /* Wait for the SD card */ 374 | sc = grisp_init_wait_for_sd(); 375 | if(sc == RTEMS_SUCCESSFUL) { 376 | evaluate_ini_file(ini_file); 377 | 378 | if (timeout_in_seconds == 0) { 379 | service_mode_requested = false; 380 | } else { 381 | service_mode_requested = wait_for_user_input(); 382 | } 383 | 384 | if (!service_mode_requested) { 385 | const char *image = image_path; 386 | if (strlen(image) > 0) { 387 | load_via_file(image); 388 | } 389 | 390 | /* Fallback: Show error and star service mode */ 391 | led_not_ok(); 392 | } 393 | } else { 394 | printf("ERROR: SD could not be mounted after timeout\n"); 395 | led_not_ok(); 396 | } 397 | 398 | service_mode(); 399 | 400 | exit(0); 401 | } 402 | 403 | /* 404 | * Configure LibBSD. 405 | */ 406 | #define GRISP_IS_BOOTLOADER 407 | #include 408 | #define RTEMS_BSD_CONFIG_INIT 409 | 410 | #include 411 | 412 | /* 413 | * Configure RTEMS. 414 | */ 415 | #define CONFIGURE_MICROSECONDS_PER_TICK 10000 416 | 417 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER 418 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER 419 | #define CONFIGURE_APPLICATION_NEEDS_STUB_DRIVER 420 | #define CONFIGURE_APPLICATION_NEEDS_ZERO_DRIVER 421 | #define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK 422 | 423 | #define CONFIGURE_FILESYSTEM_DOSFS 424 | #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32 425 | 426 | #define CONFIGURE_UNLIMITED_OBJECTS 427 | #define CONFIGURE_UNIFIED_WORK_AREAS 428 | #define CONFIGURE_MAXIMUM_USER_EXTENSIONS 1 429 | 430 | #define CONFIGURE_INIT_TASK_STACK_SIZE STACK_SIZE_INIT_TASK 431 | #define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_DEFAULT_MODES 432 | #define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT 433 | 434 | #define CONFIGURE_BDBUF_BUFFER_MAX_SIZE (32 * 1024) 435 | #define CONFIGURE_BDBUF_MAX_READ_AHEAD_BLOCKS 4 436 | #define CONFIGURE_BDBUF_CACHE_MEMORY_SIZE (1 * 1024 * 1024) 437 | 438 | /* #define CONFIGURE_STACK_CHECKER_ENABLED */ 439 | 440 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE 441 | #define CONFIGURE_INIT 442 | 443 | #include 444 | 445 | /* 446 | * Configure Shell. 447 | */ 448 | #include 449 | #define CONFIGURE_SHELL_COMMANDS_INIT 450 | #define CONFIGURE_SHELL_USER_COMMANDS \ 451 | &grisp_shell_BOOT_Command, \ 452 | &rtems_shell_BLKSTATS_Command 453 | #define CONFIGURE_SHELL_COMMANDS_ALL 454 | 455 | #include 456 | -------------------------------------------------------------------------------- /grisp-bootloader/linkcmds.bootloader: -------------------------------------------------------------------------------- 1 | INCLUDE linkcmds.memory 2 | 3 | MEMORY { 4 | BLSDRAM : ORIGIN = 0x70000000 + 50M, LENGTH = 0x04000000 - 50M 5 | } 6 | 7 | REGION_ALIAS ("REGION_START", INTFLASH); 8 | REGION_ALIAS ("REGION_VECTOR", INTSRAM); 9 | REGION_ALIAS ("REGION_TEXT", INTFLASH); 10 | REGION_ALIAS ("REGION_TEXT_LOAD", INTFLASH); 11 | REGION_ALIAS ("REGION_RODATA", INTFLASH); 12 | REGION_ALIAS ("REGION_RODATA_LOAD", INTFLASH); 13 | REGION_ALIAS ("REGION_DATA", INTSRAM); 14 | REGION_ALIAS ("REGION_DATA_LOAD", INTFLASH); 15 | REGION_ALIAS ("REGION_FAST_TEXT", ITCM); 16 | REGION_ALIAS ("REGION_FAST_TEXT_LOAD", INTFLASH); 17 | REGION_ALIAS ("REGION_FAST_DATA", DTCM); 18 | REGION_ALIAS ("REGION_FAST_DATA_LOAD", INTFLASH); 19 | REGION_ALIAS ("REGION_BSS", BLSDRAM); 20 | REGION_ALIAS ("REGION_WORK", BLSDRAM); 21 | REGION_ALIAS ("REGION_STACK", INTSRAM); 22 | REGION_ALIAS ("REGION_NOCACHE", NOCACHE); 23 | REGION_ALIAS ("REGION_NOCACHE_LOAD", INTFLASH); 24 | 25 | INCLUDE linkcmds.armv7m 26 | -------------------------------------------------------------------------------- /grisp-bootloader/slim-down.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @brief Stage-2 slim down. 5 | * 6 | * This file replaces some (heavy) functions from libbsd with dummy 7 | * implementations. This reduces the memory footprint. 8 | */ 9 | 10 | #include 11 | 12 | /* Remove some features of ifconfig. */ 13 | 14 | void _bsd_ifconfig_bridge_ctor(void) 15 | { 16 | } 17 | 18 | void _bsd_ifconfig_gif_ctor(void) 19 | { 20 | } 21 | 22 | void _bsd_ifconfig_gre_ctor(void) 23 | { 24 | } 25 | 26 | void _bsd_ifconfig_group_ctor(void) 27 | { 28 | } 29 | 30 | void _bsd_ifconfig_ieee80211_ctor(void) 31 | { 32 | } 33 | 34 | void _bsd_ifconfig_lagg_ctor(void) 35 | { 36 | } 37 | 38 | void _bsd_ifconfig_pfsync_ctor(void) 39 | { 40 | } 41 | 42 | void _bsd_ifconfig_vlan_ctor(void) 43 | { 44 | } 45 | 46 | 47 | /* Remove name service. */ 48 | 49 | struct hostent * gethostbyname(const char *name) 50 | { 51 | (void) name; 52 | return NULL; 53 | } 54 | 55 | struct hostent * gethostbyname2(const char *name, int af) 56 | { 57 | (void) name; (void) af; 58 | return NULL; 59 | } 60 | 61 | struct hostent * gethostbyaddr(const void *addr, socklen_t len, int af) 62 | { 63 | (void) addr; (void) len; (void) af; 64 | return NULL; 65 | } 66 | 67 | struct netent * getnetbyname(const char *name) 68 | { 69 | (void) name; 70 | return NULL; 71 | } 72 | 73 | struct netent *getnetbyaddr(uint32_t net, int type) 74 | { 75 | (void) net; (void) type; 76 | return NULL; 77 | } 78 | 79 | int getaddrinfo(const char *hostname, const char *servname, 80 | const struct addrinfo *hints, struct addrinfo **res) 81 | { 82 | (void) hostname; (void) servname; (void) hints; (void) res; 83 | return EAI_FAIL; 84 | } 85 | 86 | int getnameinfo(const struct sockaddr *sa, socklen_t salen, 87 | char *host, size_t hostlen, char *serv, size_t servlen, 88 | int flags) 89 | { 90 | (void) sa; (void) salen; (void) host; (void) hostlen; (void) serv; 91 | (void) servlen; (void) flags; 92 | return EAI_FAIL; 93 | } 94 | 95 | const char * gai_strerror(int ecode) 96 | { 97 | static const char *ret = "name resolution not implemented"; 98 | (void) ecode; 99 | return ret; 100 | } 101 | 102 | void freeaddrinfo(struct addrinfo *ai) 103 | { 104 | (void) ai; 105 | } 106 | -------------------------------------------------------------------------------- /grisp-fatbench/Makefile: -------------------------------------------------------------------------------- 1 | RTEMS_ROOT ?= $(PWD)/../rtems-install/rtems/5 2 | RTEMS_BSP ?= atsamv 3 | 4 | include $(RTEMS_ROOT)/make/custom/$(RTEMS_BSP).mk 5 | 6 | CFLAGS += -O0 7 | LDFLAGS += -qnolinkcmds -T linkcmds.sdram 8 | 9 | APP = $(BUILDDIR)/fatbench 10 | APP_PIECES = $(wildcard *.c) 11 | APP_OBJS = $(APP_PIECES:%.c=$(BUILDDIR)/%.o) 12 | APP_DEPS = $(APP_PIECES:%.c=$(BUILDDIR)/%.d) 13 | 14 | all: $(BUILDDIR) $(APP).exe 15 | 16 | $(BUILDDIR): 17 | mkdir $(BUILDDIR) 18 | 19 | $(APP).exe: $(APP_OBJS) 20 | $(CCLINK) $^ -lgrisp -lbsd -lm -o $@ 21 | 22 | $(APP).bin: $(APP).exe 23 | $(OBJCOPY) -O binary $^ $@ 24 | 25 | bin: all $(APP).bin 26 | 27 | clean: 28 | rm -rf $(BUILDDIR) 29 | 30 | debugoutput: 31 | echo $(PATH) 32 | 33 | -include $(APP_DEPS) 34 | -------------------------------------------------------------------------------- /grisp-fatbench/fatbench-libbsd-4b1426368b973f008cae17e51d7562f2fe102a5b.txt: -------------------------------------------------------------------------------- 1 | format with 8 sectors per cluster 2 | write 33554432 in 22.03s (1487.34KiB/s) 3 | ------------------------------------------------------------------------------- 4 | DEVICE STATISTICS 5 | ----------------------+-------------------------------------------------------- 6 | MEDIA BLOCK SIZE | 512 7 | MEDIA BLOCK COUNT | 29158400 8 | BLOCK SIZE | 4096 9 | READ HITS | 12656 10 | READ MISSES | 41 11 | READ AHEAD TRANSFERS | 6 12 | READ BLOCKS | 65 13 | READ ERRORS | 0 14 | WRITE TRANSFERS | 579 15 | WRITE BLOCKS | 8046 16 | WRITE ERRORS | 0 17 | ----------------------+-------------------------------------------------------- 18 | read 33554432 in 12.02s (2726.48KiB/s) 19 | ------------------------------------------------------------------------------- 20 | DEVICE STATISTICS 21 | ----------------------+-------------------------------------------------------- 22 | MEDIA BLOCK SIZE | 512 23 | MEDIA BLOCK COUNT | 29158400 24 | BLOCK SIZE | 4096 25 | READ HITS | 73712 26 | READ MISSES | 25 27 | READ AHEAD TRANSFERS | 2044 28 | READ BLOCKS | 8201 29 | READ ERRORS | 0 30 | WRITE TRANSFERS | 17 31 | WRITE BLOCKS | 216 32 | WRITE ERRORS | 0 33 | ----------------------+-------------------------------------------------------- 34 | 35 | format with 16 sectors per cluster 36 | write 33554432 in 15.02s (2182.08KiB/s) 37 | ------------------------------------------------------------------------------- 38 | DEVICE STATISTICS 39 | ----------------------+-------------------------------------------------------- 40 | MEDIA BLOCK SIZE | 512 41 | MEDIA BLOCK COUNT | 29158400 42 | BLOCK SIZE | 8192 43 | READ HITS | 8422 44 | READ MISSES | 11 45 | READ AHEAD TRANSFERS | 0 46 | READ BLOCKS | 11 47 | READ ERRORS | 0 48 | WRITE TRANSFERS | 333 49 | WRITE BLOCKS | 4096 50 | WRITE ERRORS | 0 51 | ----------------------+-------------------------------------------------------- 52 | read 33554432 in 8.99s (3645.38KiB/s) 53 | ------------------------------------------------------------------------------- 54 | DEVICE STATISTICS 55 | ----------------------+-------------------------------------------------------- 56 | MEDIA BLOCK SIZE | 512 57 | MEDIA BLOCK COUNT | 29158400 58 | BLOCK SIZE | 8192 59 | READ HITS | 69642 60 | READ MISSES | 7 61 | READ AHEAD TRANSFERS | 1023 62 | READ BLOCKS | 4099 63 | READ ERRORS | 0 64 | WRITE TRANSFERS | 8 65 | WRITE BLOCKS | 66 66 | WRITE ERRORS | 0 67 | ----------------------+-------------------------------------------------------- 68 | 69 | format with 32 sectors per cluster 70 | write 33554432 in 9.49s (3453.77KiB/s) 71 | ------------------------------------------------------------------------------- 72 | DEVICE STATISTICS 73 | ----------------------+-------------------------------------------------------- 74 | MEDIA BLOCK SIZE | 512 75 | MEDIA BLOCK COUNT | 29158400 76 | BLOCK SIZE | 16384 77 | READ HITS | 6299 78 | READ MISSES | 6 79 | READ AHEAD TRANSFERS | 1 80 | READ BLOCKS | 10 81 | READ ERRORS | 0 82 | WRITE TRANSFERS | 221 83 | WRITE BLOCKS | 2128 84 | WRITE ERRORS | 0 85 | ----------------------+-------------------------------------------------------- 86 | read 33554432 in 7.37s (4445.48KiB/s) 87 | ------------------------------------------------------------------------------- 88 | DEVICE STATISTICS 89 | ----------------------+-------------------------------------------------------- 90 | MEDIA BLOCK SIZE | 512 91 | MEDIA BLOCK COUNT | 29158400 92 | BLOCK SIZE | 16384 93 | READ HITS | 67616 94 | READ MISSES | 1 95 | READ AHEAD TRANSFERS | 513 96 | READ BLOCKS | 2049 97 | READ ERRORS | 0 98 | WRITE TRANSFERS | 4 99 | WRITE BLOCKS | 13 100 | WRITE ERRORS | 0 101 | ----------------------+-------------------------------------------------------- 102 | 103 | format with 64 sectors per cluster 104 | write 33554432 in 9.17s (3573.14KiB/s) 105 | ------------------------------------------------------------------------------- 106 | DEVICE STATISTICS 107 | ----------------------+-------------------------------------------------------- 108 | MEDIA BLOCK SIZE | 512 109 | MEDIA BLOCK COUNT | 29158400 110 | BLOCK SIZE | 32768 111 | READ HITS | 5248 112 | READ MISSES | 73 113 | READ AHEAD TRANSFERS | 0 114 | READ BLOCKS | 73 115 | READ ERRORS | 0 116 | WRITE TRANSFERS | 140 117 | WRITE BLOCKS | 1085 118 | WRITE ERRORS | 0 119 | ----------------------+-------------------------------------------------------- 120 | read 33554432 in 6.67s (4915.12KiB/s) 121 | ------------------------------------------------------------------------------- 122 | DEVICE STATISTICS 123 | ----------------------+-------------------------------------------------------- 124 | MEDIA BLOCK SIZE | 512 125 | MEDIA BLOCK COUNT | 29158400 126 | BLOCK SIZE | 32768 127 | READ HITS | 66624 128 | READ MISSES | 1 129 | READ AHEAD TRANSFERS | 257 130 | READ BLOCKS | 1025 131 | READ ERRORS | 0 132 | WRITE TRANSFERS | 5 133 | WRITE BLOCKS | 13 134 | WRITE ERRORS | 0 135 | ----------------------+-------------------------------------------------------- 136 | -------------------------------------------------------------------------------- /grisp-fatbench/fatbench-libbsd-ef5d536f840e01cb7a9edfd9f72dd0f058fb62aa.txt: -------------------------------------------------------------------------------- 1 | format with 1 sectors per cluster 2 | write 33554432 in 91.46s (358.27KiB/s) 3 | ------------------------------------------------------------------------------- 4 | DEVICE STATISTICS 5 | ----------------------+-------------------------------------------------------- 6 | MEDIA BLOCK SIZE | 512 7 | MEDIA BLOCK COUNT | 29158400 8 | BLOCK SIZE | 512 9 | READ HITS | 68598 10 | READ MISSES | 527 11 | READ AHEAD TRANSFERS | 260 12 | READ BLOCKS | 1567 13 | READ ERRORS | 0 14 | WRITE TRANSFERS | 4056 15 | WRITE BLOCKS | 64666 16 | WRITE ERRORS | 0 17 | ----------------------+-------------------------------------------------------- 18 | read 33554432 in 40.18s (815.57KiB/s) 19 | ------------------------------------------------------------------------------- 20 | DEVICE STATISTICS 21 | ----------------------+-------------------------------------------------------- 22 | MEDIA BLOCK SIZE | 512 23 | MEDIA BLOCK COUNT | 29158400 24 | BLOCK SIZE | 512 25 | READ HITS | 129537 26 | READ MISSES | 1537 27 | READ AHEAD TRANSFERS | 16128 28 | READ BLOCKS | 66049 29 | READ ERRORS | 0 30 | WRITE TRANSFERS | 123 31 | WRITE BLOCKS | 1932 32 | WRITE ERRORS | 0 33 | ----------------------+-------------------------------------------------------- 34 | 35 | format with 2 sectors per cluster 36 | write 33554432 in 47.38s (691.59KiB/s) 37 | ------------------------------------------------------------------------------- 38 | DEVICE STATISTICS 39 | ----------------------+-------------------------------------------------------- 40 | MEDIA BLOCK SIZE | 512 41 | MEDIA BLOCK COUNT | 29158400 42 | BLOCK SIZE | 1024 43 | READ HITS | 38093 44 | READ MISSES | 314 45 | READ AHEAD TRANSFERS | 4 46 | READ BLOCKS | 330 47 | READ ERRORS | 0 48 | WRITE TRANSFERS | 2076 49 | WRITE BLOCKS | 32170 50 | WRITE ERRORS | 0 51 | ----------------------+-------------------------------------------------------- 52 | read 33554432 in 22.31s (1468.94KiB/s) 53 | ------------------------------------------------------------------------------- 54 | DEVICE STATISTICS 55 | ----------------------+-------------------------------------------------------- 56 | MEDIA BLOCK SIZE | 512 57 | MEDIA BLOCK COUNT | 29158400 58 | BLOCK SIZE | 1024 59 | READ HITS | 97922 60 | READ MISSES | 385 61 | READ AHEAD TRANSFERS | 8128 62 | READ BLOCKS | 32897 63 | READ ERRORS | 0 64 | WRITE TRANSFERS | 57 65 | WRITE BLOCKS | 860 66 | WRITE ERRORS | 0 67 | ----------------------+-------------------------------------------------------- 68 | 69 | format with 4 sectors per cluster 70 | write 33554432 in 26.71s (1226.81KiB/s) 71 | ------------------------------------------------------------------------------- 72 | DEVICE STATISTICS 73 | ----------------------+-------------------------------------------------------- 74 | MEDIA BLOCK SIZE | 512 75 | MEDIA BLOCK COUNT | 29158400 76 | BLOCK SIZE | 2048 77 | READ HITS | 21176 78 | READ MISSES | 85 79 | READ AHEAD TRANSFERS | 7 80 | READ BLOCKS | 113 81 | READ ERRORS | 0 82 | WRITE TRANSFERS | 1068 83 | WRITE BLOCKS | 16044 84 | WRITE ERRORS | 0 85 | ----------------------+-------------------------------------------------------- 86 | read 33554432 in 13.31s (2461.33KiB/s) 87 | ------------------------------------------------------------------------------- 88 | DEVICE STATISTICS 89 | ----------------------+-------------------------------------------------------- 90 | MEDIA BLOCK SIZE | 512 91 | MEDIA BLOCK COUNT | 29158400 92 | BLOCK SIZE | 2048 93 | READ HITS | 81828 94 | READ MISSES | 97 95 | READ AHEAD TRANSFERS | 4080 96 | READ BLOCKS | 16417 97 | READ ERRORS | 0 98 | WRITE TRANSFERS | 33 99 | WRITE BLOCKS | 474 100 | WRITE ERRORS | 0 101 | ----------------------+-------------------------------------------------------- 102 | 103 | format with 8 sectors per cluster 104 | write 33554432 in 16.01s (2047.06KiB/s) 105 | ------------------------------------------------------------------------------- 106 | DEVICE STATISTICS 107 | ----------------------+-------------------------------------------------------- 108 | MEDIA BLOCK SIZE | 512 109 | MEDIA BLOCK COUNT | 29158400 110 | BLOCK SIZE | 4096 111 | READ HITS | 12656 112 | READ MISSES | 41 113 | READ AHEAD TRANSFERS | 6 114 | READ BLOCKS | 65 115 | READ ERRORS | 0 116 | WRITE TRANSFERS | 579 117 | WRITE BLOCKS | 8046 118 | WRITE ERRORS | 0 119 | ----------------------+-------------------------------------------------------- 120 | read 33554432 in 8.33s (3934.01KiB/s) 121 | ------------------------------------------------------------------------------- 122 | DEVICE STATISTICS 123 | ----------------------+-------------------------------------------------------- 124 | MEDIA BLOCK SIZE | 512 125 | MEDIA BLOCK COUNT | 29158400 126 | BLOCK SIZE | 4096 127 | READ HITS | 73712 128 | READ MISSES | 25 129 | READ AHEAD TRANSFERS | 2044 130 | READ BLOCKS | 8201 131 | READ ERRORS | 0 132 | WRITE TRANSFERS | 16 133 | WRITE BLOCKS | 200 134 | WRITE ERRORS | 0 135 | ----------------------+-------------------------------------------------------- 136 | 137 | format with 16 sectors per cluster 138 | write 33554432 in 10.96s (2990.86KiB/s) 139 | ------------------------------------------------------------------------------- 140 | DEVICE STATISTICS 141 | ----------------------+-------------------------------------------------------- 142 | MEDIA BLOCK SIZE | 512 143 | MEDIA BLOCK COUNT | 29158400 144 | BLOCK SIZE | 8192 145 | READ HITS | 8422 146 | READ MISSES | 11 147 | READ AHEAD TRANSFERS | 0 148 | READ BLOCKS | 11 149 | READ ERRORS | 0 150 | WRITE TRANSFERS | 333 151 | WRITE BLOCKS | 4096 152 | WRITE ERRORS | 0 153 | ----------------------+-------------------------------------------------------- 154 | read 33554432 in 6.46s (5073.91KiB/s) 155 | ------------------------------------------------------------------------------- 156 | DEVICE STATISTICS 157 | ----------------------+-------------------------------------------------------- 158 | MEDIA BLOCK SIZE | 512 159 | MEDIA BLOCK COUNT | 29158400 160 | BLOCK SIZE | 8192 161 | READ HITS | 69642 162 | READ MISSES | 7 163 | READ AHEAD TRANSFERS | 1023 164 | READ BLOCKS | 4099 165 | READ ERRORS | 0 166 | WRITE TRANSFERS | 8 167 | WRITE BLOCKS | 66 168 | WRITE ERRORS | 0 169 | ----------------------+-------------------------------------------------------- 170 | 171 | format with 32 sectors per cluster 172 | write 33554432 in 7.38s (4438.84KiB/s) 173 | ------------------------------------------------------------------------------- 174 | DEVICE STATISTICS 175 | ----------------------+-------------------------------------------------------- 176 | MEDIA BLOCK SIZE | 512 177 | MEDIA BLOCK COUNT | 29158400 178 | BLOCK SIZE | 16384 179 | READ HITS | 6299 180 | READ MISSES | 6 181 | READ AHEAD TRANSFERS | 1 182 | READ BLOCKS | 10 183 | READ ERRORS | 0 184 | WRITE TRANSFERS | 221 185 | WRITE BLOCKS | 2128 186 | WRITE ERRORS | 0 187 | ----------------------+-------------------------------------------------------- 188 | read 33554432 in 5.44s (6025.95KiB/s) 189 | ------------------------------------------------------------------------------- 190 | DEVICE STATISTICS 191 | ----------------------+-------------------------------------------------------- 192 | MEDIA BLOCK SIZE | 512 193 | MEDIA BLOCK COUNT | 29158400 194 | BLOCK SIZE | 16384 195 | READ HITS | 67616 196 | READ MISSES | 1 197 | READ AHEAD TRANSFERS | 513 198 | READ BLOCKS | 2049 199 | READ ERRORS | 0 200 | WRITE TRANSFERS | 4 201 | WRITE BLOCKS | 13 202 | WRITE ERRORS | 0 203 | ----------------------+-------------------------------------------------------- 204 | 205 | format with 64 sectors per cluster 206 | write 33554432 in 7.27s (4506.34KiB/s) 207 | ------------------------------------------------------------------------------- 208 | DEVICE STATISTICS 209 | ----------------------+-------------------------------------------------------- 210 | MEDIA BLOCK SIZE | 512 211 | MEDIA BLOCK COUNT | 29158400 212 | BLOCK SIZE | 32768 213 | READ HITS | 5248 214 | READ MISSES | 73 215 | READ AHEAD TRANSFERS | 0 216 | READ BLOCKS | 73 217 | READ ERRORS | 0 218 | WRITE TRANSFERS | 140 219 | WRITE BLOCKS | 1085 220 | WRITE ERRORS | 0 221 | ----------------------+-------------------------------------------------------- 222 | read 33554432 in 5.04s (6505.46KiB/s) 223 | ------------------------------------------------------------------------------- 224 | DEVICE STATISTICS 225 | ----------------------+-------------------------------------------------------- 226 | MEDIA BLOCK SIZE | 512 227 | MEDIA BLOCK COUNT | 29158400 228 | BLOCK SIZE | 32768 229 | READ HITS | 66624 230 | READ MISSES | 1 231 | READ AHEAD TRANSFERS | 257 232 | READ BLOCKS | 1025 233 | READ ERRORS | 0 234 | WRITE TRANSFERS | 5 235 | WRITE BLOCKS | 13 236 | WRITE ERRORS | 0 237 | ----------------------+-------------------------------------------------------- 238 | -------------------------------------------------------------------------------- /grisp-fatbench/fatbench.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 embedded brains GmbH. All rights reserved. 3 | * 4 | * embedded brains GmbH 5 | * Dornierstr. 4 6 | * 82178 Puchheim 7 | * Germany 8 | * 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | */ 31 | 32 | #include "fatbench.h" 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | 46 | #include 47 | #include 48 | #include 49 | #include 50 | 51 | static char buf[32 * 1024]; 52 | 53 | static rtems_printer printer; 54 | 55 | static double 56 | now(void) 57 | { 58 | double t; 59 | struct timespec ts; 60 | 61 | rtems_bsd_nanouptime(&ts); 62 | t = (double)ts.tv_sec; 63 | t += (double)ts.tv_nsec / 1000000000.0; 64 | return (t); 65 | } 66 | 67 | static void 68 | create_file(const char *path, size_t len) 69 | { 70 | double t0; 71 | double t1; 72 | double d; 73 | int rv; 74 | int fd; 75 | ssize_t n; 76 | size_t todo; 77 | 78 | t0 = now(); 79 | 80 | fd = open(path, O_CREAT | O_TRUNC | O_WRONLY); 81 | assert(fd >= 0); 82 | 83 | todo = len; 84 | while (todo > 0) { 85 | size_t junk; 86 | 87 | if (todo > sizeof(buf)) { 88 | junk = sizeof(buf); 89 | } else { 90 | junk = todo; 91 | } 92 | 93 | n = write(fd, buf, junk); 94 | assert(n == (ssize_t) junk); 95 | 96 | todo -= junk; 97 | } 98 | 99 | rv = close(fd); 100 | assert(rv == 0); 101 | 102 | t1 = now(); 103 | d = t1 - t0; 104 | printf("write %zu in %.2fs (%.2fKiB/s)\n", len, d, (double)(len / 1024) / d); 105 | } 106 | 107 | static size_t 108 | read_file(const char *path) 109 | { 110 | double t0; 111 | double t1; 112 | double d; 113 | int rv; 114 | int fd; 115 | size_t len; 116 | 117 | t0 = now(); 118 | len = 0; 119 | 120 | fd = open(path, O_RDONLY); 121 | assert(fd >= 0); 122 | 123 | while (true) { 124 | ssize_t n; 125 | 126 | n = read(fd, buf, sizeof(buf)); 127 | if (n <= 0) { 128 | break; 129 | } 130 | 131 | len += (size_t)n; 132 | } 133 | 134 | rv = close(fd); 135 | assert(rv == 0); 136 | 137 | t1 = now(); 138 | d = t1 - t0; 139 | printf("read %zu in %.2fs (%.2fKiB/s)\n", len, d, (double)(len / 1024) / d); 140 | 141 | return (len); 142 | } 143 | 144 | static void 145 | format(const char *dev_path, const char *mount_path, uint32_t sectors_per_cluster) 146 | { 147 | msdos_format_request_param_t rqdata; 148 | int rv; 149 | 150 | unmount(mount_path); 151 | 152 | memset(&rqdata, 0, sizeof(rqdata)); 153 | rqdata.sectors_per_cluster = sectors_per_cluster; 154 | rqdata.quick_format = true; 155 | rv = msdos_format(dev_path, &rqdata); 156 | assert(rv == 0); 157 | 158 | rv = mount_and_make_target_path(dev_path, mount_path, 159 | RTEMS_FILESYSTEM_TYPE_DOSFS, RTEMS_FILESYSTEM_READ_WRITE, NULL); 160 | assert(rv == 0); 161 | } 162 | 163 | static void 164 | simple_write_read(const char *dev_path, const char *mount_path, 165 | uint32_t sectors_per_cluster, size_t len) 166 | { 167 | static const char file[] = "test.bin"; 168 | int rv; 169 | size_t actual_len; 170 | 171 | printf("\nformat with %" PRIu32 " sectors per cluster\n", 172 | sectors_per_cluster); 173 | format(dev_path, mount_path, sectors_per_cluster); 174 | 175 | rv = chdir(mount_path); 176 | assert(rv == 0); 177 | 178 | rtems_blkstats(&printer, dev_path, true); 179 | create_file(file, len); 180 | rtems_blkstats(&printer, dev_path, false); 181 | 182 | rtems_blkstats(&printer, dev_path, true); 183 | actual_len = read_file(file); 184 | assert(len == actual_len); 185 | rtems_blkstats(&printer, dev_path, false); 186 | 187 | rv = chdir("/"); 188 | assert(rv == 0); 189 | } 190 | 191 | void 192 | fatbench(const char *dev_path, const char *mount_path) 193 | { 194 | uint32_t spc; 195 | size_t len; 196 | 197 | rtems_print_printer_fprintf(&printer, stdout); 198 | len = 32 * 1024 * 1024; 199 | 200 | for (spc = 1; spc <= 64; spc *= 2) { 201 | simple_write_read(dev_path, mount_path, spc, len); 202 | } 203 | } 204 | -------------------------------------------------------------------------------- /grisp-fatbench/fatbench.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 embedded brains GmbH. All rights reserved. 3 | * 4 | * embedded brains GmbH 5 | * Dornierstr. 4 6 | * 82178 Puchheim 7 | * Germany 8 | * 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef FATBENCH_H 33 | #define FATBENCH_H 34 | 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif /* __cplusplus */ 38 | 39 | void fatbench(const char *dev, const char *mount); 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif /* __cplusplus */ 44 | 45 | #endif /* FATBENCH_H */ 46 | -------------------------------------------------------------------------------- /grisp-fatbench/init.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 embedded brains GmbH. All rights reserved. 3 | * 4 | * embedded brains GmbH 5 | * Dornierstr. 4 6 | * 82178 Puchheim 7 | * Germany 8 | * 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | */ 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | #include 46 | 47 | #include 48 | #include 49 | 50 | #include "fatbench.h" 51 | 52 | #define STACK_SIZE_INIT_TASK (64 * 1024) 53 | #define STACK_SIZE_SHELL (64 * 1024) 54 | 55 | #define PRIO_SHELL 150 56 | #define PRIO_LED_TASK (RTEMS_MAXIMUM_PRIORITY - 1) 57 | #define PRIO_DHCP (RTEMS_MAXIMUM_PRIORITY - 1) 58 | 59 | const Pin atsam_pin_config[] = {GRISP_PIN_CONFIG}; 60 | const size_t atsam_pin_config_count = PIO_LISTSIZE(atsam_pin_config); 61 | const uint32_t atsam_matrix_ccfg_sysio = GRISP_MATRIX_CCFG_SYSIO; 62 | 63 | static void 64 | Init(rtems_task_argument arg) 65 | { 66 | rtems_status_code sc; 67 | 68 | (void)arg; 69 | 70 | grisp_init_sd_card(); 71 | 72 | sc = rtems_bsd_initialize(); 73 | assert(sc == RTEMS_SUCCESSFUL); 74 | 75 | sleep(2); 76 | 77 | sc = rtems_shell_init("SHLL", STACK_SIZE_SHELL, 78 | PRIO_SHELL, CONSOLE_DEVICE_NAME, false, false, NULL); 79 | assert(sc == RTEMS_SUCCESSFUL); 80 | 81 | fatbench("/dev/mmcsd-0-1", "/media/mmcsd-0-1"); 82 | 83 | rtems_task_delete(RTEMS_SELF); 84 | } 85 | 86 | /* 87 | * Configure LibBSD. 88 | */ 89 | #include 90 | #define RTEMS_BSD_CONFIG_TERMIOS_KQUEUE_AND_POLL 91 | #define RTEMS_BSD_CONFIG_INIT 92 | 93 | #include 94 | 95 | /* 96 | * Configure RTEMS. 97 | */ 98 | #define CONFIGURE_MICROSECONDS_PER_TICK 10000 99 | 100 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER 101 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER 102 | #define CONFIGURE_APPLICATION_NEEDS_STUB_DRIVER 103 | #define CONFIGURE_APPLICATION_NEEDS_ZERO_DRIVER 104 | #define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK 105 | 106 | #define CONFIGURE_FILESYSTEM_DOSFS 107 | #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32 108 | 109 | #define CONFIGURE_UNLIMITED_OBJECTS 110 | #define CONFIGURE_UNIFIED_WORK_AREAS 111 | #define CONFIGURE_MAXIMUM_USER_EXTENSIONS 1 112 | 113 | #define CONFIGURE_INIT_TASK_STACK_SIZE STACK_SIZE_INIT_TASK 114 | #define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_DEFAULT_MODES 115 | #define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT 116 | #define CONFIGURE_INIT_TASK_PRIORITY 112 117 | 118 | #define CONFIGURE_BDBUF_BUFFER_MAX_SIZE (32 * 1024) 119 | #define CONFIGURE_BDBUF_MAX_READ_AHEAD_BLOCKS 4 120 | #define CONFIGURE_BDBUF_CACHE_MEMORY_SIZE (1 * 1024 * 1024) 121 | #define CONFIGURE_BDBUF_READ_AHEAD_TASK_PRIORITY 97 122 | #define CONFIGURE_SWAPOUT_TASK_PRIORITY 97 123 | 124 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE 125 | #define CONFIGURE_INIT 126 | 127 | #include 128 | 129 | /* 130 | * Configure Shell. 131 | */ 132 | #include 133 | #include 134 | #define CONFIGURE_SHELL_COMMANDS_INIT 135 | 136 | #define CONFIGURE_SHELL_USER_COMMANDS \ 137 | &bsp_interrupt_shell_command 138 | 139 | #define CONFIGURE_SHELL_COMMANDS_ALL 140 | 141 | #include 142 | -------------------------------------------------------------------------------- /grisp-rtems-hw-test/Makefile: -------------------------------------------------------------------------------- 1 | RTEMS_ROOT ?= $(PWD)/../rtems-install/rtems/5 2 | RTEMS_BSP ?= atsamv 3 | 4 | include $(RTEMS_ROOT)/make/custom/$(RTEMS_BSP).mk 5 | 6 | CFLAGS += -O0 7 | LDFLAGS += -qnolinkcmds -T linkcmds.sdram 8 | 9 | APP = $(BUILDDIR)/rtems-hw-test 10 | APP_PIECES = $(wildcard *.c) 11 | APP_OBJS = $(APP_PIECES:%.c=$(BUILDDIR)/%.o) 12 | APP_DEPS = $(APP_PIECES:%.c=$(BUILDDIR)/%.d) 13 | 14 | all: $(BUILDDIR) $(APP).exe 15 | 16 | $(BUILDDIR): 17 | mkdir $(BUILDDIR) 18 | 19 | $(APP).exe: $(APP_OBJS) 20 | $(CCLINK) $^ -lgrisp -linih -lbsd -lm -o $@ 21 | 22 | $(APP).bin: $(APP).exe 23 | $(OBJCOPY) -O binary $^ $@ 24 | 25 | bin: all $(APP).bin 26 | 27 | clean: 28 | rm -rf $(BUILDDIR) 29 | 30 | debugoutput: 31 | echo $(PATH) 32 | 33 | -include $(APP_DEPS) 34 | -------------------------------------------------------------------------------- /grisp-rtems-hw-test/init.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017 embedded brains GmbH. All rights reserved. 3 | * 4 | * embedded brains GmbH 5 | * Dornierstr. 4 6 | * 82178 Puchheim 7 | * Germany 8 | * 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | */ 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | #include 44 | 45 | #include 46 | #include 47 | #include 48 | #include 49 | 50 | #include 51 | #include 52 | #include 53 | 54 | #include 55 | #include 56 | #include 57 | #include 58 | 59 | #include 60 | 61 | #include 62 | #include 63 | 64 | #define N_ELE(arr) (sizeof(arr)/sizeof(arr[0])) 65 | 66 | #define DS2482_ADDR 0x18 67 | 68 | #define DS2482_CMD_DRST 0xF0 69 | #define DS2482_CMD_SRP 0xE1 70 | #define DS2482_CMD_WCFG 0xD2 71 | #define DS2482_CMD_1WRS 0xB4 72 | #define DS2482_CMD_1WSB 0x87 73 | #define DS2482_CMD_1WWB 0xA5 74 | #define DS2482_CMD_1WRB 0x96 75 | #define DS2482_CMD_1WT 0x78 76 | 77 | #define DS2482_CFG_1WS 0x8 78 | #define DS2482_CFG_SPU 0x4 79 | #define DS2482_CFG_APU 0x1 80 | #define DS2482_CFG_GEN(flags) (((~((flags)<<4))&0xf0) | (flags)) 81 | 82 | #define DS2482_STAT_DIR 0x80 83 | #define DS2482_STAT_TSB 0x40 84 | #define DS2482_STAT_SBR 0x20 85 | #define DS2482_STAT_RST 0x10 86 | #define DS2482_STAT_LL 0x08 87 | #define DS2482_STAT_SD 0x04 88 | #define DS2482_STAT_PPD 0x02 89 | #define DS2482_STAT_1WB 0x01 90 | 91 | #define PMOD_CMPS_ADDR 0x1e 92 | #define PMOD_CMPS_SIZE 13 93 | #define PMOD_CMPS_PAGE_SIZE 1 94 | 95 | #define MAX_SSID_LEN 32 96 | #define MAX_IP_LEN (sizeof("255.255.255.255")) 97 | #define WLAN_NAME "wlan0" 98 | 99 | #define DIO11 {PIO_PC12, PIOC, ID_PIOC, PIO_OUTPUT_0, PIO_DEFAULT} 100 | #define DIO21 {PIO_PC13, PIOC, ID_PIOC, PIO_OUTPUT_0, PIO_DEFAULT} 101 | #define DIO31 {PIO_PA21, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT} 102 | #define DIO41 {PIO_PD30, PIOD, ID_PIOD, PIO_OUTPUT_0, PIO_DEFAULT} 103 | #define DIO51 {PIO_PD0, PIOD, ID_PIOD, PIO_INPUT, PIO_DEFAULT} 104 | #define DIO61 {PIO_PD1, PIOD, ID_PIOD, PIO_INPUT, PIO_DEFAULT} 105 | #define DIO71 {PIO_PD2, PIOD, ID_PIOD, PIO_INPUT, PIO_DEFAULT} 106 | #define DIO81 {PIO_PD3, PIOD, ID_PIOD, PIO_INPUT, PIO_DEFAULT} 107 | 108 | #define DIO12 {PIO_PC12, PIOC, ID_PIOC, PIO_INPUT, PIO_DEFAULT} 109 | #define DIO22 {PIO_PC13, PIOC, ID_PIOC, PIO_INPUT, PIO_DEFAULT} 110 | #define DIO32 {PIO_PA21, PIOA, ID_PIOA, PIO_INPUT, PIO_DEFAULT} 111 | #define DIO42 {PIO_PD30, PIOD, ID_PIOD, PIO_INPUT, PIO_DEFAULT} 112 | #define DIO52 {PIO_PD0, PIOD, ID_PIOD, PIO_OUTPUT_0, PIO_DEFAULT} 113 | #define DIO62 {PIO_PD1, PIOD, ID_PIOD, PIO_OUTPUT_0, PIO_DEFAULT} 114 | #define DIO72 {PIO_PD2, PIOD, ID_PIOD, PIO_OUTPUT_0, PIO_DEFAULT} 115 | #define DIO82 {PIO_PD3, PIOD, ID_PIOD, PIO_OUTPUT_0, PIO_DEFAULT} 116 | 117 | static const Pin DPIO1[] = {DIO11, DIO21, DIO31, DIO41, DIO51, DIO61, DIO71, DIO81}; 118 | static const Pin DPIO2[] = {DIO12, DIO22, DIO32, DIO42, DIO52, DIO62, DIO72, DIO82}; 119 | 120 | const Pin atsam_pin_config[] = {GRISP_PIN_CONFIG}; 121 | const size_t atsam_pin_config_count = PIO_LISTSIZE(atsam_pin_config); 122 | const uint32_t atsam_matrix_ccfg_sysio = GRISP_MATRIX_CCFG_SYSIO; 123 | 124 | static uint8_t test_rx_array[3]; 125 | static uint8_t test_tx_array[3]; 126 | static const char cmps_path[] = "/dev/i2c-0.compass-0"; 127 | static const char uart_path[] = "/dev/ttyUSART0"; 128 | static const char ini_file[] = "/media/mmcsd-0-0/grisp.ini"; 129 | static char ssid[MAX_SSID_LEN + 1] = ""; 130 | static char ping_ip[MAX_IP_LEN] = ""; 131 | static char net_ip[MAX_IP_LEN] = ""; 132 | static char net_mask[MAX_IP_LEN] = ""; 133 | 134 | static int 135 | ini_value_copy(void *dst, size_t dst_size, const char *value) 136 | { 137 | int ok = 1; 138 | size_t value_size = strlen(value) + 1; 139 | 140 | if (value_size <= dst_size) { 141 | memcpy(dst, value, value_size); 142 | } else { 143 | ok = 0; 144 | } 145 | 146 | return ok; 147 | } 148 | 149 | static int 150 | ini_file_handler(void *arg, const char *section, const char *name, 151 | const char *value) 152 | { 153 | int ok = 0; 154 | 155 | (void)arg; 156 | 157 | if (strcmp(section, "hw-test") == 0) { 158 | if (strcmp(name, "wlan_name") == 0) { 159 | ok = ini_value_copy(ssid, sizeof(ssid), value); 160 | } 161 | if (strcmp(name, "net_ip") == 0) { 162 | ok = ini_value_copy(net_ip, sizeof(net_ip), value); 163 | } 164 | if (strcmp(name, "net_mask") == 0) { 165 | ok = ini_value_copy(net_mask, sizeof(net_mask), value); 166 | } 167 | if (strcmp(name, "ping_ip") == 0) { 168 | ok = ini_value_copy(ping_ip, sizeof(ping_ip), value); 169 | } 170 | } else { 171 | /* All other sections are not relevant */ 172 | ok = 1; 173 | } 174 | 175 | if (!ok) { 176 | printf("boot: error in configuration file: section \"%s\", name \"%s\", value \"%s\"\n", 177 | section, name, value); 178 | ok = 1; 179 | } 180 | 181 | return ok; 182 | } 183 | 184 | static bool 185 | evaluate_ini_file(const char *filename) 186 | { 187 | int rv; 188 | bool passed = true; 189 | 190 | puts("----- parse configuration"); 191 | 192 | if (passed) { 193 | rv = ini_parse(filename, ini_file_handler, NULL); 194 | passed = (rv == 0); 195 | } 196 | if (passed) { 197 | passed = (strnlen(ssid, sizeof(ssid)) > 1); 198 | } 199 | if (passed) { 200 | passed = (strnlen(net_ip, sizeof(net_ip)) > 1); 201 | } 202 | if (passed) { 203 | passed = (strnlen(net_mask, sizeof(net_mask)) > 1); 204 | } 205 | if (passed) { 206 | passed = (strnlen(ping_ip, sizeof(ping_ip)) > 1); 207 | } 208 | if (rv == 0) { 209 | puts("***** parse configuration passed."); 210 | } else { 211 | puts("EEEEE parse configuration FAILED."); 212 | } 213 | return (rv == 0); 214 | } 215 | 216 | static const atsam_spi_config spi_config = { 217 | .spi_peripheral_id = ID_SPI0, 218 | .spi_regs = SPI0 219 | }; 220 | 221 | static int 222 | init_spi(void) 223 | { 224 | int rv; 225 | int fd; 226 | uint32_t speed = 100000; 227 | 228 | /* bus registration */ 229 | rv = spi_bus_register_atsam(ATSAM_SPI_0_BUS_PATH, &spi_config); 230 | assert(rv == 0); 231 | 232 | fd = open(ATSAM_SPI_0_BUS_PATH, O_RDWR); 233 | assert(fd != -1); 234 | 235 | rv = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed); 236 | assert(rv == 0); 237 | 238 | return fd; 239 | } 240 | 241 | static void 242 | test_set_default_msg(struct spi_ioc_transfer *msg) 243 | { 244 | msg->rx_buf = test_rx_array; 245 | msg->tx_buf = test_tx_array; 246 | msg->len = 3; 247 | msg->speed_hz = 100000; 248 | msg->delay_usecs = 1; 249 | msg->bits_per_word = 8; 250 | msg->cs_change = 1; 251 | msg->rx_nbits = 0; 252 | msg->tx_nbits = 0; 253 | msg->mode = 0; 254 | msg->cs = 2; 255 | } 256 | 257 | static void 258 | read_spi_register(int fd, uint8_t addr, uint8_t *val) 259 | { 260 | int rv; 261 | struct spi_ioc_transfer msg; 262 | 263 | test_tx_array[0] = 0x0b; 264 | test_tx_array[1] = addr; 265 | test_tx_array[2] = 0xff; 266 | 267 | test_set_default_msg(&msg); 268 | rv = ioctl(fd, SPI_IOC_MESSAGE(1), &msg); 269 | assert(rv == 0); 270 | *val = test_rx_array[2]; 271 | } 272 | 273 | static void 274 | init_cmps(int *fd_in, int *fd_out) 275 | { 276 | int rv; 277 | 278 | rv = i2c_dev_register_eeprom( 279 | ATSAM_I2C_0_BUS_PATH, 280 | &cmps_path[0], 281 | PMOD_CMPS_ADDR, 282 | 1, 283 | PMOD_CMPS_PAGE_SIZE, 284 | PMOD_CMPS_SIZE, 285 | 0 286 | ); 287 | assert(rv == 0); 288 | 289 | *fd_in = open(&cmps_path[0], O_RDWR); 290 | assert(*fd_in != -1); 291 | *fd_out = open(&cmps_path[0], O_RDWR); 292 | assert(*fd_out != -1); 293 | } 294 | 295 | static void 296 | read_write_pmod_cmps(int fd_in, uint8_t *out, size_t lenr) 297 | { 298 | ssize_t rb; 299 | off_t seekresult; 300 | 301 | seekresult = lseek(fd_in, 9, SEEK_SET); 302 | assert(seekresult >= 0); 303 | rb = read(fd_in, &out[0], lenr); 304 | assert(rb == (ssize_t)lenr); 305 | } 306 | 307 | static void 308 | init_gpio1(void) { 309 | PIO_Configure(DPIO1, sizeof(DPIO1)/sizeof(DPIO1[0])); 310 | } 311 | 312 | static void 313 | init_gpio2(void) { 314 | PIO_Configure(DPIO2, sizeof(DPIO2)/sizeof(DPIO2[0])); 315 | } 316 | 317 | static void 318 | prepare_i2c(void) 319 | { 320 | int rv; 321 | rv = atsam_register_i2c_0(); 322 | assert(rv == 0); 323 | } 324 | 325 | static void 326 | destroy_i2c(void) 327 | { 328 | int rv; 329 | rv = unlink(ATSAM_I2C_0_BUS_PATH); 330 | assert(rv == 0); 331 | } 332 | 333 | static bool 334 | test_spi(void) 335 | { 336 | int err = 0; 337 | int fd_spi; 338 | const uint8_t addr[] = {0x0, 0x1, 0x2, 0x3, 0x8, 0x9, 0xA, 0xB}; 339 | const uint8_t acl2_compare_value[] = {0xad, 0x1d, 0xf2}; 340 | uint8_t val; 341 | size_t i; 342 | 343 | puts("----- SPI test"); 344 | fd_spi = init_spi(); 345 | for (i=0; i < N_ELE(addr); i++) { 346 | read_spi_register(fd_spi, addr[i], &val); 347 | printf("value of register %x: %x\n",addr[i], val); 348 | if(i < N_ELE(acl2_compare_value)) { 349 | if (val != acl2_compare_value[i]) { 350 | err = 1; 351 | } 352 | } 353 | } 354 | if (err != 0) { 355 | puts("EEEEE SPI test FAILED. Try right module PmodACL2 on port SPI1."); 356 | } 357 | else { 358 | puts("***** SPI test passed."); 359 | return true; 360 | } 361 | 362 | return false; 363 | } 364 | 365 | static bool 366 | test_i2c_eeprom(void) 367 | { 368 | int err = 0; 369 | int rv; 370 | struct grisp_eeprom eeprom; 371 | 372 | puts("----- EEPROM test"); 373 | 374 | err = grisp_eeprom_init(); 375 | assert(err == 0); 376 | 377 | memset(&eeprom.mac_addr, 0, sizeof(eeprom.mac_addr)); 378 | 379 | if (err == 0) { 380 | eeprom.sig_version = GRISP_EEPROM_SIG_VERSION; 381 | /* Ask for values */ 382 | puts("Please enter the new EEPROM content in the following format:\n" 383 | "Format (integers): serial, batch_nr, prod_year, prod_month, prod_day, vers_major, vers_minor, ass_var"); 384 | rv = scanf("%lu, %hu, %hu, %hhu, %hhu, %hhu, %hhu, %hhu", 385 | &eeprom.serial, &eeprom.batch_nr, &eeprom.prod_year, 386 | &eeprom.prod_month, &eeprom.prod_day, &eeprom.vers_major, 387 | &eeprom.vers_minor, &eeprom.ass_var); 388 | if (rv != 8) { 389 | printf("Invalid input (%s). Don't write EEPROM.\n", 390 | strerror(errno)); 391 | err = 1; 392 | } 393 | } 394 | 395 | if (err == 0) { 396 | puts("Write EEPROM."); 397 | err = grisp_eeprom_set(&eeprom); 398 | } 399 | 400 | if (err == 0) { 401 | puts("Verify EEPROM CRC."); 402 | err = grisp_eeprom_set(&eeprom); 403 | /* Dump only for the log */ 404 | grisp_eeprom_dump(&eeprom); 405 | } 406 | 407 | if (err != 0) { 408 | puts("EEEEE EEPROM test FAILED."); 409 | } 410 | else { 411 | puts("***** EEPROM test passed."); 412 | return true; 413 | } 414 | 415 | return false; 416 | } 417 | 418 | static bool 419 | test_i2c_cmps(void) 420 | { 421 | int err = 0; 422 | int fd_in_cmps, fd_out_cmps; 423 | uint8_t cmps_compare_value[] = {0x48, 0x34, 0x33}; 424 | uint8_t cmps_in[] = {0x09}; 425 | uint8_t cmps_out[] = {0xff,0xff, 0xff, 0xff}; 426 | size_t i; 427 | int rv; 428 | 429 | puts("----- External I2C test"); 430 | 431 | init_cmps(&fd_in_cmps, &fd_out_cmps); 432 | 433 | read_write_pmod_cmps(fd_in_cmps, &cmps_out[0], sizeof (cmps_out)/sizeof(cmps_out[0])); 434 | 435 | printf("Compass register read start: "); 436 | for (i=0; i < N_ELE(cmps_in); i++) { 437 | printf("%x ",cmps_in[i]); 438 | } 439 | puts(""); 440 | 441 | printf("Compass register values: "); 442 | for (i=0; i < N_ELE(cmps_out); i++) { 443 | printf("%x ",cmps_out[i]); 444 | } 445 | puts(""); 446 | for (i=0; i < 3; i++) { 447 | if (cmps_out[i+1] != cmps_compare_value[i]) { 448 | err = 1; 449 | } 450 | } 451 | 452 | rv = close(fd_in_cmps); 453 | assert(rv == 0); 454 | 455 | rv = close(fd_out_cmps); 456 | assert(rv == 0); 457 | 458 | rv = unlink(&cmps_path[0]); 459 | assert(rv == 0); 460 | 461 | if (err != 0) { 462 | puts("EEEEE External I2C test FAILED. Try right module PmodCMPS on I2C."); 463 | } 464 | else { 465 | puts("***** External I2C test passed."); 466 | return true; 467 | } 468 | 469 | return false; 470 | } 471 | 472 | static bool 473 | test_gpio(void) 474 | { 475 | bool passed = true; 476 | uint32_t ans; 477 | 478 | puts("----- GPIO test"); 479 | 480 | init_gpio1(); 481 | 482 | if (passed) { 483 | puts("\nGPIO test"); 484 | puts("Switch GPIO1 high and measure GPIO2"); 485 | PIO_Set(&DPIO1[0]); 486 | PIO_Clear(&DPIO1[1]); 487 | PIO_Set(&DPIO1[2]); 488 | PIO_Clear(&DPIO1[3]); 489 | ans = PIO_Get(&DPIO1[4]); 490 | if (ans == 0) { 491 | puts ("GPIO fail between DIO1 and DIO5"); 492 | passed = false; 493 | } 494 | ans = PIO_Get(&DPIO1[5]); 495 | if (ans) { 496 | puts ("GPIO fail between DIO2 and DIO6"); 497 | passed = false; 498 | } 499 | ans = PIO_Get(&DPIO1[6]); 500 | if (ans == 0) { 501 | puts ("GPIO fail between DIO3 and DIO7"); 502 | passed = false; 503 | } 504 | ans = PIO_Get(&DPIO1[7]); 505 | if (ans) { 506 | puts ("GPIO fail between DIO4 and DIO8"); 507 | passed = false; 508 | } 509 | if (passed) { 510 | puts ("Pattern 1010 read"); 511 | } 512 | } 513 | if (passed) { 514 | PIO_Clear(&DPIO1[0]); 515 | PIO_Set(&DPIO1[1]); 516 | PIO_Clear(&DPIO1[2]); 517 | PIO_Set(&DPIO1[3]); 518 | ans = PIO_Get(&DPIO1[4]); 519 | if (ans) { 520 | puts ("GPIO fail between DIO1 and DIO5"); 521 | passed = false; 522 | } 523 | ans = PIO_Get(&DPIO1[5]); 524 | if (ans == 0) { 525 | puts ("GPIO fail between DIO2 and DIO6"); 526 | passed = false; 527 | } 528 | ans = PIO_Get(&DPIO1[6]); 529 | if (ans) { 530 | puts ("GPIO fail between DIO3 and DIO7"); 531 | passed = false; 532 | } 533 | ans = PIO_Get(&DPIO1[7]); 534 | if (ans == 0) { 535 | puts ("GPIO fail between DIO4 and DIO8"); 536 | passed = false; 537 | } 538 | if (passed) { 539 | puts ("Pattern 0101 read"); 540 | } 541 | } 542 | 543 | init_gpio2(); 544 | 545 | if (passed) { 546 | puts("\nGPIO test"); 547 | puts("Switch GPIO2 high and measure GPIO1"); 548 | PIO_Set(&DPIO2[4]); 549 | PIO_Clear(&DPIO2[5]); 550 | PIO_Set(&DPIO2[6]); 551 | PIO_Clear(&DPIO2[7]); 552 | ans = PIO_Get(&DPIO2[0]); 553 | if (ans == 0) { 554 | puts ("GPIO fail between DIO1 and DIO5"); 555 | passed = false; 556 | } 557 | ans = PIO_Get(&DPIO2[1]); 558 | if (ans) { 559 | puts ("GPIO fail between DIO2 and DIO6"); 560 | passed = false; 561 | } 562 | ans = PIO_Get(&DPIO2[2]); 563 | if (ans == 0) { 564 | puts ("GPIO fail between DIO3 and DIO7"); 565 | passed = false; 566 | } 567 | ans = PIO_Get(&DPIO2[3]); 568 | if (ans) { 569 | puts ("GPIO fail between DIO4 and DIO8"); 570 | passed = false; 571 | } 572 | if (passed) { 573 | puts ("Pattern 1010 read"); 574 | } 575 | } 576 | if (passed) { 577 | PIO_Clear(&DPIO2[4]); 578 | PIO_Set(&DPIO2[5]); 579 | PIO_Clear(&DPIO2[6]); 580 | PIO_Set(&DPIO2[7]); 581 | ans = PIO_Get(&DPIO2[0]); 582 | if (ans) { 583 | puts ("GPIO fail between DIO1 and DIO5"); 584 | passed = false; 585 | } 586 | ans = PIO_Get(&DPIO2[1]); 587 | if (ans == 0) { 588 | puts ("GPIO fail between DIO2 and DIO6"); 589 | passed = false; 590 | } 591 | ans = PIO_Get(&DPIO2[2]); 592 | if (ans) { 593 | puts ("GPIO fail between DIO3 and DIO7"); 594 | passed = false; 595 | } 596 | ans = PIO_Get(&DPIO2[3]); 597 | if (ans == 0) { 598 | puts ("GPIO fail between DIO4 and DIO8"); 599 | passed = false; 600 | } 601 | if (passed) { 602 | puts ("Pattern 0101 read"); 603 | } 604 | } 605 | 606 | if (!passed) { 607 | puts("EEEEE GPIO test FAILED."); 608 | } 609 | else { 610 | puts("***** GPIO test passed."); 611 | } 612 | 613 | return passed; 614 | } 615 | 616 | static bool 617 | test_uart(void) 618 | { 619 | bool passed = true; 620 | int fd; 621 | int rv; 622 | struct termios options; 623 | char rx = '\0'; 624 | 625 | puts("----- UART test"); 626 | 627 | fd = open(uart_path, O_RDWR); 628 | assert(fd != -1); 629 | 630 | /* Setup interface */ 631 | rv = tcgetattr(fd, &options); 632 | assert(rv == 0); 633 | rv = cfsetispeed(&options, B19200); 634 | assert(rv == 0); 635 | rv = cfsetospeed(&options, B19200); 636 | assert(rv == 0); 637 | options.c_cflag |= CRTSCTS; 638 | rv = tcsetattr(fd, TCSANOW, &options); 639 | assert(rv == 0); 640 | 641 | rv = write(fd, "x", 1); 642 | if (rv != 1) { 643 | passed = false; 644 | perror("uart write failed"); 645 | } 646 | 647 | if (passed) { 648 | rv = read(fd, &rx, 1); 649 | if (rv != 1) { 650 | perror("uart read failed"); 651 | passed = false; 652 | } else if (rx != 'x') { 653 | passed = false; 654 | printf("received wrong character: %c\n", rx); 655 | } 656 | } 657 | 658 | rv = close(fd); 659 | assert(rv == 0); 660 | 661 | if (!passed) { 662 | puts("EEEEE UART test FAILED."); 663 | } 664 | else { 665 | puts("***** UART test passed."); 666 | } 667 | 668 | return passed; 669 | } 670 | 671 | static bool 672 | prepare_libbsd(void) 673 | { 674 | rtems_status_code sc; 675 | int exit_code; 676 | char *ifcfg[] = { 677 | "ifconfig", WLAN_NAME, "create", "wlandev", "rtwn0", "up", NULL 678 | }; 679 | bool passed = true; 680 | 681 | puts("----- prepare libbsd"); 682 | grisp_init_sd_card(); 683 | grisp_init_lower_self_prio(); 684 | grisp_init_libbsd(); 685 | 686 | if (passed) { 687 | sc = grisp_init_wait_for_sd(); 688 | if (sc == RTEMS_SUCCESSFUL) { 689 | printf("SD: OK\n"); 690 | } else { 691 | printf("ERROR: SD could not be mounted after timeout\n"); 692 | passed = false; 693 | } 694 | } 695 | 696 | if (passed) { 697 | /* Some time for USB device to be detected. */ 698 | rtems_task_wake_after(RTEMS_MILLISECONDS_TO_TICKS(4000)); 699 | exit_code = rtems_bsd_command_ifconfig( 700 | RTEMS_BSD_ARGC(ifcfg), ifcfg); 701 | if(exit_code != EXIT_SUCCESS) { 702 | printf("ERROR while creating wlan."); 703 | passed = false; 704 | } 705 | } 706 | 707 | if (passed) { 708 | puts("***** prepare libbsd passed."); 709 | } else { 710 | puts("EEEEE prepare libbsd FAILED."); 711 | } 712 | 713 | return passed; 714 | } 715 | 716 | static bool 717 | set_up_wifi(void) 718 | { 719 | bool passed = true; 720 | int exit_code; 721 | char *ifcfg_scan[] = { 722 | "ifconfig", WLAN_NAME, "scan", NULL 723 | }; 724 | char *ifcfg_ssid[] = { 725 | "ifconfig", WLAN_NAME, "ssid", ssid, NULL 726 | }; 727 | char *ifcfg_ip[] = { 728 | "ifconfig", WLAN_NAME, net_ip, "netmask", net_mask, NULL 729 | }; 730 | char *ifcfg[] = { 731 | "ifconfig", WLAN_NAME, NULL 732 | }; 733 | 734 | puts("----- set up wifi"); 735 | 736 | if (passed) { 737 | exit_code = rtems_bsd_command_ifconfig( 738 | RTEMS_BSD_ARGC(ifcfg_scan), ifcfg_scan); 739 | if(exit_code != EXIT_SUCCESS) { 740 | printf("ERROR while scanning with wlan."); 741 | passed = false; 742 | } 743 | } 744 | 745 | if (passed) { 746 | exit_code = rtems_bsd_command_ifconfig( 747 | RTEMS_BSD_ARGC(ifcfg_ssid), ifcfg_ssid); 748 | if(exit_code != EXIT_SUCCESS) { 749 | printf("ERROR while setting ssid of wlan."); 750 | passed = false; 751 | } 752 | } 753 | 754 | rtems_task_wake_after(RTEMS_MILLISECONDS_TO_TICKS(2000)); 755 | 756 | if (passed) { 757 | exit_code = rtems_bsd_command_ifconfig( 758 | RTEMS_BSD_ARGC(ifcfg_ip), ifcfg_ip); 759 | if(exit_code != EXIT_SUCCESS) { 760 | printf("ERROR while setting ip on wlan."); 761 | passed = false; 762 | } 763 | } 764 | 765 | (void) rtems_bsd_command_ifconfig(RTEMS_BSD_ARGC(ifcfg), ifcfg); 766 | 767 | if (passed) { 768 | puts("***** set up wifi passed."); 769 | } else { 770 | puts("EEEEE set up wifi FAILED."); 771 | } 772 | 773 | return passed; 774 | } 775 | 776 | static bool 777 | test_ping(void) 778 | { 779 | bool passed = true; 780 | int exit_code; 781 | char *ping[] = { 782 | "ping", ping_ip, NULL 783 | }; 784 | const int maxtries = 10; 785 | const rtems_interval delay = RTEMS_MILLISECONDS_TO_TICKS(1000); 786 | int tries = 0; 787 | 788 | puts("----- do ping test"); 789 | 790 | do { 791 | exit_code = rtems_bsd_command_ping(RTEMS_BSD_ARGC(ping), ping); 792 | if(exit_code != EXIT_SUCCESS) { 793 | printf("Ping failed."); 794 | passed = false; 795 | } else { 796 | passed = true; 797 | } 798 | if (!passed && tries < maxtries) { 799 | rtems_task_wake_after(delay); 800 | } 801 | ++tries; 802 | } while (!passed && tries <= maxtries); 803 | 804 | if (passed) { 805 | puts("***** ping test passed."); 806 | } else { 807 | puts("EEEEE ping test FAILED."); 808 | } 809 | 810 | return passed; 811 | } 812 | 813 | static bool 814 | ds2482_master_reset(int file) 815 | { 816 | uint8_t buf[] = {DS2482_CMD_DRST}; 817 | uint8_t rd[1] = {0}; 818 | struct i2c_rdwr_ioctl_data work_queue; 819 | struct i2c_msg msg[] = { 820 | { 821 | .addr = DS2482_ADDR, 822 | .flags = 0, 823 | .len = sizeof(buf), 824 | .buf = buf, 825 | },{ 826 | .addr = DS2482_ADDR, 827 | .flags = I2C_M_RD, 828 | .len = sizeof(rd), 829 | .buf = rd, 830 | } 831 | }; 832 | 833 | work_queue.msgs = msg; 834 | work_queue.nmsgs = sizeof(msg)/sizeof(msg[0]); 835 | 836 | if (ioctl(file, I2C_RDWR, &work_queue) < 0) { 837 | puts("Resetting 1-Wire master failed."); 838 | return false; 839 | } 840 | 841 | if ((rd[0] & DS2482_STAT_RST) == 0) { 842 | printf("Reset bit of 1-Wire not set: 0x%02x\n", rd[0]); 843 | return false; 844 | } 845 | 846 | return true; 847 | } 848 | 849 | static bool 850 | test_1wire(void) 851 | { 852 | bool passed = true; 853 | int i2c_file; 854 | 855 | puts("----- 1wire test"); 856 | 857 | if (passed) { 858 | i2c_file = open(ATSAM_I2C_0_BUS_PATH, O_RDWR); 859 | if (i2c_file < 0) { 860 | passed = false; 861 | printf("Opening I2C failed: %s\n", strerror(errno)); 862 | } 863 | } 864 | 865 | if (passed) { 866 | /* Only do a reset to see whether the master is there. */ 867 | passed = ds2482_master_reset(i2c_file); 868 | } 869 | 870 | if (i2c_file >= 0) { 871 | close(i2c_file); 872 | } 873 | 874 | if (!passed) { 875 | puts("EEEEE 1wire test FAILED."); 876 | } 877 | else { 878 | puts("***** 1wire test passed."); 879 | } 880 | 881 | return passed; 882 | } 883 | 884 | static void 885 | Init(rtems_task_argument arg) 886 | { 887 | bool passed = true; 888 | char choice; 889 | int err; 890 | 891 | (void)arg; 892 | puts(""); 893 | puts("Start testing Grisp hardware"); 894 | puts("Contect the following modules:"); 895 | puts(" - PmodACL2 on SPI1"); 896 | puts(" - PmodCMPS on I2C"); 897 | puts(" - Bridge between GPIO1 and GPIO2"); 898 | puts(" - Loopback on UART (TxD -> RxD, RTS -> CTS)"); 899 | puts("Prepare a WiFi access point with a configuration that matches the one in grisp.ini."); 900 | 901 | grisp_led_set1(false, false, true); 902 | grisp_led_set2(false, false, false); 903 | 904 | if (passed) { 905 | passed = prepare_libbsd(); 906 | } 907 | if (passed) { 908 | passed = evaluate_ini_file(ini_file); 909 | } 910 | if (passed) { 911 | passed = set_up_wifi(); 912 | } 913 | if (passed) { 914 | passed = test_spi(); 915 | } 916 | if (passed) { 917 | passed = test_gpio(); 918 | } 919 | if (passed) { 920 | passed = test_uart(); 921 | } 922 | if (passed) { 923 | int c; 924 | puts("\nLED test red"); 925 | grisp_led_set1(true, false, false); 926 | grisp_led_set2(true, false, false); 927 | puts("Only red LEDS on? y/n"); 928 | err = scanf("%c", &choice); 929 | assert(err == 1); 930 | while ((c = getchar()) != '\n' && c != EOF); /* Flush stdin. */ 931 | if (choice != 'y') { 932 | passed = false; 933 | } 934 | } 935 | if (passed) { 936 | int c; 937 | puts("\nLED test green"); 938 | grisp_led_set1(false, true, false); 939 | grisp_led_set2(false, true, false); 940 | puts("Only green LEDS on? y/n"); 941 | err = scanf("%c", &choice); 942 | assert(err == 1); 943 | while ((c = getchar()) != '\n' && c != EOF); /* Flush stdin. */ 944 | if (choice != 'y') { 945 | passed = false; 946 | } 947 | } 948 | if (passed) { 949 | int c; 950 | puts("\nLED test blue"); 951 | grisp_led_set1(false, false, true); 952 | grisp_led_set2(false, false, true); 953 | puts("Only blue LEDS on? y/n"); 954 | err = scanf("%c", &choice); 955 | assert(err == 1); 956 | while ((c = getchar()) != '\n' && c != EOF); /* Flush stdin. */ 957 | if (choice != 'y') { 958 | passed = false; 959 | } 960 | } 961 | if (passed) { 962 | passed = test_ping(); 963 | } 964 | prepare_i2c(); 965 | if (passed) { 966 | passed = test_1wire(); 967 | } 968 | if (passed) { 969 | passed = test_i2c_cmps(); 970 | } 971 | if (passed) { 972 | passed = test_i2c_eeprom(); 973 | } 974 | destroy_i2c(); 975 | 976 | if (passed) { 977 | puts("**** Test successful ****"); 978 | } 979 | else { 980 | puts("**** Test FAILED ****"); 981 | } 982 | 983 | while(true) { 984 | sleep(1); 985 | } 986 | 987 | rtems_task_delete(RTEMS_SELF); 988 | } 989 | 990 | /* 991 | * Configure LibBSD. 992 | */ 993 | #include 994 | #define RTEMS_BSD_CONFIG_TERMIOS_KQUEUE_AND_POLL 995 | #define RTEMS_BSD_CONFIG_INIT 996 | 997 | #include 998 | 999 | /* 1000 | * Configure RTEMS. 1001 | */ 1002 | #define CONFIGURE_MICROSECONDS_PER_TICK 10000 1003 | 1004 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER 1005 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER 1006 | #define CONFIGURE_APPLICATION_NEEDS_STUB_DRIVER 1007 | #define CONFIGURE_APPLICATION_NEEDS_ZERO_DRIVER 1008 | #define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK 1009 | 1010 | #define CONFIGURE_FILESYSTEM_DOSFS 1011 | #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32 1012 | 1013 | #define CONFIGURE_UNLIMITED_OBJECTS 1014 | #define CONFIGURE_UNIFIED_WORK_AREAS 1015 | #define CONFIGURE_MAXIMUM_USER_EXTENSIONS 1 1016 | 1017 | #define CONFIGURE_INIT_TASK_STACK_SIZE (64 * 1024) 1018 | #define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_DEFAULT_MODES 1019 | #define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT 1020 | 1021 | #define CONFIGURE_BDBUF_BUFFER_MAX_SIZE (32 * 1024) 1022 | #define CONFIGURE_BDBUF_MAX_READ_AHEAD_BLOCKS 4 1023 | #define CONFIGURE_BDBUF_CACHE_MEMORY_SIZE (1 * 1024 * 1024) 1024 | #define CONFIGURE_BDBUF_READ_AHEAD_TASK_PRIORITY 97 1025 | #define CONFIGURE_SWAPOUT_TASK_PRIORITY 97 1026 | 1027 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE 1028 | #define CONFIGURE_INIT 1029 | 1030 | #include 1031 | 1032 | /* 1033 | * Configure Shell. 1034 | */ 1035 | #include 1036 | #include 1037 | #define CONFIGURE_SHELL_COMMANDS_INIT 1038 | #define CONFIGURE_SHELL_COMMANDS_ALL 1039 | #define CONFIGURE_SHELL_USER_COMMANDS \ 1040 | &bsp_interrupt_shell_command, \ 1041 | &rtems_shell_ARP_Command, \ 1042 | &rtems_shell_PFCTL_Command, \ 1043 | &rtems_shell_PING_Command, \ 1044 | &rtems_shell_IFCONFIG_Command, \ 1045 | &rtems_shell_ROUTE_Command, \ 1046 | &rtems_shell_NETSTAT_Command, \ 1047 | &rtems_shell_DHCPCD_Command, \ 1048 | &rtems_shell_HOSTNAME_Command, \ 1049 | &rtems_shell_SYSCTL_Command, \ 1050 | &rtems_shell_VMSTAT_Command, \ 1051 | &rtems_shell_WLANSTATS_Command, \ 1052 | &rtems_shell_BLKSTATS_Command 1053 | 1054 | #include 1055 | -------------------------------------------------------------------------------- /grisp-rtems-hw-test/sd-card-content/grisp.ini: -------------------------------------------------------------------------------- 1 | [boot] 2 | timeout_in_seconds = 2 3 | image_path = /media/mmcsd-0-0/rtems-hw-test.bin 4 | 5 | [hw-test] 6 | wlan_name = grisptest 7 | ping_ip = 192.168.178.1 8 | net_ip = 192.168.178.100 9 | net_mask = 255.255.255.0 10 | -------------------------------------------------------------------------------- /grisp-rtems-hw-test/sd-card-content/rtems-hw-test.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grisp/grisp-software/f2324212d9ad9e28574fa2211045fab96fb30dc6/grisp-rtems-hw-test/sd-card-content/rtems-hw-test.bin -------------------------------------------------------------------------------- /grisp-sd-sample/Makefile: -------------------------------------------------------------------------------- 1 | RTEMS_ROOT ?= $(PWD)/../rtems-install/rtems/5 2 | RTEMS_BSP ?= atsamv 3 | 4 | include $(RTEMS_ROOT)/make/custom/$(RTEMS_BSP).mk 5 | 6 | CFLAGS += -O0 7 | LDFLAGS += -qnolinkcmds -T linkcmds.sdram 8 | 9 | APP = $(BUILDDIR)/sd-sample 10 | APP_PIECES = $(wildcard *.c) 11 | APP_OBJS = $(APP_PIECES:%.c=$(BUILDDIR)/%.o) 12 | APP_DEPS = $(APP_PIECES:%.c=$(BUILDDIR)/%.d) 13 | 14 | all: $(BUILDDIR) $(APP).exe 15 | 16 | $(BUILDDIR): 17 | mkdir $(BUILDDIR) 18 | 19 | $(APP).exe: $(APP_OBJS) 20 | $(CCLINK) $^ -lgrisp -lftpd -lbsd -lm -o $@ 21 | 22 | $(APP).bin: $(APP).exe 23 | $(OBJCOPY) -O binary $^ $@ 24 | 25 | bin: all $(APP).bin 26 | 27 | clean: 28 | rm -rf $(BUILDDIR) 29 | 30 | debugoutput: 31 | echo $(PATH) 32 | 33 | -include $(APP_DEPS) 34 | -------------------------------------------------------------------------------- /grisp-sd-sample/init.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 embedded brains GmbH. All rights reserved. 3 | * 4 | * embedded brains GmbH 5 | * Dornierstr. 4 6 | * 82178 Puchheim 7 | * Germany 8 | * 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | */ 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | 49 | #include 50 | 51 | #include 52 | #include 53 | #include 54 | 55 | #define STACK_SIZE_INIT_TASK (64 * 1024) 56 | #define STACK_SIZE_SHELL (64 * 1024) 57 | 58 | #define PRIO_SHELL 150 59 | #define PRIO_LED_TASK (RTEMS_MAXIMUM_PRIORITY - 1) 60 | #define PRIO_DHCP (RTEMS_MAXIMUM_PRIORITY - 1) 61 | #define PRIO_WPA (RTEMS_MAXIMUM_PRIORITY - 1) 62 | 63 | const char *wpa_supplicant_conf = "/media/mmcsd-0-0/wpa_supplicant.conf"; 64 | 65 | const Pin atsam_pin_config[] = {GRISP_PIN_CONFIG}; 66 | const size_t atsam_pin_config_count = PIO_LISTSIZE(atsam_pin_config); 67 | const uint32_t atsam_matrix_ccfg_sysio = GRISP_MATRIX_CCFG_SYSIO; 68 | 69 | struct rtems_ftpd_configuration rtems_ftpd_configuration = { 70 | .priority = 100, 71 | .max_hook_filesize = 0, 72 | .port = 21, 73 | .hooks = NULL, 74 | .root = NULL, 75 | .tasks_count = 4, 76 | .idle = 5 * 60, 77 | .access = 0 78 | }; 79 | 80 | static void 81 | start_shell(void) 82 | { 83 | rtems_status_code sc = rtems_shell_init( 84 | "SHLL", 85 | STACK_SIZE_SHELL, 86 | PRIO_SHELL, 87 | CONSOLE_DEVICE_NAME, 88 | false, 89 | true, 90 | NULL 91 | ); 92 | assert(sc == RTEMS_SUCCESSFUL); 93 | } 94 | 95 | static void 96 | create_wlandev(void) 97 | { 98 | int exit_code; 99 | char *ifcfg_check[] = { 100 | "ifconfig", 101 | "wlan0", 102 | NULL 103 | }; 104 | char *ifcfg_create[] = { 105 | "ifconfig", 106 | "wlan0", 107 | "create", 108 | "wlandev", 109 | "rtwn0", 110 | "down", 111 | NULL 112 | }; 113 | char *ifcfg_up[] = { 114 | "ifconfig", 115 | "wlan0", 116 | "up", 117 | NULL 118 | }; 119 | 120 | /* Check if device exists */ 121 | exit_code = rtems_bsd_command_ifconfig( 122 | RTEMS_BSD_ARGC(ifcfg_check), ifcfg_check); 123 | if (exit_code != EXIT_SUCCESS) { 124 | /* Create it if not */ 125 | exit_code = rtems_bsd_command_ifconfig( 126 | RTEMS_BSD_ARGC(ifcfg_create), ifcfg_create); 127 | if(exit_code != EXIT_SUCCESS) { 128 | printf("ERROR while creating wlan0.\n"); 129 | } 130 | sleep(1); 131 | exit_code = rtems_bsd_command_ifconfig( 132 | RTEMS_BSD_ARGC(ifcfg_up), ifcfg_up); 133 | if(exit_code != EXIT_SUCCESS) { 134 | printf("ERROR while setting wlan0 up.\n"); 135 | } 136 | } 137 | } 138 | 139 | static void 140 | led_task(rtems_task_argument arg) 141 | { 142 | bool state = false; 143 | 144 | (void)arg; 145 | 146 | while(true) { 147 | state = !state; 148 | grisp_led_set1(!state, !state, state); 149 | grisp_led_set2(state, state, !state); 150 | rtems_task_wake_after(RTEMS_MILLISECONDS_TO_TICKS(250)); 151 | } 152 | } 153 | 154 | static void 155 | init_led(void) 156 | { 157 | rtems_status_code sc; 158 | rtems_id id; 159 | 160 | sc = rtems_task_create( 161 | rtems_build_name('L', 'E', 'D', ' '), 162 | PRIO_LED_TASK, 163 | RTEMS_MINIMUM_STACK_SIZE, 164 | RTEMS_DEFAULT_MODES, 165 | RTEMS_DEFAULT_ATTRIBUTES, 166 | &id 167 | ); 168 | assert(sc == RTEMS_SUCCESSFUL); 169 | 170 | sc = rtems_task_start(id, led_task, 0); 171 | assert(sc == RTEMS_SUCCESSFUL); 172 | } 173 | 174 | static int 175 | command_startftp(int argc, char *argv[]) 176 | { 177 | rtems_status_code sc; 178 | 179 | (void) argc; 180 | (void) argv; 181 | 182 | sc = rtems_initialize_ftpd(); 183 | if(sc == RTEMS_SUCCESSFUL) { 184 | printf("FTP started.\n"); 185 | } else { 186 | printf("ERROR: FTP could not be started.\n"); 187 | } 188 | 189 | return 0; 190 | } 191 | 192 | rtems_shell_cmd_t rtems_shell_STARTFTP_Command = { 193 | "startftp", /* name */ 194 | "startftp", /* usage */ 195 | "net", /* topic */ 196 | command_startftp, /* command */ 197 | NULL, /* alias */ 198 | NULL, /* next */ 199 | 0, 0, 0 200 | }; 201 | 202 | static void 203 | Init(rtems_task_argument arg) 204 | { 205 | rtems_status_code sc; 206 | 207 | (void)arg; 208 | 209 | grisp_led_set1(false, false, false); 210 | grisp_led_set2(true, false, false); 211 | puts("\nGRISP RTEMS SD Demo\n"); 212 | grisp_init_sd_card(); 213 | grisp_init_lower_self_prio(); 214 | grisp_init_libbsd(); 215 | 216 | /* Wait for the SD card */ 217 | grisp_led_set2(true, false, true); 218 | sc = grisp_init_wait_for_sd(); 219 | if (sc == RTEMS_SUCCESSFUL) { 220 | printf("SD: OK\n"); 221 | } else { 222 | printf("ERROR: SD could not be mounted after timeout\n"); 223 | grisp_led_set1(true, false, false); 224 | } 225 | 226 | grisp_init_dhcpcd(PRIO_DHCP); 227 | 228 | grisp_led_set2(false, false, true); 229 | printf("Wait some time till USB device is detected.\n"); 230 | rtems_task_wake_after(RTEMS_MILLISECONDS_TO_TICKS(4000)); 231 | grisp_init_wpa_supplicant(wpa_supplicant_conf, PRIO_WPA, create_wlandev); 232 | 233 | init_led(); 234 | start_shell(); 235 | 236 | exit(0); 237 | } 238 | 239 | /* 240 | * Configure LibBSD. 241 | */ 242 | #include 243 | #define RTEMS_BSD_CONFIG_TERMIOS_KQUEUE_AND_POLL 244 | #define RTEMS_BSD_CONFIG_INIT 245 | 246 | #include 247 | 248 | /* 249 | * Configure RTEMS. 250 | */ 251 | #define CONFIGURE_MICROSECONDS_PER_TICK 10000 252 | 253 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER 254 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER 255 | #define CONFIGURE_APPLICATION_NEEDS_STUB_DRIVER 256 | #define CONFIGURE_APPLICATION_NEEDS_ZERO_DRIVER 257 | #define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK 258 | 259 | #define CONFIGURE_FILESYSTEM_DOSFS 260 | #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32 261 | 262 | #define CONFIGURE_UNLIMITED_OBJECTS 263 | #define CONFIGURE_UNIFIED_WORK_AREAS 264 | #define CONFIGURE_MAXIMUM_USER_EXTENSIONS 1 265 | 266 | #define CONFIGURE_INIT_TASK_STACK_SIZE STACK_SIZE_INIT_TASK 267 | #define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_DEFAULT_MODES 268 | #define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT 269 | 270 | #define CONFIGURE_BDBUF_BUFFER_MAX_SIZE (32 * 1024) 271 | #define CONFIGURE_BDBUF_MAX_READ_AHEAD_BLOCKS 4 272 | #define CONFIGURE_BDBUF_CACHE_MEMORY_SIZE (1 * 1024 * 1024) 273 | #define CONFIGURE_BDBUF_READ_AHEAD_TASK_PRIORITY 97 274 | #define CONFIGURE_SWAPOUT_TASK_PRIORITY 97 275 | 276 | //#define CONFIGURE_STACK_CHECKER_ENABLED 277 | 278 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE 279 | #define CONFIGURE_INIT 280 | 281 | #include 282 | 283 | /* 284 | * Configure Shell. 285 | */ 286 | #include 287 | #include 288 | #define CONFIGURE_SHELL_COMMANDS_INIT 289 | 290 | #define CONFIGURE_SHELL_USER_COMMANDS \ 291 | &bsp_interrupt_shell_command, \ 292 | &rtems_shell_ARP_Command, \ 293 | &rtems_shell_PFCTL_Command, \ 294 | &rtems_shell_PING_Command, \ 295 | &rtems_shell_IFCONFIG_Command, \ 296 | &rtems_shell_ROUTE_Command, \ 297 | &rtems_shell_NETSTAT_Command, \ 298 | &rtems_shell_DHCPCD_Command, \ 299 | &rtems_shell_HOSTNAME_Command, \ 300 | &rtems_shell_SYSCTL_Command, \ 301 | &rtems_shell_VMSTAT_Command, \ 302 | &rtems_shell_WLANSTATS_Command, \ 303 | &rtems_shell_STARTFTP_Command, \ 304 | &rtems_shell_BLKSTATS_Command, \ 305 | &rtems_shell_WPA_SUPPLICANT_Command, \ 306 | &rtems_shell_WPA_SUPPLICANT_FORK_Command 307 | 308 | #define CONFIGURE_SHELL_COMMANDS_ALL 309 | 310 | #include 311 | -------------------------------------------------------------------------------- /grisp-sd-sample/wpa_supplicant.conf.example: -------------------------------------------------------------------------------- 1 | network={ 2 | ssid="grisptest" 3 | key_mgmt=WPA-PSK 4 | psk="testtest" 5 | } 6 | -------------------------------------------------------------------------------- /grisp-simple-sample/Makefile: -------------------------------------------------------------------------------- 1 | RTEMS_ROOT ?= $(PWD)/../rtems-install/rtems/5 2 | RTEMS_BSP ?= atsamv 3 | 4 | include $(RTEMS_ROOT)/make/custom/$(RTEMS_BSP).mk 5 | 6 | CFLAGS += -O0 7 | LDFLAGS += -qnolinkcmds -T linkcmds.sdram 8 | 9 | APP = $(BUILDDIR)/simple-sample 10 | APP_PIECES = $(wildcard *.c) 11 | APP_OBJS = $(APP_PIECES:%.c=$(BUILDDIR)/%.o) 12 | APP_DEPS = $(APP_PIECES:%.c=$(BUILDDIR)/%.d) 13 | 14 | all: $(BUILDDIR) $(APP).exe 15 | 16 | $(BUILDDIR): 17 | mkdir $(BUILDDIR) 18 | 19 | $(APP).exe: $(APP_OBJS) 20 | $(CCLINK) $^ -lgrisp -o $@ 21 | 22 | $(APP).bin: $(APP).exe 23 | $(OBJCOPY) -O binary $^ $@ 24 | 25 | bin: all $(APP).bin 26 | 27 | clean: 28 | rm -rf $(BUILDDIR) 29 | 30 | debugoutput: 31 | echo $(PATH) 32 | 33 | -include $(APP_DEPS) 34 | -------------------------------------------------------------------------------- /grisp-simple-sample/init.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 embedded brains GmbH. All rights reserved. 3 | * 4 | * embedded brains GmbH 5 | * Dornierstr. 4 6 | * 82178 Puchheim 7 | * Germany 8 | * 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | */ 31 | 32 | #include 33 | #include 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include 41 | 42 | #include 43 | #include 44 | 45 | #define STACK_SIZE_INIT_TASK (32 * 1024) 46 | #define STACK_SIZE_SHELL (32 * 1024) 47 | #define PRIO_SHELL 10 48 | 49 | const Pin atsam_pin_config[] = {GRISP_PIN_CONFIG}; 50 | const size_t atsam_pin_config_count = PIO_LISTSIZE(atsam_pin_config); 51 | const uint32_t atsam_matrix_ccfg_sysio = GRISP_MATRIX_CCFG_SYSIO; 52 | 53 | static rtems_id led_timer_id = RTEMS_INVALID_ID; 54 | 55 | static void 56 | led_timer(rtems_id timer, void *arg) 57 | { 58 | rtems_status_code sc; 59 | static uint8_t state = 0x1; 60 | bool r, g, b; 61 | 62 | (void)arg; 63 | 64 | sc = rtems_timer_reset(timer); 65 | assert(sc == RTEMS_SUCCESSFUL); 66 | 67 | ++state; 68 | if (state > 0x7) { 69 | state = 0x0; 70 | } 71 | 72 | r = ((state & 0x1) != 0); 73 | g = ((state & 0x2) != 0); 74 | b = ((state & 0x4) != 0); 75 | 76 | grisp_led_set2(r, g, b); 77 | } 78 | 79 | static void 80 | init_led(void) 81 | { 82 | rtems_status_code sc; 83 | 84 | grisp_led_set1(false, false, false); 85 | grisp_led_set2(false, false, false); 86 | 87 | sc = rtems_timer_initiate_server( 88 | 250, 89 | RTEMS_MINIMUM_STACK_SIZE, 90 | RTEMS_DEFAULT_ATTRIBUTES 91 | ); 92 | assert(sc == RTEMS_SUCCESSFUL); 93 | 94 | sc = rtems_timer_create(rtems_build_name('L', 'E', 'D', ' '), 95 | &led_timer_id); 96 | assert(sc == RTEMS_SUCCESSFUL); 97 | 98 | sc = rtems_timer_server_fire_after( 99 | led_timer_id, 100 | rtems_clock_get_ticks_per_second() / 2, 101 | led_timer, 102 | NULL 103 | ); 104 | assert(sc == RTEMS_SUCCESSFUL); 105 | } 106 | 107 | static void 108 | start_shell(void) 109 | { 110 | rtems_status_code sc = rtems_shell_init( 111 | "SHLL", 112 | STACK_SIZE_SHELL, 113 | PRIO_SHELL, 114 | CONSOLE_DEVICE_NAME, 115 | false, 116 | true, 117 | NULL 118 | ); 119 | assert(sc == RTEMS_SUCCESSFUL); 120 | } 121 | 122 | static void 123 | Init(rtems_task_argument arg) 124 | { 125 | (void)arg; 126 | 127 | puts("\nSimple RTEMS sample application\n"); 128 | init_led(); 129 | start_shell(); 130 | 131 | exit(0); 132 | } 133 | 134 | /* 135 | * Configure RTEMS. 136 | */ 137 | #define CONFIGURE_MICROSECONDS_PER_TICK 10000 138 | 139 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER 140 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER 141 | 142 | #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 8 143 | 144 | #define CONFIGURE_UNLIMITED_OBJECTS 145 | #define CONFIGURE_UNIFIED_WORK_AREAS 146 | 147 | #define CONFIGURE_INIT_TASK_STACK_SIZE STACK_SIZE_INIT_TASK 148 | 149 | #define CONFIGURE_STACK_CHECKER_ENABLED 150 | 151 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE 152 | #define CONFIGURE_INIT 153 | 154 | #include 155 | 156 | /* 157 | * Configure Shell. 158 | */ 159 | #include 160 | #define CONFIGURE_SHELL_COMMANDS_INIT 161 | #define CONFIGURE_SHELL_COMMANDS_ALL 162 | #define CONFIGURE_SHELL_NO_COMMAND_MKRFS 163 | #define CONFIGURE_SHELL_NO_COMMAND_FDISK 164 | #define CONFIGURE_SHELL_NO_COMMAND_DEBUGRFS 165 | 166 | #include 167 | -------------------------------------------------------------------------------- /grisp-simple-sample/sample-binaries/grisp.ini: -------------------------------------------------------------------------------- 1 | [boot] 2 | timeout_in_seconds = 3 3 | image_path = /media/mmcsd-0-0/simple-sample.bin 4 | -------------------------------------------------------------------------------- /grisp-simple-sample/sample-binaries/simple-sample.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grisp/grisp-software/f2324212d9ad9e28574fa2211045fab96fb30dc6/grisp-simple-sample/sample-binaries/simple-sample.bin -------------------------------------------------------------------------------- /libinih/Makefile: -------------------------------------------------------------------------------- 1 | RTEMS_ROOT ?= $(PWD)/../rtems-install/rtems/5 2 | RTEMS_BSP ?= atsamv 3 | 4 | include $(RTEMS_ROOT)/make/custom/$(RTEMS_BSP).mk 5 | 6 | # inih uses a slightly odd cast. The way it is used, it should be no problem. 7 | # Therefore make an exception for this error. 8 | CFLAGS += -Wno-error=cast-qual 9 | 10 | # to support long lines: 11 | CFLAGS += -DINI_USE_STACK=0 12 | CFLAGS += -DINI_ALLOW_REALLOC=1 13 | CFLAGS += -DINI_MAX_LINE=1024*32 14 | 15 | LIB = $(BUILDDIR)/libinih.a 16 | LIB_PIECES = $(wildcard inih/*.c) 17 | LIB_OBJS = $(LIB_PIECES:%.c=$(BUILDDIR)/%.o) 18 | LIB_DEPS = $(LIB_PIECES:%.c=$(BUILDDIR)/%.d) 19 | 20 | all: $(BUILDDIR) $(LIB) 21 | 22 | install: all 23 | mkdir -p $(PROJECT_INCLUDE)/inih 24 | install -m 644 $(LIB) $(PROJECT_LIB) 25 | install -m 644 inih/*.h $(PROJECT_INCLUDE)/inih 26 | 27 | $(BUILDDIR): 28 | mkdir $(BUILDDIR) 29 | mkdir $(BUILDDIR)/inih 30 | 31 | $(LIB): $(LIB_OBJS) 32 | $(AR) rcu $@ $^ 33 | $(RANLIB) $@ 34 | 35 | clean: 36 | rm -rf $(BUILDDIR) 37 | 38 | -include $(LIB_DEPS) 39 | --------------------------------------------------------------------------------